[TRAFODION-2399] Syntax error when loading from salted table This was caused by methods to generate an SQL string literal from a constant value. In some cases it repeated the character set name introducer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/1417baf4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/1417baf4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/1417baf4 Branch: refs/heads/master Commit: 1417baf4d15b45dd390c6ff1bfd6078cdf137f53 Parents: 91a809b Author: Hans Zeller <[email protected]> Authored: Tue Dec 20 22:26:13 2016 +0000 Committer: Hans Zeller <[email protected]> Committed: Tue Dec 20 22:26:13 2016 +0000 ---------------------------------------------------------------------- core/sql/common/CharType.cpp | 2 +- core/sql/common/sql_charset_strings.h | 2 ++ core/sql/optimizer/ItemExpr.cpp | 21 ++++++++++++++------- core/sql/optimizer/ValueDesc.cpp | 6 +++++- 4 files changed, 22 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1417baf4/core/sql/common/CharType.cpp ---------------------------------------------------------------------- diff --git a/core/sql/common/CharType.cpp b/core/sql/common/CharType.cpp index 4babc92..299fe56 100644 --- a/core/sql/common/CharType.cpp +++ b/core/sql/common/CharType.cpp @@ -167,7 +167,7 @@ NAString CharType::getCharSetName() const NAString CharType::getCharSetAsPrefix(CharInfo::CharSet cs) { - return NAString("_") + CharInfo::getCharSetName(cs); + return NAString(SQLCHARSET_INTRODUCER_IN_LITERAL) + CharInfo::getCharSetName(cs); } NAString CharType::getCharSetAsPrefix() const http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1417baf4/core/sql/common/sql_charset_strings.h ---------------------------------------------------------------------- diff --git a/core/sql/common/sql_charset_strings.h b/core/sql/common/sql_charset_strings.h index d7bc3e1..8a45228 100644 --- a/core/sql/common/sql_charset_strings.h +++ b/core/sql/common/sql_charset_strings.h @@ -78,6 +78,8 @@ #define SQLCHARSETSYNONYM_SQL_TEXT "SQL_TEXT" #define SQLCHARSETSTRING_UNKNOWN "_unknown_" +#define SQLCHARSET_INTRODUCER_IN_LITERAL "_" + #ifndef SQLCOLLATIONSTRING_DEFINED #define SQLCOLLATIONSTRING_DEFINED 1 http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1417baf4/core/sql/optimizer/ItemExpr.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp index 508ea9f..4f715c2 100644 --- a/core/sql/optimizer/ItemExpr.cpp +++ b/core/sql/optimizer/ItemExpr.cpp @@ -10716,13 +10716,18 @@ NAString ConstValue::getConstStr(NABoolean transformNeeded) const else if(getType()->getTypeQualifier() == NA_CHARACTER_TYPE) { CharType* chType = (CharType*)getType(); + NAString txt; - // 4/8/96: added the Boolean switch so that displayable - // and non-displayable version can be differed. if ( transformNeeded ) - return chType->getCharSetAsPrefix() + getText(); + txt = getText(); else - return chType->getCharSetAsPrefix() + getTextForQuery(QUERY_FORMAT); + txt = getTextForQuery(QUERY_FORMAT); + + // if result doesn't have a charset specifier already, add one + if (txt.index(SQLCHARSET_INTRODUCER_IN_LITERAL) == 0) + return txt; + else + return chType->getCharSetAsPrefix() + txt; } else { @@ -10800,6 +10805,8 @@ const NAString ConstValue::getText4CacheKey() const return getText(); } else { + NAString result = getText(); + // we want to return _charset'strfoo' instead of 'strfoo'. // This is to fix genesis case 10-040616-0347 "NF: query cache does not // work properly on || for certain character set". The root cause here @@ -10808,9 +10815,9 @@ const NAString ConstValue::getText4CacheKey() const // select ?p1 || _ksc5601'arg' from ... // select ?p1 || _kanji'arg from ... // The solution is to make them different via charset prefixes. - NAString result("_", CmpCommon::statementHeap()); - result += CharInfo::getCharSetName(((CharType*)getType())->getCharSet()); - result += getText(); + if (result.index(SQLCHARSET_INTRODUCER_IN_LITERAL) != 0) + result.prepend(((CharType*)getType())->getCharSetAsPrefix()); + return result; } } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1417baf4/core/sql/optimizer/ValueDesc.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/ValueDesc.cpp b/core/sql/optimizer/ValueDesc.cpp index 2fdaa22..b0d77ba 100644 --- a/core/sql/optimizer/ValueDesc.cpp +++ b/core/sql/optimizer/ValueDesc.cpp @@ -6691,7 +6691,11 @@ ValueIdList::computeEncodedKey(const TableDesc* tDesc, NABoolean isMaxKey, // and no inputs, all VEGies should have constants in // them and should be replaced with those ie = ie->replaceVEGExpressions(availableValues, availableValues); - value = ie->evaluate(STMTHEAP); + if (ie->getOperatorType() == ITM_CONSTANT) + value = static_cast<ConstValue *>(ie); + else + value = ie->evaluate(STMTHEAP); + if ( !value ) return NULL; } else
