Second rework: Check divisioning columns, also generator core fix
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/5631883d Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/5631883d Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/5631883d Branch: refs/heads/master Commit: 5631883d6b2d81c6d34081288889b791cfbbe527 Parents: 20953fe Author: Dave Birdsall <dbirds...@apache.org> Authored: Wed Nov 22 01:48:35 2017 +0000 Committer: Dave Birdsall <dbirds...@apache.org> Committed: Wed Nov 22 01:48:35 2017 +0000 ---------------------------------------------------------------------- core/sql/optimizer/IndexDesc.cpp | 9 ++++++--- core/sql/optimizer/ItemExpr.cpp | 16 ++++++++-------- core/sql/regress/compGeneral/EXPECTED071 | 26 ++++++++++++++++++++++++++ core/sql/regress/compGeneral/TEST071 | 10 ++++++++++ 4 files changed, 50 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5631883d/core/sql/optimizer/IndexDesc.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/IndexDesc.cpp b/core/sql/optimizer/IndexDesc.cpp index df22a49..742ff96 100644 --- a/core/sql/optimizer/IndexDesc.cpp +++ b/core/sql/optimizer/IndexDesc.cpp @@ -810,9 +810,9 @@ IndexProperty::compareIndexPromise(const IndexProperty *ixProp) const while (!done) { if (columnToCheck >= index->getIndexKey().entries()) - return INCOMPATIBLE; // must be one of the indexes is just "_SALT_" (seems unlikely actually) + return INCOMPATIBLE; // must be one of the indexes is just "_SALT_" or "_DIVISION_1_" (seems unlikely actually) else if (columnToCheck >= otherIndex->getIndexKey().entries()) - return INCOMPATIBLE; // must be one of the indexes is just "_SALT_" (seems unlikely actually) + return INCOMPATIBLE; // must be one of the indexes is just "_SALT_" or "_DIVISION_1_" (seems unlikely actually) else { IndexColumn * indexCol = (IndexColumn *)(index->getIndexKey()[columnToCheck]).getItemExpr(); @@ -820,10 +820,13 @@ IndexProperty::compareIndexPromise(const IndexProperty *ixProp) const if ( indexCol->getNAColumn()->isSaltColumn() && otherIndexCol->getNAColumn()->isSaltColumn() ) columnToCheck++; + else if ( indexCol->getNAColumn()->isDivisioningColumn() && + otherIndexCol->getNAColumn()->isDivisioningColumn() ) + columnToCheck++; else if ( indexCol->getDefinition() != otherIndexCol->getDefinition() ) return INCOMPATIBLE; else - done = TRUE; // leading column (ignoring "_SALT_" if both have "_SALT_") is the same; do Kb checks + done = TRUE; // leading column (ignoring salt, divisioning if both have it) is the same; do Kb checks } } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5631883d/core/sql/optimizer/ItemExpr.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp index 09cc906..732dfde 100644 --- a/core/sql/optimizer/ItemExpr.cpp +++ b/core/sql/optimizer/ItemExpr.cpp @@ -709,11 +709,11 @@ ItemExpr * ItemExpr::createMirrorPred(ItemExpr *compColPtr, const ValueIdSet &underlyingCols) { CMPASSERT(compColPtr->getOperatorType() == ITM_BASECOLUMN); - ValueIdSet eics = ((BaseColumn *)compColPtr)->getEIC(); - ValueId iCol; - ItemExpr *compColIndxPtr; - eics.getFirst(iCol); - compColIndxPtr = iCol.getItemExpr(); + BaseColumn *bcol = static_cast<BaseColumn *>(compColPtr); + // use the basecolumn Veg, using the basecolumn by itself can cause issues + // during codegen downstream + ValueId egVid = bcol->getTableDesc()->getColumnVEGList()[bcol->getColNumber()]; + ItemExpr *compColVEGRefPtr = egVid.getItemExpr(); switch (getOperatorType()) { @@ -750,7 +750,7 @@ ItemExpr * ItemExpr::createMirrorPred(ItemExpr *compColPtr, ItemExpr * compPred = new(CmpCommon::statementHeap()) BiRelat(ITM_EQUAL, - compColIndxPtr, + compColVEGRefPtr, (foldedExpr==NULL) ? newCompExpr.getItemExpr() : foldedExpr); compPred->synthTypeAndValueId(TRUE); @@ -821,14 +821,14 @@ ItemExpr * ItemExpr::createMirrorPred(ItemExpr *compColPtr, if (keyColOnLeft == TRUE) compPred = new(CmpCommon::statementHeap()) BiRelat(((BiRelat *) this)->getRelaxedComparisonOpType(), - compColIndxPtr, + compColVEGRefPtr, mirroredExpr //newCompExpr.getItemExpr() ); else compPred = new(CmpCommon::statementHeap()) BiRelat(((BiRelat *) this)->getRelaxedComparisonOpType(), mirroredExpr, //newCompExpr.getItemExpr(), - compColIndxPtr); + compColVEGRefPtr); compPred->synthTypeAndValueId(TRUE); return compPred; break; http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5631883d/core/sql/regress/compGeneral/EXPECTED071 ---------------------------------------------------------------------- diff --git a/core/sql/regress/compGeneral/EXPECTED071 b/core/sql/regress/compGeneral/EXPECTED071 index e07238f..9fa3ec3 100644 --- a/core/sql/regress/compGeneral/EXPECTED071 +++ b/core/sql/regress/compGeneral/EXPECTED071 @@ -1512,6 +1512,32 @@ MTD2 MTD2X2 6 0 0 S SYSKEY --- 30 row(s) selected. >> +>>update statistics for table mtd1 on every column; + +--- SQL operation complete. +>> +>>select store_id, item_id, sale_date, sale_amt ++>from mtd1 ++>where item_id = 101 and sale_amt = 100.0 and sale_date between date '2011-06-01' and date '2011-06-30'; + +STORE_ID ITEM_ID SALE_DATE SALE_AMT +----------- ----------- ---------- --------------------- + + 1 101 2011-06-30 100.00 + +--- 1 row(s) selected. +>> +>>select store_id, item_id, sale_date, sale_amt ++>from mtd1 ++>where item_id = 102 and sale_amt = 200.0 and sale_date between date '2011-07-01' and date '2011-08-31'; + +STORE_ID ITEM_ID SALE_DATE SALE_AMT +----------- ----------- ---------- --------------------- + + 2 102 2011-08-02 200.00 + +--- 1 row(s) selected. +>> >>set parserflags 1; --- SQL operation complete. http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5631883d/core/sql/regress/compGeneral/TEST071 ---------------------------------------------------------------------- diff --git a/core/sql/regress/compGeneral/TEST071 b/core/sql/regress/compGeneral/TEST071 index 09ef16a..d002f59 100644 --- a/core/sql/regress/compGeneral/TEST071 +++ b/core/sql/regress/compGeneral/TEST071 @@ -753,6 +753,16 @@ order by 1, 2, 3 execute smdixquery; +update statistics for table mtd1 on every column; + +select store_id, item_id, sale_date, sale_amt +from mtd1 +where item_id = 101 and sale_amt = 100.0 and sale_date between date '2011-06-01' and date '2011-06-30'; + +select store_id, item_id, sale_date, sale_amt +from mtd1 +where item_id = 102 and sale_amt = 200.0 and sale_date between date '2011-07-01' and date '2011-08-31'; + set parserflags 1; -- validate contents of index against base table after create index select count(*) from mtd1;