You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by sa...@apache.org on 2016/11/13 01:10:47 UTC

[2/3] incubator-trafodion git commit: Added regression test and fixed all the review comments.

Added regression test and fixed all the review comments.


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

Branch: refs/heads/master
Commit: f67784b047d4e815bd0b18b3ecc7642101c97cd7
Parents: 8517335
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Sat Nov 12 17:28:01 2016 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Sat Nov 12 17:28:01 2016 +0000

----------------------------------------------------------------------
 core/sql/optimizer/BindRelExpr.cpp       |  61 ++++++++-------
 core/sql/optimizer/BindWA.h              |   3 +-
 core/sql/optimizer/Inlining.cpp          |   2 +-
 core/sql/optimizer/RelSequence.cpp       |   4 +-
 core/sql/regress/executor/EXPECTED015.SB | 108 ++++++++++++++++++++++++++
 core/sql/regress/executor/TEST015        |  25 ++++++
 6 files changed, 171 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f67784b0/core/sql/optimizer/BindRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index db324a3..f63ddd2 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -2445,7 +2445,8 @@ Join * RelExpr::getLeftJoinChild() const
   
   while(result)
     {
-      if (result->getOperatorType() == REL_LEFT_JOIN) break;
+      if (result->getOperatorType() == REL_LEFT_JOIN) 
+        break;
       result = result->child(0);
     }
   return (Join *)result;
@@ -2457,7 +2458,8 @@ RelSequence* RelExpr::getOlapChild() const
   
   while(result)
     {
-      if (result->getOperatorType() == REL_SEQUENCE) break;
+      if (result->getOperatorType() == REL_SEQUENCE) 
+        break;
       result = result->child(0);
     }
   return (RelSequence *)result;
@@ -10322,12 +10324,12 @@ RelExpr *Insert::bindNode(BindWA *bindWA)
     const NodeMap* np;
     Lng32 partns = 1;
     if ( pf && (np = pf->getNodeMap()) )
-    {
-       partns = np->getNumEntries();
-       if(partns > 1  && CmpCommon::getDefault(ATTEMPT_ESP_PARALLELISM) == DF_OFF)
-         // 4490 - BULK LOAD into a salted table is not supported if ESP parallelism is turned off
-         *CmpCommon::diags() << DgSqlCode(-4490);
-    }
+      {
+        partns = np->getNumEntries();
+        if(partns > 1  && CmpCommon::getDefault(ATTEMPT_ESP_PARALLELISM) == DF_OFF)
+          // 4490 - BULK LOAD into a salted table is not supported if ESP parallelism is turned off
+          *CmpCommon::diags() << DgSqlCode(-4490);
+      }
   }
 
   if (isUpsertThatNeedsMerge(isAlignedRowFormat, omittedDefaultCols, omittedCurrentDefaultClassCols)) {
@@ -10336,12 +10338,12 @@ RelExpr *Insert::bindNode(BindWA *bindWA)
 	boundExpr = xformUpsertToMerge(bindWA);  
 	return boundExpr;
       }
-      else if( CmpCommon::getDefault(TRAF_UPSERT_TO_EFF_TREE) == DF_ON)
-	boundExpr = xformUpsertToEfficientTree(bindWA);
+    else 
+      boundExpr = xformUpsertToEfficientTree(bindWA);
     
     
   }
-   if (NOT (isMerge() || noIMneeded()))
+  if (NOT (isMerge() || noIMneeded()))
     boundExpr = handleInlining(bindWA, boundExpr);
 
   // turn OFF Non-atomic Inserts for ODBC if we have detected that Inlining is needed
@@ -10423,7 +10425,8 @@ NABoolean Insert::isUpsertThatNeedsMerge(NABoolean isAlignedRowFormat, NABoolean
      return FALSE;
 }
 
-#ifdef __ignore
+/** commenting the following method out for future work. This may be enabled as a further performance improvement if we can eliminate the sort node that gets geenrated as part of the Sequence Node. In case of no duplicates we won't need the Sequence node at all. 
+
 // take an insert(src) node and transform it into
 // a tuple_flow with old/new rows flowing to the IM tree.
 // with a newly created input_scan
@@ -10536,7 +10539,8 @@ RelExpr* Insert::xformUpsertToEfficientTreeNoDup(BindWA *bindWA)
 
   return topNode; 
 }
-#endif
+*/
+
 // take an insert(src) node and transform it into
 // a tuple_flow with old/new rows flowing to the IM tree.
 // with a newly created sequence node used to eliminate duplicates.
@@ -10599,7 +10603,7 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
   ColReference * targetColRef;
   int predCount = 0;
   ValueIdSet newOuterRefs;
