You are viewing a plain text version of this content. The canonical link for it is here.
Posted to codereview@trafodion.apache.org by DaveBirdsall <gi...@git.apache.org> on 2017/04/05 18:25:28 UTC

[GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...

GitHub user DaveBirdsall opened a pull request:

    https://github.com/apache/incubator-trafodion/pull/1046

    [TRAFODION-2576] Fix long varchar bug in incremental UPDATE STATISTICS

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/DaveBirdsall/incubator-trafodion Trafodion2376

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-trafodion/pull/1046.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1046
    
----
commit ebf98de2ba8ffd361773df3e42b8813b98ce6691
Author: Dave Birdsall <db...@apache.org>
Date:   2017-04-05T18:23:38Z

    [TRAFODION-2576] Fix long varchar bug in incremental UPDATE STATISTICS

----


---
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.
---

[GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/1046#discussion_r110058006
  
    --- 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 --
    
    ... or, actually, make it universally BYTES when the charset is UTF-8. That probably makes more sense, as the information content is then roughly the same.


---
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.
---

[GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-trafodion/pull/1046


---
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.
---

[GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...

Posted by DaveBirdsall <gi...@git.apache.org>.
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.
---

[GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/1046#discussion_r110052947
  
    --- 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 --
    
    This is a question to this pre-existing code: We added character and byte semantics, like Oracle has it, to UTF-8 character columns. Do we need something similar here? Maybe as simple as adding the keyword "BYTES" when we deal with UTF-8 character columns with a length specified 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.
---

[GitHub] incubator-trafodion pull request #1046: [TRAFODION-2576] Fix long varchar bu...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/1046#discussion_r110060012
  
    --- 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 --
    
    ... thinking about this again, we don't have a SUBSTRING method that will give the first n _bytes_ of a UTF-8 string, truncated to the next UTF-8 character. So, without such a function we can't really do what I suggested above.
    
    If we have a long UTF-8 column c and maxLengthInBytes is 256, then we will take SUBSTRING(c for 64) here. In many situations and languages, this will be about 64 bytes of information, not 256.


---
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.
---