trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbirds...@apache.org
Subject [1/2] incubator-trafodion git commit: [TRAFODION-2576] Fix long varchar bug in incremental UPDATE STATISTICS
Date Thu, 06 Apr 2017 23:14:17 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 48c7c608c -> 0d75af13a


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


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/ebf98de2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/ebf98de2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/ebf98de2

Branch: refs/heads/master
Commit: ebf98de2ba8ffd361773df3e42b8813b98ce6691
Parents: 3366fdb
Author: Dave Birdsall <dbirdsall@apache.org>
Authored: Wed Apr 5 18:23:38 2017 +0000
Committer: Dave Birdsall <dbirdsall@apache.org>
Committed: Wed Apr 5 18:23:38 2017 +0000

----------------------------------------------------------------------
 core/sql/ustat/hs_cli.cpp     | 80 -------------------------------------
 core/sql/ustat/hs_cli.h       |  3 --
 core/sql/ustat/hs_globals.cpp | 82 +++++++++++++++++++++++++++++++++++---
 core/sql/ustat/hs_globals.h   |  3 ++
 core/sql/ustat/hs_la.cpp      | 28 +++++++++++++
 core/sql/ustat/hs_la.h        |  2 +
 6 files changed, 110 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ebf98de2/core/sql/ustat/hs_cli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_cli.cpp b/core/sql/ustat/hs_cli.cpp
index 873a1a0..046f415 100644
--- a/core/sql/ustat/hs_cli.cpp
+++ b/core/sql/ustat/hs_cli.cpp
@@ -5501,86 +5501,6 @@ NAString HSSample::getTempTablePartitionInfo(NABoolean unpartitionedSample,
     return tableOptions;
   }
 
-
-//
-// METHOD:  addTruncatedSelectList()
-//
-// PURPOSE: Generates a SELECT list consisting of 
-//          column references or a SUBSTRING
-//          on column references which truncates the
-//          column to the maximum length allowed in
-//          UPDATE STATISTICS.
-//
-// INPUT:   'qry' - the SQL query string to append the 
-//          select list to.
-//
-void HSSample::addTruncatedSelectList(NAString & qry)
-  {
-    bool first = true;
-    for (Lng32 i = 0; i < objDef->getNumCols(); i++)
-      {
-        if (!ComTrafReservedColName(*objDef->getColInfo(i).colname))
-          {
-            if (!first)
-              qry += ", ";
-
-            addTruncatedColumnReference(qry,objDef->getColInfo(i));
-            first = false;
-          }
-      }
-  }
-
-
-//
-// 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 HSSample::addTruncatedColumnReference(NAString & qry,HSColumnStruct & colInfo)
-  {
-    HSGlobalsClass *hs_globals = GetHSContext();
-    Lng32 maxLengthInBytes = hs_globals->maxCharColumnLengthInBytes;
-    bool isOverSized = DFS2REC::isAnyCharacter(colInfo.datatype) &&
-                           (colInfo.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(colInfo.datatype);
-        if (isFixedChar)
-          qry += "CAST(";
-        qry += "SUBSTRING(";
-        qry += colInfo.externalColumnName->data();
-        qry += " FOR ";
-        
-        char temp[20];  // big enough for "nnnnnn)"
-        sprintf(temp,"%d)", maxLengthInBytes / CharInfo::maxBytesPerChar(colInfo.charset));
-        qry += temp;
-        if (isFixedChar)
-          {
-            qry += " AS CHAR(";
-            qry += temp;
-            qry += ")";
-          }
-        qry += " AS ";
-        qry += colInfo.externalColumnName->data();
-      }
-    else
-      qry += colInfo.externalColumnName->data();
-  }
-
-
 // Print the heading for the display of a query plan to the log.
 void printPlanHeader(HSLogMan *LM)
   {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ebf98de2/core/sql/ustat/hs_cli.h
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_cli.h b/core/sql/ustat/hs_cli.h
index ffb55a9..58bc353 100644
--- a/core/sql/ustat/hs_cli.h
+++ b/core/sql/ustat/hs_cli.h
@@ -239,9 +239,6 @@ class HSSample
 
     NABoolean isIUS() { return isIUS_; }
 
-    void addTruncatedSelectList(NAString & qry);
-    static void addTruncatedColumnReference(NAString & qry, HSColumnStruct & colInfo);
-
   private:
     // Member function
     void makeTableName(NABoolean isPersSample = FALSE);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ebf98de2/core/sql/ustat/hs_globals.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_globals.cpp b/core/sql/ustat/hs_globals.cpp
index 243e3d0..8aa5111 100644
--- a/core/sql/ustat/hs_globals.cpp
+++ b/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 += ")";
+          }
+        qry += " AS ";
+        qry += externalColumnName->data();
+      }
+    else
+      qry += externalColumnName->data();
+  }
+
 
 HSInterval::HSInterval()
       : rowCount_(0), uecCount_(0), gapMagnitude_(0), highFreq_(FALSE),
@@ -4224,7 +4273,7 @@ Lng32 HSSample::make(NABoolean rowCountIsEstimate, // input
         // The source table has an oversized column. We have to generate
         // SUBSTRING calls on such columns to fit them into the sample
         // table.
-        addTruncatedSelectList(dml);
+        objDef->addTruncatedSelectList(dml);
       }      
     else
       dml += "*";
