Github user sureshsubbiah commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/66#discussion_r38111897
--- Diff: core/sql/optimizer/SearchKey.cpp ---
@@ -2711,6 +2716,65 @@ void SearchKey::computeCoveredLeadingKeys()
}
}
+void SearchKey::computeFullKeyPredicates(ValueIdSet& predicates)
+{
+ // If the key column is an INDEX COLUMN, convert it into a base column
+ ValueIdList baseKeyCols;
+
+ ValueId vid;
+ const ValueIdList& keyColumns = getKeyColumns();
+ for (CollIndex i=0; i<keyColumns.entries(); i++ ) {
+ if ( keyColumns[i].getItemExpr()->getOperatorType() ==
ITM_INDEXCOLUMN )
+ vid =
((IndexColumn*)(keyColumns[i].getItemExpr()))->getDefinition();
+ else
+ vid = keyColumns[i];
+
+ baseKeyCols.insertAt(baseKeyCols.entries(), vid);
+ }
+
+ // compute the # of leading key columns covered by the key columns
+ // in the disjunct.
+ ValueIdSet columnsCoveredByKey;
+
+ vid = predicates.init();
+ for (; predicates.next(vid); predicates.advance(vid)) {
+
+ columnsCoveredByKey.clear();
+ vid.getItemExpr()->findAll(ITM_BASECOLUMN, columnsCoveredByKey,
TRUE, TRUE);
+
+ // for each vid (or predicate), check the base column list
+ for (CollIndex i=0; i<baseKeyCols.entries(); i++ ) {
+
+ NABoolean found = FALSE;
+
+ // the predicate directly refers the base column
+ if ( columnsCoveredByKey.containsTheGivenValue(baseKeyCols[i]) ) {
+ fullKeyPredicates_ += vid;
+ found = TRUE;
+ } else {
--- End diff --
I don't understand why we need this else branch? Is it because a particular
basecolumn may have different valueids and we may not have found a match the
"contains" check in the if branch.Can you please give an example where the else
branch was actually taken?
Also could comparing by position lead to a false hit in the case where the
same table is scanned twice? If we have an OR pred then we can get columns from
a the second scan in the preds for the first table scan (I think). If we just
compare by position we may think we have a match but the column may refer to
the second scan and not the first. Not sure if this will happen as something
else could prevent this from happening.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---