Wrong alias rewriting in subqueries
-----------------------------------
Key: TEIID-3846
URL:
https://issues.jboss.org/browse/TEIID-3846
Project: Teiid
Issue Type: Bug
Components: Query Engine
Affects Versions: 8.7
Reporter: Salvatore R
Assignee: Steven Hawkins
Fix For: 8.12.3, 8.13
I defined two tables in PostgreSQL (but it's reproducible also in other databases
like MySQL, for example) as follows:
{code:sql}
CREATE TABLE test_a
(
a integer,
b integer
);
CREATE TABLE test_b
(
b integer,
c integer
);
{code}
Running this query:
{code:sql}
SELECT
*
FROM
( SELECT
( SELECT x.a FROM pg.test_a AS x WHERE x.b = g_0.c ) AS c_2
FROM
pg.test_b AS g_0
) AS v_0
{code}
I get the following exception:
{code:sql}
13:11:30,073 WARN [org.teiid.CONNECTOR] (Worker5_QueryProcessorQueue50) 1iTDksSjXt1V
Connector worker process failed for atomic-request=1iTDksSjXt1V.16.1.11:
org.teiid.translator.jdbc.JDBCExecutionException: 0 TEIID11008:TEIID11004 Error executing
statement(s): [Prepared Values: [] SQL: SELECT v_0.c_0 FROM (SELECT (SELECT
g_1."a" FROM "public"."test_a" AS g_1 WHERE
g_1."b" = g_1."c") AS c_0 FROM "public"."test_b"
AS g_0) AS v_0]
at
org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:131)
[translator-jdbc-8.12.0.CR1.jar:8.12.0.CR1]
at
org.teiid.dqp.internal.datamgr.ConnectorWorkItem.execute(ConnectorWorkItem.java:349)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_67]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[rt.jar:1.7.0_67]
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[rt.jar:1.7.0_67]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_67]
at
org.teiid.dqp.internal.datamgr.ConnectorManager$1.invoke(ConnectorManager.java:211)
at com.sun.proxy.$Proxy47.execute(Unknown Source)
at
org.teiid.dqp.internal.process.DataTierTupleSource.getResults(DataTierTupleSource.java:298)
at
org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:110)
at
org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:107)
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_67]
at org.teiid.dqp.internal.process.FutureWork.run(FutureWork.java:58)
at
org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:276)
at
org.teiid.dqp.internal.process.ThreadReuseExecutor$RunnableWrapper.run(ThreadReuseExecutor.java:119)
at
org.teiid.dqp.internal.process.ThreadReuseExecutor$3.run(ThreadReuseExecutor.java:210)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[rt.jar:1.7.0_67]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[rt.jar:1.7.0_67]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]
Caused by: org.postgresql.util.PSQLException: ERROR: column g_1.c does not exist
Position: 91
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
at
org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:123)
[translator-jdbc-8.12.0.CR1.jar:8.12.0.CR1]
... 18 more
{code}
It seems that the problem is related to the alias "g_0" used for the source
table "pg.test_b". In fact, if a different alias is used, the query runs without
errors:
{code:sql}
SELECT
*
FROM
( SELECT
( SELECT x.a FROM pg.test_a AS x WHERE x.b = y.c ) AS c_2
FROM
pg.test_b AS y
) AS v_0
{code}