-  ItemExpr * pkeyValPrev;
+  ItemExpr * pkeyValPrev = NULL;
   ItemExpr * pkeyVals = NULL;
   for (CollIndex i = 0; i < tableCols.entries(); i++)
     {
@@ -10630,11 +10634,12 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
 						     keyPredPrev,
 						     keyPred);  
 	    }
-	  pkeyValPrev = pkeyVals;
+          
+          pkeyValPrev = pkeyVals;
     
 	  pkeyVals = tableCols[i].getItemExpr();
 	  
-	  if (i > 0) 
+	  if (pkeyValPrev != NULL ) 
 	    {
 	      pkeyVals = new(bindWA->wHeap()) ItemList(pkeyVals,pkeyValPrev);
       
@@ -10644,8 +10649,8 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
     }
  
   // Map the table's primary key values to the source lists key values
-  ValueIdList tablePKeyVals = NULL;
-  ValueIdList sourcePKeyVals = NULL;
+  ValueIdList tablePKeyVals ;
+  ValueIdList sourcePKeyVals ;
   
   pkeyVals->convertToValueIdList(tablePKeyVals,bindWA,ITM_ITEM_LIST);
   updateToSelectMap().mapValueIdListDown(tablePKeyVals,sourcePKeyVals);
@@ -10653,8 +10658,7 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
 
 
   Join *lj = new(bindWA->wHeap()) Join(child(0),targetTableScan,REL_LEFT_JOIN,keyPred);
-  lj->doNotTransformToTSJ();	  
-  lj->setTSJForWrite(TRUE);
+  
   bindWA->getCurrentScope()->xtnmStack()->createXTNM();
 
   
@@ -10664,7 +10668,7 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
   bindWA->getCurrentScope()->xtnmStack()->removeXTNM();
  
  
-  ValueIdSet sequenceFunction = NULL;		
+  ValueIdSet sequenceFunction ;		
  
   ItemExpr *constOne = new (bindWA->wHeap()) ConstValue(1);
  
@@ -10676,6 +10680,7 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
   
   //Create the olap node and use the primary key of the table as the 
   //"partition by" columns for the olap node.
+  CMPASSERT(!bindWA->getCurrentScope()->getSequenceNode());
   RelSequence *seqNode = new(bindWA->wHeap()) RelSequence(boundLJ, sourcePKeyVals.rebuildExprTree(ITM_ITEM_LIST),  (ItemExpr *)NULL);
  
 
@@ -10695,14 +10700,14 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
   // Add a selection predicate (post predicate) to check if the LEAD item is NULL
   ItemExpr *selPredOnLead = NULL;
   selPredOnLead = new (bindWA->wHeap()) UnLogic(ITM_IS_NULL,leadItem);
-  selPredOnLead->bindNode(bindWA);
+  selPredOnLead = selPredOnLead->bindNode(bindWA);
   if (bindWA->errStatus()) return this;
   seqNode->selectionPred() += selPredOnLead->getValueId();
-  
-  RelExpr *boundSeqNode = seqNode->bindNode(bindWA);  
-  boundSeqNode->setChild(0,boundLJ);
+  seqNode->setChild(0,boundLJ);
 
-  
+ 
+  RelExpr *boundSeqNode = seqNode->bindNode(bindWA);  
+   
   setChild(0,boundSeqNode);
 
   // Fixup the newRecExpr() and newRecExprArray() to refer to the new 
@@ -10710,12 +10715,12 @@ RelExpr* Insert::xformUpsertToEfficientTree(BindWA *bindWA)
   // from the current bindScope for this.
   ValueIdSet newNewRecExpr;
   ValueIdMap notCoveredMap = bindWA->getCurrentScope()->getNcToOldMap();
-  notCoveredMap.rewriteValueIdSetDown(newRecExpr(),newNewRecExpr);
+  notCoveredMap.rewriteValueIdSetUp(newNewRecExpr, newRecExpr());
   newRecExpr() = newNewRecExpr;
   
   ValueIdList oldRecArrList(newRecExprArray());
   ValueIdList newRecArrList;
-  notCoveredMap.rewriteValueIdListDown(oldRecArrList,newRecArrList);
+  notCoveredMap.rewriteValueIdListUp(newRecArrList, oldRecArrList);
   ValueIdArray newNewRecArray(newRecArrList.entries());
   
   for (CollIndex i = 0; i < newRecArrList.entries(); i++)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f67784b0/core/sql/optimizer/BindWA.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindWA.h b/core/sql/optimizer/BindWA.h
