added enhanced check to handle default values copy

Current code has an optimization to move source default
value to target if total length (null+VClen+length) match.
This is sufficient for current scenarios where the difference
between source and target is only in VClen indicator (2 or 4 bytes).
But that assumption may not be true in future and was pointed out
by reviewer. An enhanced check has been added to make sure
that all sub-parts (nullLen, vcLen, dataLen) also match.


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

Branch: refs/heads/master
Commit: 383de008bb3be279b997d1f0ac411d4f0068fb3e
Parents: 1231c04
Author: Cloud User <[email protected]>
Authored: Mon Apr 11 17:27:31 2016 +0000
Committer: Cloud User <[email protected]>
Committed: Mon Apr 11 17:27:31 2016 +0000

----------------------------------------------------------------------
 core/sql/generator/GenExpGenerator.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/383de008/core/sql/generator/GenExpGenerator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.cpp 
b/core/sql/generator/GenExpGenerator.cpp
index 9cef6cd..ed20c83 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -756,9 +756,17 @@ void ExpGenerator::copyDefaultValues(
           Lng32 srcDefLen = srcAttr->getDefaultValueStorageLength();
           char* srcDefVal = srcAttr->getDefaultValue();
          char * tgtDefVal = new(generator->getSpace()) char[tgtDefLen];
+
           // if source and target def storage lengths dont match, then
           // need to move each part (null, vclen, data) separately.
-          if (tgtDefLen != srcDefLen) 
+          if ((tgtDefLen == srcDefLen) &&
+              (tgtAttr->getNullFlag() == srcAttr->getNullFlag()) &&
+              (tgtAttr->getVCIndicatorLength() == 
srcAttr->getVCIndicatorLength()) &&
+              (tgtAttr->getLength() == srcAttr->getLength()))
+            {
+              str_cpy_all(tgtDefVal, srcDefVal, srcDefLen);
+            }
+          else
             {
               char * tgtDefValCurr = tgtDefVal;
 
@@ -784,10 +792,6 @@ void ExpGenerator::copyDefaultValues(
 
               str_cpy_all(tgtDefValCurr, srcDefVal, srcDefLen);
             }
-          else
-            {
-              str_cpy_all(tgtDefVal, srcDefVal, srcDefLen);
-            }
          
          tgtAttr->setDefaultValue(srcAttr->getDefaultClass(), tgtDefVal);
        }

Reply via email to