Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/513#discussion_r65590770
  
    --- Diff: core/conn/odbc/src/odbc/nsksrvrcore/srvrothers.cpp ---
    @@ -4811,6 +4811,64 @@ odbc_SQLSvc_GetSQLCatalogs_sme_(
     
                        break;
     
    +        case SQL_API_SQLSTATISTICS:
    +            if (!checkIfWildCard(catalogNm, catalogNmNoEsc) && !metadataId)
    +            {
    +                exception_->exception_nr = 
odbc_SQLSvc_GetSQLCatalogs_ParamError_exn_;
    +                exception_->u.ParamError.ParamDesc = 
SQLSVC_EXCEPTION_WILDCARD_NOT_SUPPORTED;
    +            }
    +            if (tableNm[0] != '$' && tableNm[0] != '\\')
    +            {
    +                if (strcmp(catalogNm, "") == 0)
    +                    strcpy(tableName1, SEABASE_MD_CATALOG);
    +                else
    +                    strcpy(tableName1, catalogNm);
    +            }
    +
    +            tableParam[0] = tableName1;
    +            convertWildcard(metadataId, TRUE, schemaNm, expSchemaNm);
    +            convertWildcardNoEsc(metadataId, TRUE, schemaNm, 
schemaNmNoEsc);
    +            convertWildcard(metadataId, TRUE, tableNm, expTableNm);
    +            convertWildcardNoEsc(metadataId, TRUE, tableNmNoEsc, 
tableNmNoEsc);
    +            inputParam[0] = schemaNmNoEsc;
    +            inputParam[1] = expSchemaNm;
    +            inputParam[2] = tableNmNoEsc;
    +            inputParam[3] = expTableNm;
    +
    +            snprintf(CatalogQuery, sizeof(CatalogQuery),
    +                    "select "
    +                    "cast('%s' as varchar(128)) TABLE_CAT, "
    +                    "cast(trim(ob.SCHEMA_NAME) as varchar(128)) 
TABLE_SCHEM, "
    +                    "cast(trim(ob.OBJECT_NAME) as varchar(128)) 
TABLE_NAME, "
    +                    "cast(0 as smallint) NON_UNIQUE, " // not support
    +                    "cast('' as varchar(128)) INDEX_QUALIFIER, " // not 
support
    +                    "cast('' as varchar(128)) INDEX_NAME, "
    +                    "cast(0 as smallint) TYPE, " // not support
    +                    "cast((case when (trim(co.COLUMN_CLASS) <> 'S') then 
co.column_number+1 else "
    +                        "co.column_number end) as smallint) 
ORDINAL_POSITION, "
    +                    "cast(trim(co.COLUMN_NAME) as varchar(128)) 
COLUMN_NAME, "
    +                    "cast('' as char(1)) ASC_OR_DES, "
    +                    "cast(sb.rowcount as integer) CARDINALITY, "
    +                    "cast(0 as integer) PAGES, " // not support
    +                    "cast('' as varchar(128)) FILTER_CONDITION " // not 
support
    +                    "from "
    +                    "TRAFODION.\"_MD_\".OBJECTS ob, "
    +                    "TRAFODION.\"_MD_\".COLUMNS co, "
    +                    "TRAFODION.%s.sb_histograms sb "
    +                    "where "
    +                    "ob.OBJECT_UID = co.OBJECT_UID "
    +                    "and co.COLUMN_NUMBER = sb.COLUMN_NUMBER "
    --- End diff --
    
    Unfortunately, I don't know of a document either. I've learned the format 
of the data in the Histograms table by reverse-engineering it, along with a 
little bit of code reading. Here's what I know: For a multi-column histogram, 
there will be n rows in the SB_HISTOGRAMS table, where n is the number of 
columns in the histogram. One way to see this is to create a table with a 
primary key, put some rows into it (100 rows, let's say),then do UPDATE 
STATISTICS ON EVERY COLUMN. After that, do SHOWSTATS ON EVERY COLUMN. That will 
show you the table_uid for that table. Then do "select histogram_id, count(*) 
from sb_histograms where table_uid = <the value from SHOWSTATS> group by 
histogram_id". You'll notice some histogram_id's with counts of one. Those are 
the single column histograms. You'll also notice a few with counts greater than 
one. These are the multi-column histograms. If you then look at the rows for 
that particular histogram_id, you'll see there is a row for each column in the 
 histogram. It is a denormalized representation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to