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-2575] Truncate long strings when computing USTAT aggregates
Date Wed, 05 Apr 2017 23:19:49 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 8de588865 -> 48c7c608c


[TRAFODION-2575] Truncate long strings when computing USTAT aggregates


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

Branch: refs/heads/master
Commit: ca7c9c589eb01497ed7b24a83da812a75361999f
Parents: a955827
Author: Dave Birdsall <dbirdsall@apache.org>
Authored: Tue Apr 4 21:14:47 2017 +0000
Committer: Dave Birdsall <dbirdsall@apache.org>
Committed: Tue Apr 4 21:14:47 2017 +0000

----------------------------------------------------------------------
 core/sql/ustat/hs_globals.cpp | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ca7c9c58/core/sql/ustat/hs_globals.cpp
----------------------------------------------------------------------
diff --git a/core/sql/ustat/hs_globals.cpp b/core/sql/ustat/hs_globals.cpp
index 243e3d0..d459dff 100644
--- a/core/sql/ustat/hs_globals.cpp
+++ b/core/sql/ustat/hs_globals.cpp
@@ -5780,6 +5780,13 @@ Lng32 HSGlobalsClass::CollectStatistics()
         //We must use TRANSLATE to convert non-unicode character strings
         //to unicode
         NABoolean isVarChar = group->computeAvgVarCharSize();
+        // For long character strings, we'll truncate (trading off some
+        // UEC accuracy for performance and also avoiding engine bugs
+        // pertaining to very long varchars).
+        HSColumnStruct &col = group->colSet[0];
+        bool isOverSized = DFS2REC::isAnyCharacter(col.datatype) &&
+              (col.length > maxCharColumnLengthInBytes);
+
         if (isVarChar)
          *group->clistr = "SELECT FMTVAL, SUMVAL, AVGVAL FROM (SELECT ";
         else
@@ -5794,8 +5801,7 @@ Lng32 HSGlobalsClass::CollectStatistics()
         }
         else
          group->clistr->append(", COUNT(*) FROM ");
-        group->clistr->append(hssample_table->data());
-       
+   
         Int64 hintRowCount =  0;
 
         if (sampleTableUsed)
@@ -5809,7 +5815,31 @@ Lng32 HSGlobalsClass::CollectStatistics()
 
         char cardHint[50];
         sprintf(cardHint, " <<+ cardinality %e >> ", (double)hintRowCount);
-        group->clistr->append(cardHint);
+
+        if (isOverSized)
+        {
+          // Stick in a nested select that truncates the string.
+          // We have to do it here so the truncated string is
+          // the grouping column below.
+          char temp[20];  // long enough for 32-bit integer
+          sprintf(temp,"%d",maxCharColumnLengthInBytes);
+
+          group->clistr->append("(SELECT SUBSTR(");
+          group->clistr->append(columnName.data());
+          group->clistr->append(" FOR ");
+          group->clistr->append(temp);
+          group->clistr->append(") AS ");
+          group->clistr->append(columnName.data());
+          group->clistr->append(" FROM ");
+          group->clistr->append(hssample_table->data());
+          group->clistr->append(cardHint);
+          group->clistr->append(") AS T1");
+        }
+        else
+        {
+          group->clistr->append(hssample_table->data());
+          group->clistr->append(cardHint);
+        }
 
         group->clistr->append(" GROUP BY ");
         group->clistr->append(columnName.data());


Mime
View raw message