Skip to content

Commit

Permalink
TEIID-3662: ensuring that the value set is ordered and updating the i…
Browse files Browse the repository at this point in the history
…ndex

usage costing
Conflicts:
	engine/src/main/java/org/teiid/query/tempdata/IndexInfo.java
	engine/src/test/java/org/teiid/query/processor/TestTempTables.java
  • Loading branch information
shawkins authored and johnathonlee committed Sep 21, 2015
1 parent 86465c6 commit d940fdd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
2 changes: 2 additions & 0 deletions build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
Expand Up @@ -337,6 +337,8 @@ <h4>from 8.7.4</h4>
</li>
<li>[<a href='https://issues.jboss.org/browse/TEIID-3658'>TEIID-3658</a>] - VDBs may start before transport service
</li>
<li>[<a href='https://issues.jboss.org/browse/TEIID-3662'>TEIID-3662</a>] - IN predicate against a materialized/temp table index without an order by returns wrong results
</li>
</ul>

<h4>from 8.7.3</h4>
Expand Down
4 changes: 1 addition & 3 deletions engine/src/main/java/org/teiid/query/tempdata/IndexInfo.java
Expand Up @@ -57,9 +57,7 @@ TupleBrowser createTupleBrowser() throws TeiidComponentException {
}
if (!valueSet.isEmpty()) {
LogManager.logDetail(LogConstants.CTX_DQP, "Using index value set"); //$NON-NLS-1$
if (ordering != null) {
sortValueSet(direction);
}
sortValueSet(direction);
CollectionTupleSource cts = new CollectionTupleSource(valueSet.iterator());
return new TupleBrowser(this.table.getTree(), cts, direction);
}
Expand Down
14 changes: 8 additions & 6 deletions engine/src/main/java/org/teiid/query/tempdata/TempTable.java
Expand Up @@ -571,13 +571,15 @@ private long estimateCost(OrderBy orderBy, IndexInfo ii, long rowCost) {
additionalCost = (64 - Long.numberOfLeadingZeros(initialCost - 1));
rowCost /= 3;
}
if (rowCost > 1 && (!ii.covering || (orderBy != null && ii.ordering == null))) {
if (rowCost > 1 && !ii.covering) {
//primary lookup
additionalCost += rowCost * (64 - Long.numberOfLeadingZeros(rowCost - 1));
}
if (rowCost > 1 && orderBy != null && ii.ordering != null) {
//pk order or non-covered ordering
rowCost *= (64 - Long.numberOfLeadingZeros(rowCost - 1));
if (!ii.covering) {
//primary lookup
rowCost *= 2;
}
//TODO: this should be based upon the filtered rowCost, but instead it is
//written as a bonus
additionalCost -= Math.min(additionalCost, rowCost * (64 - Long.numberOfLeadingZeros(rowCost - 1)));
}
return rowCost + additionalCost;
}
Expand Down
Expand Up @@ -157,8 +157,8 @@ private void execute(String sql, List<?>... expectedResults) throws Exception {
}

@Test public void testNonCoveringSecondaryIndex() throws Exception {
execute("SELECT * from vgroup5 where y in ('zne', 'zwo') order by y desc", Arrays.asList("two", "zwo", 1), Arrays.asList("one", "zne", 1));
execute("SELECT * from vgroup5 where y is null", Arrays.asList((String)null, (String)null, 1));
execute("SELECT * from vgroup5 where y in ('zwo', 'zne') order by y desc", Arrays.asList("two", "zwo", 1), Arrays.asList("one", "zne", 1));
execute("SELECT * from vgroup5 where y is null", Arrays.asList((String)null, (String)null, 1), Arrays.asList(" b", (String)null, 1), Arrays.asList(" c", (String)null, 1), Arrays.asList(" d", (String)null, 1));
execute("SELECT * from vgroup5 where y is null and z = 2");
}

Expand Down
12 changes: 12 additions & 0 deletions engine/src/test/java/org/teiid/query/processor/TestTempTables.java
Expand Up @@ -577,5 +577,17 @@ private void sampleTable() throws Exception {
//multiple out of order values
execute("select x.e1 from x inner join /*+ makeind */ x1 on x.e3 = x1.e3 and x.e2 = x1.e2", new List[] {Arrays.asList("2"), Arrays.asList("1")}); //$NON-NLS-1$
}

@Test public void testIndexInPredicate() throws Exception {
execute("create local temporary table x (e1 string, e2 integer, primary key (e1))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$

//the issue is only apparent when the values are from different pages
for (int i = 0; i < 2048; i++) {
execute("insert into x (e2, e1) values ("+i+", '"+i+"')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
}

execute("select e2, e1 from x where e1 in ('2000', '1')", new List[] {Arrays.asList(1, "1"), Arrays.asList(2000, "2000")}); //$NON-NLS-1$

}

}
Expand Up @@ -499,7 +499,10 @@ public static TransformationMetadata exampleMaterializedView() {
new String[] { DataTypeManager.DefaultDataTypes.STRING});

//non-covering index
QueryNode vTrans5 = new QueryNode("SELECT x, 'z' || substring(x, 2) as y, 1 as z FROM matsrc"); //$NON-NLS-1$ //$NON-NLS-2$
QueryNode vTrans5 = new QueryNode("SELECT x, 'z' || substring(x, 2) as y, 1 as z FROM matsrc "
+ "union all SELECT ifnull(x, ' ') || 'b', 'x' || substring(x, 2) as y, 1 as z FROM matsrc "
+ "union all SELECT ifnull(x, ' ') || 'c', 'y' || substring(x, 2) as y, 1 as z FROM matsrc "
+ "union all SELECT ifnull(x, ' ') || 'd', 'w' || substring(x, 2) as y, 1 as z FROM matsrc");
Table vGroup5 = createVirtualGroup("VGroup5", virtModel, vTrans5); //$NON-NLS-1$
vGroup5.setMaterialized(true);
List<Column> vElements5 = createElements(vGroup5,
Expand Down

0 comments on commit d940fdd

Please sign in to comment.