index 4089291..c074814 100644
--- a/core/sql/optimizer/BindWA.h
+++ b/core/sql/optimizer/BindWA.h
@@ -685,7 +685,8 @@ public:
   // --------------------------------------------------------------------
   RelExpr *&getSequenceNode() { return sequenceNode_; };
 
-  ValueIdMap &getNcToOldMap() { return ncToOldMap_;}
+  const ValueIdMap &getNcToOldMap() { return ncToOldMap_;}
+  void setNCToOldMap(ValueIdMap vmap) {ncToOldMap_ = vmap; }
 
   ValueIdList getOlapPartition() const {return OlapPartition_; };
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f67784b0/core/sql/optimizer/Inlining.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/Inlining.cpp b/core/sql/optimizer/Inlining.cpp
index ad534e7..c98bf29 100644
--- a/core/sql/optimizer/Inlining.cpp
+++ b/core/sql/optimizer/Inlining.cpp
@@ -626,7 +626,7 @@ RETDesc *GenericUpdate::createOldAndNewCorrelationNames(BindWA *bindWA, NABoolea
     // DELETE or UPDATE --
     // Now merge the old/target/before valueid's (the Scan child RETDesc)
     // into this RETDesc such that these cols are all named "OLD@.<col>"
-    //f
+    //
     Scan *scan ;
     if (getOperatorType() != REL_UNARY_INSERT)
       scan = getScanNode();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f67784b0/core/sql/optimizer/RelSequence.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelSequence.cpp b/core/sql/optimizer/RelSequence.cpp
index e7b67b7..626f58b 100644
--- a/core/sql/optimizer/RelSequence.cpp
+++ b/core/sql/optimizer/RelSequence.cpp
@@ -1193,7 +1193,7 @@ RelExpr *RelSequence::bindNode(BindWA *bindWA)
       newColumn->getValueId(),
       USER_COLUMN,
       colList->at(i)->getHeading());
-    ncToOldMap.addMapEntry(columnValueId,newColumn->getValueId());
+    ncToOldMap.addMapEntry(newColumn->getValueId(),columnValueId);
     if(colList->at(i)->isGrouped()) {
       ColumnNameMap *cnm =
         resultTable->findColumn(colList->at(i)->getColRefNameObj());
@@ -1262,7 +1262,7 @@ RelExpr *RelSequence::bindNode(BindWA *bindWA)
 
   bindWA->getCurrentScope()->getSequenceNode() = boundExpr;
   // save the ncToOldmap in the current scope. It will be used in Insert::bindnode for a special case.
-  bindWA->getCurrentScope()->getNcToOldMap() = ncToOldMap;
+  bindWA->getCurrentScope()->setNCToOldMap( ncToOldMap);
   return boundExpr;
 
 } // RelSequence::bindNode()

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f67784b0/core/sql/regress/executor/EXPECTED015.SB
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/EXPECTED015.SB b/core/sql/regress/executor/EXPECTED015.SB
index a80f143..15e3d87 100755
--- a/core/sql/regress/executor/EXPECTED015.SB
+++ b/core/sql/regress/executor/EXPECTED015.SB
@@ -163,6 +163,17 @@
 
 --- SQL operation complete.
 >>
+>>create table t015t16 (a largeint  not null, b int not null, 
++>c int, d int, e int, primary key(a,b)) ;
+
+--- SQL operation complete.
+>>create index t015t16i1 on t015t16(c) ;
+
+--- SQL operation complete.
+>>create unique index t015t16i2 on t015t16(d) ;
+
+--- SQL operation complete.
+>>
 >>prepare explainIt from
 +>select substring(operator,1,16) operator
 +>from table (explain(NULL,'XX')) t
@@ -1959,4 +1970,101 @@ TRAFODION_MERGE
 
 --- 1 row(s) selected.
 >>
