From teiid-commits at lists.jboss.org Thu Aug 16 10:53:55 2012
Content-Type: multipart/mixed; boundary="===============0676595553535927728=="
MIME-Version: 1.0
From: teiid-commits at lists.jboss.org
To: teiid-commits at lists.jboss.org
Subject: [teiid-commits] teiid SVN: r4329 - in trunk:
engine/src/main/java/org/teiid/dqp/internal/process and 8 other directories.
Date: Thu, 16 Aug 2012 10:53:55 -0400
Message-ID: <201208161453.q7GErtO0012105@svn01.web.mwc.hst.phx2.redhat.com>
--===============0676595553535927728==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: shawkins
Date: 2012-08-16 10:53:55 -0400 (Thu, 16 Aug 2012)
New Revision: 4329
Added:
trunk/engine/src/main/java/org/teiid/query/util/Options.java
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/Ru=
leMergeCriteria.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQuer=
yPlanner.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/ExistsCriteria.java
trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdow=
n.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.ja=
va
Log:
TEIID-2149 changing the applicability of subqueryUnnestDefault
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-08-1=
6 13:32:05 UTC (rev 4328)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-08-1=
6 14:53:55 UTC (rev 4329)
@@ -10,7 +10,7 @@
=
Teiid ${project.version} Release Notes
-Teiid ${project.version} adds metadata and integration features. =
+
Teiid ${project.version} adds performance and integration features. =
=
Overview
Highlights
-
=
@@ -35,6 +33,12 @@
- decodeinteger/decodestring have been deprecated. A CASE expression =
should be used instead.
=
+from 8.1
+
+ - TEIID-2149 Subquery Unnesting - the optimizer will not consul=
t the subqueryUnnestDefault property if it can make a cost based decision t=
o replace a subquery with a merge join.
+Use the subquery hints, DJ, MJ, and NO_UNNEST to override this behavior if=
needed.
+
+
from 8.0
- org.teiid.metadata.Schema holds FunctionMethods by uuid rather than =
name to accommodate overridden method signatures.
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request=
.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java =
2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java =
2012-08-16 14:53:55 UTC (rev 4329)
@@ -43,6 +43,7 @@
import org.teiid.core.id.IDGenerator;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
+import org.teiid.core.util.PropertiesUtils;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.dqp.internal.process.AuthorizationValidator.CommandType;
import org.teiid.dqp.internal.process.multisource.MultiSourceCapabilitiesF=
inder;
@@ -85,6 +86,7 @@
import org.teiid.query.tempdata.GlobalTableStore;
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.Options;
import org.teiid.query.validator.AbstractValidationVisitor;
import org.teiid.query.validator.ValidationVisitor;
import org.teiid.query.validator.Validator;
@@ -245,6 +247,9 @@
context.setResultSetCacheEnabled(this.resultSetCacheEnabled);
context.setUserRequestSourceConcurrency(this.userRequestConcurrenc=
y);
context.setSubject(workContext.getSubject());
+ Options options =3D new Options();
+ options.setProperties(System.getProperties());
+ PropertiesUtils.setBeanProperties(options, options.getProperties()=
, "org.teiid"); //$NON-NLS-1$
this.context.setSession(workContext.getSession());
this.context.setRequestId(this.requestId);
this.context.setDQPWorkContext(this.workContext);
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/r=
ules/RuleMergeCriteria.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/R=
uleMergeCriteria.java 2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/R=
uleMergeCriteria.java 2012-08-16 14:53:55 UTC (rev 4329)
@@ -74,9 +74,6 @@
=
public final class RuleMergeCriteria implements OptimizerRule {
=
- public static final String UNNEST_DEFAULT =3D "org.teiid.subqueryUnnestDe=
fault"; //$NON-NLS-1$ =
- private final boolean UNNEST =3D Boolean.getBoolean(UNNEST_DEFAULT); =
- =
/**
* Used to replace correlated references
*/
@@ -246,7 +243,7 @@
float sourceCost =3D NewCalculateCostUtil.computeCostForTree(current.get=
FirstChild(), metadata);
Criteria crit =3D (Criteria)current.getProperty(NodeConstants.Info.SELEC=
T_CRITERIA);
=
- PlannedResult plannedResult =3D findSubquery(crit);
+ PlannedResult plannedResult =3D findSubquery(crit, true);
if (plannedResult.query =3D=3D null) {
return current;
}
@@ -338,7 +335,7 @@
}
}
=
- public PlannedResult findSubquery(Criteria crit) throws TeiidComponentExc=
eption, QueryMetadataException {
+ public PlannedResult findSubquery(Criteria crit, boolean unnest) throws T=
eiidComponentException, QueryMetadataException {
PlannedResult result =3D new PlannedResult();
if (crit instanceof SubquerySetCriteria) {
//convert to the quantified form
@@ -350,12 +347,12 @@
result.type =3D crit.getClass();
result.mergeJoin =3D ssc.getSubqueryHint().isMergeJoin();
result.makeInd =3D ssc.getSubqueryHint().isDepJoin();
- if (!UNNEST && !result.mergeJoin) {
+ if (!unnest && !result.mergeJoin) {
return result;
}
crit =3D new SubqueryCompareCriteria(ssc.getExpression(), ssc.getComman=
d(), SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.SOME);
} else if (crit instanceof CompareCriteria) {
- if (!UNNEST) {
+ if (!unnest) {
return result;
}
//convert to the quantified form
@@ -406,7 +403,7 @@
//the correlations can only be in where (if no group by or aggregates) =
or having
result.mergeJoin =3D exists.getSubqueryHint().isMergeJoin();
result.makeInd =3D exists.getSubqueryHint().isDepJoin();
- if (!UNNEST && !result.mergeJoin) {
+ if (!unnest && !result.mergeJoin) {
return result;
}
result.query =3D (Query)exists.getCommand();
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStaga=
ingQueryPlanner.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQue=
ryPlanner.java 2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQue=
ryPlanner.java 2012-08-16 14:53:55 UTC (rev 4329)
@@ -256,7 +256,7 @@
}
ExistsCriteria ec =3D new ExistsCriteria();
ec.setSubqueryHint(new ExistsCriteria.SubqueryHint());
- ec.getSubqueryHint().setDepJoin(true);
+ ec.getSubqueryHint().setDepJoin();
ec.setCommand(query);
Criteria existing =3D stagableQuery.getCriteria();
stagableQuery.setCriteria(Criteria.combineCriteria(existing, e=
c));
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.j=
ava
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 20=
12-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 20=
12-08-16 14:53:55 UTC (rev 4329)
@@ -219,7 +219,7 @@
} else if (parts[i].equalsIgnoreCase(SubqueryHint.NOUNNEST)) {
hint.setNoUnnest(true);
} else if (parts[i].equalsIgnoreCase(SubqueryHint.DJ)) {
- hint.setDepJoin(true);
+ hint.setDepJoin();
}
}
return hint;
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter=
.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java =
2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java =
2012-08-16 14:53:55 UTC (rev 4329)
@@ -113,6 +113,17 @@
DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.Defaul=
tDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.LONG, =
DataTypeManager.DefaultDataTypes.FLOAT, DataTypeManager.DefaultDataT=
ypes.DOUBLE));
=
+ // Constants used in simplifying mathematical criteria
+ private final static Integer INTEGER_ZERO =3D new Integer(0);
+ private final static Double DOUBLE_ZERO =3D new Double(0);
+ private final static Float FLOAT_ZERO =3D new Float(0);
+ private final static Long LONG_ZERO =3D new Long(0);
+ private final static BigInteger BIG_INTEGER_ZERO =3D new BigInteger("0=
"); //$NON-NLS-1$
+ private final static BigDecimal BIG_DECIMAL_ZERO =3D new BigDecimal("0=
"); //$NON-NLS-1$
+ private final static Short SHORT_ZERO =3D new Short((short)0);
+ private final static Byte BYTE_ZERO =3D new Byte((byte)0);
+ private boolean rewriteAggs =3D true;
+ =
private QueryMetadataInterface metadata;
private CommandContext context;
=
@@ -425,7 +436,7 @@
names.add(gs.getName());
}
for (Iterator crits =3D current.iterator(); crits.hasNext();) {
- PlannedResult plannedResult =3D rmc.findSubquery(crits.next());
+ PlannedResult plannedResult =3D rmc.findSubquery(crits.next(), context!=
=3Dnull?context.getOptions().isSubqueryUnnestDefault():false);
if (plannedResult.not || plannedResult.query =3D=3D null || plannedResu=
lt.query.getProcessorPlan() !=3D null =
|| plannedResult.query.getWith() !=3D null) {
continue;
@@ -1289,17 +1300,6 @@
return false;
}
=
- // Constants used in simplifying mathematical criteria
- private Integer INTEGER_ZERO =3D new Integer(0);
- private Double DOUBLE_ZERO =3D new Double(0);
- private Float FLOAT_ZERO =3D new Float(0);
- private Long LONG_ZERO =3D new Long(0);
- private BigInteger BIG_INTEGER_ZERO =3D new BigInteger("0"); //$NON-NL=
S-1$
- private BigDecimal BIG_DECIMAL_ZERO =3D new BigDecimal("0"); //$NON-NL=
S-1$
- private Short SHORT_ZERO =3D new Short((short)0);
- private Byte BYTE_ZERO =3D new Byte((byte)0);
- private boolean rewriteAggs =3D true;
-
/**
* @param criteria
* @return CompareCriteria
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/ExistsCriteri=
a.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/ExistsCriteria.java=
2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/ExistsCriteria.java=
2012-08-16 14:53:55 UTC (rev 4329)
@@ -64,8 +64,8 @@
return noUnnest;
}
=
- public void setDepJoin(boolean depJoin) {
- this.depJoin =3D depJoin;
+ public void setDepJoin() {
+ this.depJoin =3D true;
this.mergeJoin =3D true;
}
=
Modified: trunk/engine/src/main/java/org/teiid/query/util/CommandContext.ja=
va
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java 201=
2-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java 201=
2-08-16 14:53:55 UTC (rev 4329)
@@ -146,6 +146,8 @@
private ClassLoader classLoader;
=
private List warnings =3D null;
+ =
+ private Options options =3D null;
}
=
private GlobalState globalState =3D new GlobalState();
@@ -814,5 +816,16 @@
public void setTupleSourceCache(TupleSourceCache tupleSourceCache) {
this.tupleSourceCache =3D tupleSourceCache;
}
+ =
+ public Options getOptions() {
+ if (this.globalState.options =3D=3D null) {
+ this.globalState.options =3D new Options();
+ }
+ return this.globalState.options;
+ }
+ =
+ public void setOptions(Options options) {
+ this.globalState.options =3D options;
+ }
=
}
Added: trunk/engine/src/main/java/org/teiid/query/util/Options.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/main/java/org/teiid/query/util/Options.java =
(rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/util/Options.java 2012-08-16=
14:53:55 UTC (rev 4329)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * =
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * =
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * =
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.util;
+
+import java.util.Properties;
+
+/**
+ * A holder for options
+ */
+public class Options {
+
+ public static final String UNNEST_DEFAULT =3D "org.teiid.subqueryUnnestDe=
fault"; //$NON-NLS-1$ =
+
+ private Properties properties;
+ private boolean subqueryUnnestDefault;
+ =
+ public Properties getProperties() {
+ return properties;
+ }
+ =
+ public void setProperties(Properties properties) {
+ this.properties =3D properties;
+ }
+ =
+ public boolean isSubqueryUnnestDefault() {
+ return subqueryUnnestDefault;
+ }
+ =
+ public void setSubqueryUnnestDefault(boolean subqueryUnnestDefault) {
+ this.subqueryUnnestDefault =3D subqueryUnnestDefault;
+ }
+ =
+ public Options subqueryUnnestDefault(boolean s) {
+ this.subqueryUnnestDefault =3D s;
+ return this;
+ } =
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/util/Option=
s.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubquery=
Pushdown.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdo=
wn.java 2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdo=
wn.java 2012-08-16 14:53:55 UTC (rev 4329)
@@ -25,7 +25,6 @@
import static org.junit.Assert.*;
import static org.teiid.query.optimizer.TestOptimizer.*;
=
-import org.junit.After;
import org.junit.Test;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -37,10 +36,11 @@
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capabilit=
y;
-import org.teiid.query.optimizer.relational.rules.RuleMergeCriteria;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.rewriter.TestQueryRewriter;
import org.teiid.query.unittest.RealMetadataFactory;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.Options;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.SourceSystemFunctions;
=
@@ -392,9 +392,9 @@
}
=
/**
- * Check that subquery is not pushed if the subquery cannot all be pus=
hed to the source.
+ * Check that subquery is not pushed if the subquery cannot all be pus=
hed to the source. Automatically converted to a merge join
*/
- @Test public void testNoPushSubqueryInWhereClause1() {
+ @Test public void testNoPushSubqueryInWhereClause1() throws Exception {
FakeCapabilitiesFinder capFinder =3D new FakeCapabilitiesFinder();
BasicSourceCapabilities caps =3D getTypicalCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
@@ -403,25 +403,25 @@
=
ProcessorPlan plan =3D helpPlan("Select e1 from pm1.g1 where e1 in=
(select max(e1) FROM pm1.g2)", RealMetadataFactory.example1Cached(), //$N=
ON-NLS-1$
null, capFinder,
- new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$=
NON-NLS-1$ =
+ new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER =
BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ =
checkNodeTypes(plan, new int[] {
1, // Access
0, // DependentAccess
- 1, // DependentSelect
+ 0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
- 0, // MergeJoinStrategy
+ 1, // MergeJoinStrategy
0, // Null
- 0, // PlanExecution
+ 1, // PlanExecution
1, // Project
0, // Select
0, // Sort
0 // UnionAll
});
}
-
+ =
/**
* Check that subquery is not pushed if the subquery is from a differe=
nt model
* than the outer query.
@@ -768,16 +768,18 @@
}
=
@Test public void testSubqueryRewriteToJoinDistinct() throws Exception=
{
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from =
pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 =3D x.e1)",=
"SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) AS X_=
_1 WHERE x.e1 =3D X__1.e1", RealMetadataFactory.example1Cached());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from =
pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 =3D x.e1)",=
"SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) AS X_=
_1 WHERE x.e1 =3D X__1.e1", RealMetadataFactory.example1Cached(), cc);
}
=
/**
* Agg does not depend on cardinality
*/
@Test public void testSubqueryRewriteToJoinGroupBy() throws Exception {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select max(e1) from pm1.=
g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 =3D x.e1) group=
by e2", "SELECT MAX(e1) FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) A=
S X__1 WHERE x.e1 =3D X__1.e1 GROUP BY e2", RealMetadataFactory.example1Cac=
hed());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select max(e1) from pm1.=
g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 =3D x.e1) group=
by e2", "SELECT MAX(e1) FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) A=
S X__1 WHERE x.e1 =3D X__1.e1 GROUP BY e2", RealMetadataFactory.example1Cac=
hed(), cc);
}
=
/**
@@ -788,8 +790,9 @@
}
=
@Test public void testSubqueryRewriteToJoin() throws Exception {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere exists (select pm1.g1.e1 FROM pm1.g1 where e1 =3D pm3.g1.e1)", "SELECT =
e1 FROM pm3.g1, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE pm3.g1.e1 =3D =
X__1.e1", RealMetadataFactory.example4());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere exists (select pm1.g1.e1 FROM pm1.g1 where e1 =3D pm3.g1.e1)", "SELECT =
e1 FROM pm3.g1, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE pm3.g1.e1 =3D =
X__1.e1", RealMetadataFactory.example4(), cc);
}
=
@Test public void testSubqueryRewriteToJoin1() throws Exception {
@@ -816,13 +819,15 @@
}
=
@Test public void testDontRewriteToJoinWithOtherCriteria() throws Exce=
ption {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e1 in /*+ NO_UNNEST */ (select pm1.g1.e1 FROM pm1.g1 where e2 < =
pm3.g1.e2)", "SELECT e1 FROM pm3.g1 WHERE pm3.g1.e1 IN /*+ NO_UNNEST */ (SE=
LECT pm1.g1.e1 FROM pm1.g1 WHERE e2 < pm3.g1.e2)", RealMetadataFactory.exam=
ple4());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e1 in /*+ NO_UNNEST */ (select pm1.g1.e1 FROM pm1.g1 where e2 < =
pm3.g1.e2)", "SELECT e1 FROM pm3.g1 WHERE pm3.g1.e1 IN /*+ NO_UNNEST */ (SE=
LECT pm1.g1.e1 FROM pm1.g1 WHERE e2 < pm3.g1.e2)", RealMetadataFactory.exam=
ple4(), cc);
}
=
@Test public void testSubqueryRewriteToJoinWithAggregate() throws Exce=
ption {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e2 < (select max(e2) FROM pm1.g1 where pm3.g1.e1 =3D e1)", "SELE=
CT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1 FROM pm1.g1 GROUP BY e1) AS=
X__1 WHERE (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 =3D X__1.e1)", RealMeta=
dataFactory.example4());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e2 < (select max(e2) FROM pm1.g1 where pm3.g1.e1 =3D e1)", "SELE=
CT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1 FROM pm1.g1 GROUP BY e1) AS=
X__1 WHERE (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 =3D X__1.e1)", RealMeta=
dataFactory.example4(), cc);
}
=
/**
@@ -834,13 +839,15 @@
}
=
@Test public void testSubqueryRewriteToJoinWithAggregate2() throws Exc=
eption {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e2 < (select max(e2) FROM pm1.g1 WHERE pm3.g1.e1 =3D e1 HAVING m=
in(e3) < pm3.g1.e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1,=
MIN(e3) AS expr3 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (X__1.expr3 < pm3.=
g1.e3) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 =3D X__1.e1)", RealMetad=
ataFactory.example4());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e2 < (select max(e2) FROM pm1.g1 WHERE pm3.g1.e1 =3D e1 HAVING m=
in(e3) < pm3.g1.e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1,=
MIN(e3) AS expr3 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (X__1.expr3 < pm3.=
g1.e3) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 =3D X__1.e1)", RealMetad=
ataFactory.example4(), cc);
}
=
@Test public void testSubqueryRewriteToJoinWithGroupingExpression() th=
rows Exception {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from =
pm3.g1 where exists (select 1 FROM pm1.g1 group by e4 || 'x' HAVING min(e3)=
|| (e4 || 'x') =3D pm3.g1.e3)", "SELECT DISTINCT e1 FROM pm3.g1, (SELECT 1=
AS expr1, MIN(e3) AS expr2, concat(convert(e4, string), 'x') AS expr3, con=
cat(convert(MIN(e3), string), concat(convert(e4, string), 'x')) AS expr FRO=
M pm1.g1 GROUP BY concat(convert(e4, string), 'x')) AS X__1 WHERE convert(p=
m3.g1.e3, string) =3D X__1.expr", RealMetadataFactory.example4());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from =
pm3.g1 where exists (select 1 FROM pm1.g1 group by e4 || 'x' HAVING min(e3)=
|| (e4 || 'x') =3D pm3.g1.e3)", "SELECT DISTINCT e1 FROM pm3.g1, (SELECT 1=
AS expr1, MIN(e3) AS expr2, concat(convert(e4, string), 'x') AS expr3, con=
cat(convert(MIN(e3), string), concat(convert(e4, string), 'x')) AS expr FRO=
M pm1.g1 GROUP BY concat(convert(e4, string), 'x')) AS X__1 WHERE convert(p=
m3.g1.e3, string) =3D X__1.expr", RealMetadataFactory.example4(), cc);
}
=
/**
@@ -876,8 +883,9 @@
}
=
@Test public void testSubqueryExpressionJoin() throws Exception {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
- TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e2 < (Select max(e2) from pm2.g2 where e1 =3D pm3.g1.e1 having c=
onvert(min(e2), string) > pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT MAX(=
e2) AS expr1, e1, MIN(e2) AS expr3 FROM pm2.g2 GROUP BY e1) AS X__1 WHERE (=
convert(X__1.expr3, string) > pm3.g1.e1) AND (pm3.g1.e2 < X__1.expr1) AND (=
pm3.g1.e1 =3D X__1.e1)", RealMetadataFactory.example4());
+ CommandContext cc =3D new CommandContext();
+ cc.setOptions(new Options().subqueryUnnestDefault(true));
+ TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 wh=
ere pm3.g1.e2 < (Select max(e2) from pm2.g2 where e1 =3D pm3.g1.e1 having c=
onvert(min(e2), string) > pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT MAX(=
e2) AS expr1, e1, MIN(e2) AS expr3 FROM pm2.g2 GROUP BY e1) AS X__1 WHERE (=
convert(X__1.expr3, string) > pm3.g1.e1) AND (pm3.g1.e2 < X__1.expr1) AND (=
pm3.g1.e1 =3D X__1.e1)", RealMetadataFactory.example4(), cc);
}
=
/**
@@ -933,7 +941,6 @@
* Same as above, but the source is much larger, so a semi-join is fav=
orable
*/
@Test public void testSemiJoinExistsCosting() {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toS=
tring());
ProcessorPlan plan =3D helpPlan("Select e1 from pm2.g2 as o where =
not exists (select 1 from pm3.g1 where e1 =3D o.e1 having o.e2 =3D count(e2=
))", RealMetadataFactory.example4(), //$NON-NLS-1$
new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm2.g=
2 AS g_0 ORDER BY c_0, c_1" }); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
@@ -977,10 +984,6 @@
checkJoinCounts(plan, 0, 1);
}
=
- @After public void tearDown() {
- System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.FALSE.to=
String());
- }
- =
@Test public void testAntiSemiJoinInHint() {
ProcessorPlan plan =3D helpPlan("Select e1 from pm1.g2 as o where =
e2 NOT IN /*+ MJ */ (select count(e2) from pm3.g1 where e1 =3D o.e1)", Real=
MetadataFactory.example4(), //$NON-NLS-1$
new String[] { "SELECT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g=
2 AS g_0 ORDER BY c_1, c_0" }); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewr=
iter.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.j=
ava 2012-08-16 13:32:05 UTC (rev 4328)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.j=
ava 2012-08-16 14:53:55 UTC (rev 4329)
@@ -173,11 +173,15 @@
}
=
public static Command helpTestRewriteCommand(String original, String e=
xpected, QueryMetadataInterface metadata) throws TeiidException { =
- Command command =3D QueryParser.getQueryParser().parseCommand(orig=
inal); =
- QueryResolver.resolveCommand(command, metadata);
- Command rewriteCommand =3D QueryRewriter.rewrite(command, metadata=
, null);
- assertEquals("Rewritten command was not expected", expected, rewri=
teCommand.toString()); //$NON-NLS-1$
- return rewriteCommand;
+ return helpTestRewriteCommand(original, expected, metadata, null);
+ }
+ =
+ public static Command helpTestRewriteCommand(String original, String e=
xpected, QueryMetadataInterface metadata, CommandContext cc) throws TeiidEx=
ception {
+ Command command =3D QueryParser.getQueryParser().parseCommand(origina=
l); =
+ QueryResolver.resolveCommand(command, metadata);
+ Command rewriteCommand =3D QueryRewriter.rewrite(command, metadata=
, cc);
+ assertEquals("Rewritten command was not expected", expected, rewri=
teCommand.toString()); //$NON-NLS-1$
+ return rewriteCommand;
}
=
@Test public void testRewriteUnknown() {
--===============0676595553535927728==--