trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaveBirdsall <...@git.apache.org>
Subject [GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...
Date Thu, 06 Apr 2017 16:02:23 GMT
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/1046#discussion_r110201855
  
    --- Diff: core/sql/ustat/hs_globals.cpp ---
    @@ -1882,6 +1882,55 @@ NABoolean HSColumnStruct::operator==(const HSColumnStruct&
other) const
         return ( colnum == other.colnum );
       }
     
    +//
    +// METHOD:  addTruncatedColumnReference()
    +//
    +// PURPOSE: Generates a column reference or a SUBSTRING
    +//          on a column reference which truncates the
    +//          column to the maximum length allowed in
    +//          UPDATE STATISTICS.
    +//
    +// INPUT:   'qry' - the SQL query string to append the 
    +//          reference to.
    +//          'colInfo' - struct containing datatype info
    +//          about the column.
    +//
    +void HSColumnStruct::addTruncatedColumnReference(NAString & qry)
    +  {
    +    HSGlobalsClass *hs_globals = GetHSContext();
    +    Lng32 maxLengthInBytes = hs_globals->maxCharColumnLengthInBytes;
    +    bool isOverSized = DFS2REC::isAnyCharacter(datatype) &&
    +                           (length > maxLengthInBytes);
    +    if (isOverSized)
    +      {
    +        // Note: The result data type of SUBSTRING is VARCHAR, always.
    +        // But if the column is CHAR, many places in the ustat code are not
    +        // expecting a VARCHAR. So, we stick a CAST around it to convert
    +        // it back to a CHAR in these cases.
    +
    +        NABoolean isFixedChar = DFS2REC::isSQLFixedChar(datatype);
    +        if (isFixedChar)
    +          qry += "CAST(";
    +        qry += "SUBSTRING(";
    +        qry += externalColumnName->data();
    +        qry += " FOR ";
    +        
    +        char temp[20];  // big enough for "nnnnnn)"
    +        sprintf(temp,"%d)", maxLengthInBytes / CharInfo::maxBytesPerChar(charset));
    +        qry += temp;
    +        if (isFixedChar)
    +          {
    +            qry += " AS CHAR(";
    +            qry += temp;
    +            qry += ")";
    --- End diff --
    
    Thanks for these comments. Your analysis is correct. The code is limiting strings to 256
bytes, which for UTF-8 means 64 characters since the longest UTF-8 character is 4 bytes long.
    
    By the way, the 256 byte limit is controllable by CQD so a customer or user can increase
this if they wish. The CQD is USTAT_MAX_CHAR_COL_LENGTH_IN_BYTES.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message