+>>--upsert transformation to eff tree tests
+>>cqd traf_upsert_to_eff_tree 'ON';
+
+--- SQL operation complete.
+>>prepare xx from upsert into t015t16 values (1,2,3,4,5),(6,7,8,9,10);
+
+--- SQL command prepared.
+>>explain options 'f' xx;
+
+LC   RC   OP   OPERATOR              OPT       DESCRIPTION           CARD
+---- ---- ---- --------------------  --------  --------------------  ---------
+
+15   .    16   root                            x                     4.00E+000
+7    14   15   nested_join                                           4.00E+000
+10   13   14   merge_union                                           4.00E+000
+11   12   13   blocked_union                                         2.00E+000
+.    .    12   trafodion_insert                T015T16I2             1.00E+000
+.    .    11   trafodion_vsbb_delet            T015T16I2             1.00E+000
+8    9    10   blocked_union                                         2.00E+000
+.    .    9    trafodion_insert                T015T16I1             1.00E+000
+.    .    8    trafodion_vsbb_delet            T015T16I1             1.00E+000
+5    6    7    nested_join                                           1.00E+000
+.    .    6    trafodion_upsert                T015T16               1.00E+000
+4    .    5    sequence                                              1.00E+000
+3    .    4    sort                                                  2.00E+000
+2    1    3    left_hybrid_hash_joi                                  2.00E+000
+.    .    2    tuplelist                                             2.00E+000
+.    .    1    trafodion_scan                  T015T16               1.00E+002
+
+--- SQL operation complete.
+>>execute xx;
+
+--- 2 row(s) inserted.
+>>select * from t015t16 order by a;
+
+A                     B            C            D            E          
+--------------------  -----------  -----------  -----------  -----------
+
+                   1            2            3            4            5
+                   6            7            8            9           10
+
+--- 2 row(s) selected.
+>>prepare xx2 from upsert into t015t16 values (10,11,12,13,14);
+
+--- SQL command prepared.
+>>execute xx2;
+
+--- 1 row(s) inserted.
+>>select * from t015t16 order by a;
+
+A                     B            C            D            E          
+--------------------  -----------  -----------  -----------  -----------
+
+                   1            2            3            4            5
+                   6            7            8            9           10
+                  10           11           12           13           14
+
+--- 3 row(s) selected.
+>>
+>>prepare xx2 from upsert into t015t16 values (1,2,30,40,50);
+
+--- SQL command prepared.
+>>execute xx2;
+
+--- 1 row(s) inserted.
+>>select * from t015t16 order by a;
+
+A                     B            C            D            E          
+--------------------  -----------  -----------  -----------  -----------
+
+                   1            2           30           40           50
+                   6            7            8            9           10
+                  10           11           12           13           14
+
+--- 3 row(s) selected.
+>>
+>>prepare xx2 from upsert into t015t16 values (3,4,1,1,1),(6,7,80,90,100),(6,7,81,91,101);
+
+--- SQL command prepared.
+>>execute xx2;
+
+--- 2 row(s) inserted.
+>>select * from t015t16 order by a;
+
+A                     B            C            D            E          
+--------------------  -----------  -----------  -----------  -----------
+
+                   1            2           30           40           50
+                   3            4            1            1            1
+                   6            7           81           91          101
+                  10           11           12           13           14
+
+--- 4 row(s) selected.
+>>
+>>cqd traf_upsert_to_eff_tree 'OFF';
+
+--- SQL operation complete.
 >>log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f67784b0/core/sql/regress/executor/TEST015
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/TEST015 b/core/sql/regress/executor/TEST015
index bcf05e4..1f5915e 100755
--- a/core/sql/regress/executor/TEST015
+++ b/core/sql/regress/executor/TEST015
@@ -48,6 +48,7 @@ drop table ot;
 drop table odt cascade;
 drop table de cascade ;
 drop table dec1 cascade;
+drop table t015t16 cascade;
 
 --control query default POS 'OFF';
 
@@ -260,6 +261,11 @@ PRIMARY KEY (ID)
 ALTER TABLE OT 
 ADD CONSTRAINT UI1_OT UNIQUE (objectCode, version);
 
+create table t015t16 (a largeint  not null, b int not null, 
+c int, d int, e int, primary key(a,b)) ;
+create index t015t16i1 on t015t16(c) ;
+create unique index t015t16i2 on t015t16(d) ;
+
 prepare explainIt from
 select substring(operator,1,16) operator
 from table (explain(NULL,'XX')) t
@@ -865,5 +871,24 @@ prepare XX from UPSERT INTO DE (ID, dataElementConceptID, valueDomainID)
 VALUES  (1,  (select d.id from DEC1 d where d.codeValue = 'aa'),  3 ) ;
 execute explainIt;
 
+--upsert transformation to eff tree tests
+cqd traf_upsert_to_eff_tree 'ON';
+prepare xx from upsert into t015t16 values (1,2,3,4,5),(6,7,8,9,10);
+explain options 'f' xx;
+execute xx;
+select * from t015t16 order by a;
+prepare xx2 from upsert into t015t16 values (10,11,12,13,14);
+execute xx2;
+select * from t015t16 order by a;
+
+prepare xx2 from upsert into t015t16 values (1,2,30,40,50);
+execute xx2;
+select * from t015t16 order by a;
+
+prepare xx2 from upsert into t015t16 values (3,4,1,1,1),(6,7,80,90,100),(6,7,81,91,101);
+execute xx2;
+select * from t015t16 order by a;
+
+cqd traf_upsert_to_eff_tree 'OFF';
 log;