Repository: trafodion
Updated Branches:
  refs/heads/master 288ed2103 -> 908ea7d5b


[TRAFODION-3097] At times the query involving sequence function fail and dumps 
core

BiArithmetic sum expression clause in Sequence expression can't have
pcode generated like an arithmetic expression that supports augmented
assignment operation such as a += b.


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

Branch: refs/heads/master
Commit: 68294fc74c198e6a88132ac8699415fe52f70fbc
Parents: 8dbf5df
Author: selvaganesang <[email protected]>
Authored: Fri Jun 1 20:14:12 2018 +0000
Committer: selvaganesang <[email protected]>
Committed: Fri Jun 1 23:26:36 2018 +0000

----------------------------------------------------------------------
 core/sql/exp/ExpPCodeClauseGen.cpp     |  4 ++++
 core/sql/exp/exp_clause.cpp            |  3 +++
 core/sql/exp/exp_clause_derived.h      | 14 ++++++++++++--
 core/sql/generator/GenExpGenerator.cpp |  2 ++
 core/sql/generator/GenExpGenerator.h   |  9 ++++++++-
 core/sql/generator/GenItemExpr.cpp     |  2 ++
 core/sql/generator/Generator.h         |  2 +-
 core/sql/regress/executor/EXPECTED063  | 24 ++++++++++++------------
 core/sql/regress/executor/TEST063      |  2 +-
 9 files changed, 45 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/exp/ExpPCodeClauseGen.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpPCodeClauseGen.cpp 
b/core/sql/exp/ExpPCodeClauseGen.cpp
index 958e210..04d88e0 100644
--- a/core/sql/exp/ExpPCodeClauseGen.cpp
+++ b/core/sql/exp/ExpPCodeClauseGen.cpp
@@ -2412,10 +2412,14 @@ ex_expr::exp_return_type 
ex_arith_sum_clause::pCodeGenerate(Space *space, UInt32
      (op1->getDatatype() > REC_MAX_NUMERIC))
     return ex_clause::pCodeGenerate(space, f);
 
+  if (! isAugmentedAssignOperation())
+     return ex_clause::pCodeGenerate(space, f);
+
   // The result should be the same as one of the operands.
   //
   Int32 firstOperand = isSameAttribute(dst, op1);
   Int32 secondOperand = isSameAttribute(dst, op2);
+  
   if(!firstOperand && !secondOperand)
     return ex_clause::pCodeGenerate(space, f);
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index 2a9278e..ffd8b27 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -1632,8 +1632,10 @@ ex_arith_clause::ex_arith_clause(OperatorTypeEnum 
oper_type,
                   (oper_type == ITM_NEGATE ? 2 : 3), attr, space),
        flags_(0)
 {
+  setAugmentedAssignOperation(TRUE);
   arithRoundingMode_ = (char)arithRoundingMode;
 
+
   if (divToDownscale)
     setDivToDownscale(TRUE);
 
@@ -1659,6 +1661,7 @@ ex_arith_clause::ex_arith_clause(clause_type type,
                                   flags_(0)
  
 {
+  setAugmentedAssignOperation(TRUE);
   setInstruction(); 
 }
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/exp/exp_clause_derived.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause_derived.h 
b/core/sql/exp/exp_clause_derived.h
index 31dae0c..f478cd7 100644
--- a/core/sql/exp/exp_clause_derived.h
+++ b/core/sql/exp/exp_clause_derived.h
@@ -487,7 +487,9 @@ public:
 
   // Construction
   //
-  ex_arith_clause(){};
+  ex_arith_clause() 
+      { setAugmentedAssignOperation(TRUE); }
+
   ex_arith_clause(OperatorTypeEnum oper_type,
                             Attributes ** attr,
                             Space * space,
@@ -587,7 +589,8 @@ public:
 private:
   enum
   {
-    DIV_TO_DOWNSCALE = 0x01
+    DIV_TO_DOWNSCALE = 0x01,
+    ALLOW_AUGMENTED_ASSIGN_OPERATION = 0x02
   };
 
   char filler[4];             // 00-03
@@ -616,6 +619,12 @@ private:
   { return (flags_ & DIV_TO_DOWNSCALE) != 0;}
   void setDivToDownscale(NABoolean v)      
   { (v ? flags_ |= DIV_TO_DOWNSCALE : flags_ &= ~DIV_TO_DOWNSCALE); }
+public:
+  NABoolean isAugmentedAssignOperation()
+  { return (flags_ & ALLOW_AUGMENTED_ASSIGN_OPERATION) != 0;}
+
+  void setAugmentedAssignOperation(NABoolean v) 
+  { (v ? flags_ |= ALLOW_AUGMENTED_ASSIGN_OPERATION : flags_ &= 
~ALLOW_AUGMENTED_ASSIGN_OPERATION); }
   
 };
 
@@ -656,6 +665,7 @@ public:
   }
 
   virtual short getClassSize() { return (short)sizeof(*this); }
+
   // ---------------------------------------------------------------------
   
 private:   

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/generator/GenExpGenerator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.cpp 
b/core/sql/generator/GenExpGenerator.cpp
index bffaae1..fc7d39e 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -4289,6 +4289,7 @@ short ExpGenerator::generateSequenceExpression(const 
ValueIdSet &sequenceItems,
   if (sequenceItems.isEmpty()) return 0;
 
   initExprGen();
+  setInSequenceFuncExpr(TRUE);
   startExprGen(&expr, ex_expr::exp_ARITH_EXPR);
 
   // Loop over the sequence items calling the protective short-circuit
@@ -4309,6 +4310,7 @@ short ExpGenerator::generateSequenceExpression(const 
ValueIdSet &sequenceItems,
       itmExpr->codeGen(generator);
     }
 
+  setInSequenceFuncExpr(FALSE);
   // Finalize the expression generation machinery.
   //
   endExprGen(&expr, 1);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/generator/GenExpGenerator.h
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.h 
b/core/sql/generator/GenExpGenerator.h
index 09136ca..fcc8c30 100644
--- a/core/sql/generator/GenExpGenerator.h
+++ b/core/sql/generator/GenExpGenerator.h
@@ -394,7 +394,9 @@ class ExpGenerator : public NABasicObject
     // if pcode has been generated, then expression generator removes the
     // clauses (except for in case of showplan or clause_eval).
     // If this flag is set, then clauses are not removed.
-    SAVE_CLAUSES_IN_EXPR = 0x0100
+    SAVE_CLAUSES_IN_EXPR   = 0x0100,
+
+    IN_SEQUENCE_FUNC_EXPR  = 0x0200
   };
 
   UInt16 pCodeMode_;
@@ -1042,6 +1044,11 @@ public:
     return ((flags_ & SAVE_CLAUSES_IN_EXPR) != 0);
   };
 