@@ -5109,7 +5158,7 @@ static void mapInternalSortTypes(HSColGroupStruct *groupList, NABoolean
forHive
           group->ISprecision = col.precision;
           group->ISscale = col.scale;
           // the method below handles adding SUBSTRING for over-size char/varchars
-          HSSample::addTruncatedColumnReference(group->ISSelectExpn,col);
+          col.addTruncatedColumnReference(group->ISSelectExpn);
         }
         break;
      } // switch
@@ -6758,7 +6807,8 @@ Lng32 HSGlobalsClass::generateSampleI(Int64 currentSampleSize,
 
     NAString insertSelectIQuery;
     iusSampleInsertedInMem->generateInsertSelectIQuery(sampleTable_I, 
-                        *user_table, insertSelectIQuery, 
+                        *user_table, insertSelectIQuery,
+                        hasOversizedColumns, objDef, 
                         currentSampleSize, futureSampleSize,
                         deleteSetSize, actualRowCount);
 
@@ -12482,7 +12532,17 @@ void HSGlobalsClass::generateIUSSelectInsertQuery(const NAString&
smplTable,
 {
   queryText.append("UPSERT USING LOAD INTO "); // for algorithm 1
   queryText.append(smplTable.data());
-  queryText.append(" (SELECT * FROM ");
+  queryText.append(" (SELECT ");
+  if (hasOversizedColumns)
+    {
+      // The source table has an oversized column. We have to generate
+      // SUBSTRING calls on such columns to fit them into the sample
+      // table.
+      objDef->addTruncatedSelectList(queryText);
+    }      
+  else
+    queryText.append("*");
+  queryText.append(" FROM ");
 
   if (CmpCommon::getDefault(USTAT_INCREMENTAL_UPDATE_STATISTICS) == DF_ON)
     {
@@ -16181,6 +16241,8 @@ void
 HSInMemoryTable::generateInsertSelectIQuery(NAString& targetTable, 
                                             NAString& sourceTable,
                                             NAString& queryText,
+                                            NABoolean hasOversizedColumns,
+                                            HSTableDef * objDef,
                                             Int64 futureSampleSize,
                                             Int64 currentSampleSize,
                                             Int64 deleteSetSize,
@@ -16200,7 +16262,17 @@ HSInMemoryTable::generateInsertSelectIQuery(NAString& targetTable,
 
   queryText.append(targetTable.data());
 
-  queryText.append(" (SELECT * FROM ");
+  queryText.append(" (SELECT ");
+  if (hasOversizedColumns)
+    {
+      // The source table has an oversized column. We have to generate
+      // SUBSTRING calls on such columns to fit them into the sample
+      // table.
+      objDef->addTruncatedSelectList(queryText);
+    }      
+  else
+    queryText.append("*");
+  queryText.append(" FROM ");
 
   queryText.append(sourceTable.data());
   queryText.append(" WHERE ");

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ebf98de2/core/sql/ustat/hs_globals.h
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_globals.h b/core/sql/ustat/hs_globals.h
index 65b88ca..4687be4 100644
--- a/core/sql/ustat/hs_globals.h
+++ b/core/sql/ustat/hs_globals.h
@@ -1029,6 +1029,8 @@ struct HSColumnStruct : public NABasicObject
 
     NABoolean operator==(const HSColumnStruct&) const;
 
+    void addTruncatedColumnReference(NAString & qry);
+
     ~HSColumnStruct();
   };
 
@@ -2594,6 +2596,7 @@ class HSInMemoryTable : public NABasicObject
 
     void generateInsertSelectIQuery(NAString& targetTbl, NAString& sourceTable,
                                     NAString& queryText,
+                                    NABoolean hasOversizedColumns, HSTableDef * objDef,
                                     Int64 currentSampleSize, Int64 futureSampleSize,
                                     Int64 deleteSetSize, Int64 sourceSetSize);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ebf98de2/core/sql/ustat/hs_la.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_la.cpp b/core/sql/ustat/hs_la.cpp
index 8d5685a..d33bedd 100644
--- a/core/sql/ustat/hs_la.cpp
+++ b/core/sql/ustat/hs_la.cpp
@@ -1294,3 +1294,31 @@ Lng32 HSHbaseTableDef::DescribeColumnNames()
   return 0;
 }
 
+//
+// METHOD:  addTruncatedSelectList()
+//
+// PURPOSE: Generates a SELECT list consisting of 
+//          column references or a SUBSTRING
+//          on column references which truncates the
+//          column to the maximum length allowed in
+//          UPDATE STATISTICS.
+//
+// INPUT:   'qry' - the SQL query string to append the 
+//          select list to.
+//
+void HSTableDef::addTruncatedSelectList(NAString & qry)
+  {
+    bool first = true;
+    for (Lng32 i = 0; i < getNumCols(); i++)
+      {
+        if (!ComTrafReservedColName(*getColInfo(i).colname))
+          {
+            if (!first)
+              qry += ", ";
+
+            getColInfo(i).addTruncatedColumnReference(qry);
+            first = false;
+          }
+      }
+  }
+

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ebf98de2/core/sql/ustat/hs_la.h
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_la.h b/core/sql/ustat/hs_la.h
index 3431d7a..e205862 100644
--- a/core/sql/ustat/hs_la.h
+++ b/core/sql/ustat/hs_la.h
@@ -120,6 +120,8 @@ class HSTableDef : public NABasicObject
     // SQ, Hive, or Hbase table?
     virtual tblOrigin getTblOrigin() const = 0;
 
+    void addTruncatedSelectList(NAString & qry);
+
   protected:
     NABoolean setObjectUID(NABoolean createExternalObject);
 


Mime
View raw message