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-1887] Upsert into aligned format table with no primary keys fails with error 3241 after the patch from PR 340
Date Wed, 16 Mar 2016 15:50:30 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master b7039ef4a -> f9b3afd33


[TRAFODION-1887] Upsert into aligned format table with no primary keys fails with error 3241
after the patch from PR 340

Also, added new test cases to test this sceanrio.


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

Branch: refs/heads/master
Commit: 6aed4d3db95a726d57a29f39a0383c2b1154e9d8
Parents: 0da9903
Author: selvaganesang <selva.govindarajan@esgyn.com>
Authored: Sat Mar 12 16:35:24 2016 +0000
Committer: selvaganesang <selva.govindarajan@esgyn.com>
Committed: Sat Mar 12 16:35:24 2016 +0000

----------------------------------------------------------------------
 core/sql/optimizer/BindRelExpr.cpp   | 40 ++++++++++++++++---------------
 core/sql/optimizer/RelUpdate.h       |  3 ++-
 core/sql/regress/seabase/EXPECTED020 | 20 ++++++++++++++++
 core/sql/regress/seabase/TEST020     |  7 ++++++
 4 files changed, 50 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6aed4d3d/core/sql/optimizer/BindRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index ab347a7..cbb460e 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -9888,7 +9888,7 @@ RelExpr *Insert::bindNode(BindWA *bindWA)
                    (nacol->getDefaultClass() == COM_IDENTITY_GENERATED_BY_DEFAULT)) {
             setSystemGeneratesIdentityValue(TRUE);
           }
-          else 
+          else if (nacol->getDefaultClass() != COM_NO_DEFAULT)
             omittedDefaultCols = TRUE;
 
           // Bind the default value, make an Assign, etc, as above
@@ -10112,15 +10112,8 @@ RelExpr *Insert::bindNode(BindWA *bindWA)
          *CmpCommon::diags() << DgSqlCode(-4490);
     }
   }
-  if (isUpsert() && (!getIsTrafLoadPrep()) && 
-        (((!isAlignedRowFormat) && omittedCurrentDefaultClassCols) || 
-             (isAlignedRowFormat && omittedDefaultCols)) 
-              && (CmpCommon::getDefault(TRAF_UPSERT_WITH_INSERT_DEFAULT_SEMANTICS)
== DF_OFF)) {
-    boundExpr = xformUpsertToMerge(bindWA);
-    return boundExpr;
-  }
-  else 
-  if (isUpsertThatNeedsMerge()) {
+
+  if (isUpsertThatNeedsMerge(isAlignedRowFormat, omittedDefaultCols, omittedCurrentDefaultClassCols))
{
     boundExpr = xformUpsertToMerge(bindWA);
     return boundExpr;
   }
@@ -10171,17 +10164,26 @@ matched clause of merge). If the upsert caused a row to be updated
in the
 base table then the old version of the row will have to be deleted from 
 indexes, and a new version inserted. Upsert is being transformed to merge
 so that we can delete the old version of an updated row from the index.
+
+Upsert is also converted into merge when there are omitted cols with default values and 
+TRAF_UPSERT_WITH_INSERT_DEFAULT_SEMANTICS is set to  OFF in case of aligned format table
or 
+omitted current timestamp cols in case of non-aligned row format
 */
-NABoolean Insert::isUpsertThatNeedsMerge() const
+NABoolean Insert::isUpsertThatNeedsMerge(NABoolean isAlignedRowFormat, NABoolean omittedDefaultCols,
+                                   NABoolean omittedCurrentDefaultClassCols) const
 {
-  if (!isUpsert() || getIsTrafLoadPrep() || 
-      (getTableDesc()->isIdentityColumnGeneratedAlways() && 
-       getTableDesc()->hasIdentityColumnInClusteringKey()) ||
-      getTableDesc()->getClusteringIndex()->getNAFileSet()->hasSyskey() || 
-      !(getTableDesc()->hasSecondaryIndexes()))
-    return FALSE;
-
-  return TRUE;
+  if (isUpsert() && 
+      (NOT getIsTrafLoadPrep()) && 
+      (NOT (getTableDesc()->isIdentityColumnGeneratedAlways() && getTableDesc()->hasIdentityColumnInClusteringKey()))
&& 
+      (NOT (getTableDesc()->getClusteringIndex()->getNAFileSet()->hasSyskey()))
&& 
+       ((getTableDesc()->hasSecondaryIndexes()) ||
+         (( NOT isAlignedRowFormat) && omittedCurrentDefaultClassCols) ||
+             ((isAlignedRowFormat && omittedDefaultCols
+              && (CmpCommon::getDefault(TRAF_UPSERT_WITH_INSERT_DEFAULT_SEMANTICS)
== DF_OFF)))
+       ))
+     return TRUE;
+  else
+     return FALSE;
 }
 
 RelExpr* Insert::xformUpsertToMerge(BindWA *bindWA) 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6aed4d3d/core/sql/optimizer/RelUpdate.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelUpdate.h b/core/sql/optimizer/RelUpdate.h
index dbd8a06..d949781 100644
--- a/core/sql/optimizer/RelUpdate.h
+++ b/core/sql/optimizer/RelUpdate.h
@@ -1149,7 +1149,8 @@ public:
     baseColRefs_ = val;
   }
 
-  NABoolean isUpsertThatNeedsMerge() const;
+  NABoolean isUpsertThatNeedsMerge(NABoolean isAlignedRowFormat, NABoolean omittedDefaultCols,
+                                   NABoolean omittedCurrentDefaultCols) const;
   RelExpr* xformUpsertToMerge(BindWA *bindWA) ;
 
 protected:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6aed4d3d/core/sql/regress/seabase/EXPECTED020
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED020 b/core/sql/regress/seabase/EXPECTED020
index b1e8606..f2f807f 100644
--- a/core/sql/regress/seabase/EXPECTED020
+++ b/core/sql/regress/seabase/EXPECTED020
@@ -3496,4 +3496,24 @@ E@           A
           6                     5
 
 --- 5 row(s) selected.
+>>
+>>create table test020t43(c1 int, c2 int ) attribute aligned format ;
+
+--- SQL operation complete.
+>>upsert into test020t43 values (1,1);
+
+--- 1 row(s) inserted.
+>>upsert into test020t43 (c1) values(1);
+
+--- 1 row(s) inserted.
+>>select * from test020t43 ;
+
+C1           C2
+-----------  -----------
+
+          1            1
+          1            ?
+
+--- 2 row(s) selected.
+>>
 >>log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6aed4d3d/core/sql/regress/seabase/TEST020
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST020 b/core/sql/regress/seabase/TEST020
index 64afa3c..f428169 100755
--- a/core/sql/regress/seabase/TEST020
+++ b/core/sql/regress/seabase/TEST020
@@ -90,6 +90,7 @@ drop table test020_t33 cascade;
 drop table test020t40 cascade;
 drop table test020t41 cascade;
 drop table test020t42 cascade;
+drop table test020t43 cascade;
 
 ?section tests
 create table  test020t1 (c1 int not null primary key,
@@ -815,3 +816,9 @@ select * from table(index_table test020t42ix) ;
 -- check if the updated d column is reflected in the index
 upsert into test020t42 (a,b,e) values (1, 'c', 4);
 select * from table(index_table test020t42ix) ;
+
+create table test020t43(c1 int, c2 int ) attribute aligned format ;
+upsert into test020t43 values (1,1);
+upsert into test020t43 (c1) values(1);
+select * from test020t43 ; 
+


Mime
View raw message