+  NABoolean inSequenceFuncExpr()
+    { return (flags_ & IN_SEQUENCE_FUNC_EXPR) != 0; }
+  void setInSequenceFuncExpr(NABoolean v)
+    { (v ? flags_ |= IN_SEQUENCE_FUNC_EXPR : flags_ &= 
~IN_SEQUENCE_FUNC_EXPR); }      
+
   // The working heap for dynamic memory allocation, will be
   // be destroyed at the end of each statement.
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/generator/GenItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemExpr.cpp 
b/core/sql/generator/GenItemExpr.cpp
index ead1926..7163dea 100644
--- a/core/sql/generator/GenItemExpr.cpp
+++ b/core/sql/generator/GenItemExpr.cpp
@@ -359,6 +359,8 @@ short BiArithSum::codeGen(Generator * generator)
     ex_arith_sum_clause(getOperatorType(), 
                        attr, 
                        generator->getSpace());
+  if (eg->inSequenceFuncExpr())
+     arith_clause->setAugmentedAssignOperation(FALSE);
   
   generator->getExpGenerator()->linkClause(this, arith_clause);
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/generator/Generator.h
----------------------------------------------------------------------
diff --git a/core/sql/generator/Generator.h b/core/sql/generator/Generator.h
index 8f2f50d..d6fc0c0 100644
--- a/core/sql/generator/Generator.h
+++ b/core/sql/generator/Generator.h
@@ -242,7 +242,7 @@ class Generator : public NABasicObject
     , AQR_WNR_INSERT_EMPTY    = 0x00000100
 
     // if trafodion/hbase IUD operation is using RI inlining
-    , RI_INLINING_FOR_TRAF_IUD = 0x00000200
+    , RI_INLINING_FOR_TRAF_IUD     = 0x00000200
 
     // If Hive tables are accessed at runtime
     , HIVE_ACCESS              = 0x00000400

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/regress/executor/EXPECTED063
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/EXPECTED063 
b/core/sql/regress/executor/EXPECTED063
index 4b45f7e..07d3e5f 100755
--- a/core/sql/regress/executor/EXPECTED063
+++ b/core/sql/regress/executor/EXPECTED063
@@ -602,36 +602,36 @@ A       (EXPR)       (EXPR)
 >>
 >>SELECT a, (SELECT SUM(B) from t063t1 where (a <= S.a)), y  
 +>FROM t063t1 S, (SELECT a, RUNNINGSUM(B) from t063t1 sequence by a) AS T(x, 
y) 
-+>where a = x;
++>where a = x order by a;
 
 A       (EXPR)                Y                   
 ------  --------------------  --------------------
 
+     1                    10                    10
+     2                    28                    28
      3                    55                    55
+     4                    90                    90
      5                   135                   135
      6                   165                   165
      7                   200                   200
      8                   240                   240
+     9                   285                   285
+    10                   307                   307
     11                   333                   333
+    12                   363                   363
+    13                   398                   398
+    14                   436                   436
     15                   481                   481
     16                   504                   504
+    17                   529                   529
     18                   556                   556
+    19                   585                   585
     20                   607                   607
     21                   631                   631
     22                   657                   657
+    23                   685                   685
     24                   715                   715
     25                   747                   747
-     1                    10                    10
-     2                    28                    28
-     4                    90                    90
-     9                   285                   285
-    10                   307                   307
-    12                   363                   363
-    13                   398                   398
-    14                   436                   436
-    17                   529                   529
-    19                   585                   585
-    23                   685                   685
 
 --- 25 row(s) selected.
 >>

http://git-wip-us.apache.org/repos/asf/trafodion/blob/68294fc7/core/sql/regress/executor/TEST063
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/TEST063 
b/core/sql/regress/executor/TEST063
index a8199bb..40b9795 100755
--- a/core/sql/regress/executor/TEST063
+++ b/core/sql/regress/executor/TEST063
@@ -217,7 +217,7 @@ SELECT a, RUNNINGMAX(b), (SELECT MAX(B) from t063t1 where 
(a <= S.a)) from t063t
 
 SELECT a, (SELECT SUM(B) from t063t1 where (a <= S.a)), y  
 FROM t063t1 S, (SELECT a, RUNNINGSUM(B) from t063t1 sequence by a) AS T(x, y) 
-where a = x;
+where a = x order by a;
 
 -- MOVINGMIN/MOVINGMAX
 

Reply via email to