Uploaded image for project: 'Teiid'
  1. Teiid
  2. TEIID-3949

Subqueries are wrongly pushed down to the underlying datasource

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 9.0, 8.12.5, 8.13.1
    • 8.12
    • Query Engine
    • None

      I have two schemas, one in PostgreSQL and another one in MySQL, called "pg" and "my" respectively.

      I defined the following tables in PG:

      CREATE TABLE test_a (a integer, b integer);
      CREATE TABLE test_only_pg (a integer, b integer);
      

      and this table in MySQL:

      CREATE TABLE `test_b` (
        `b` int(11),
        `c` int(11)
      )
      

      When I run this query:

      SELECT
      	SUM(x.b - (SELECT a FROM pg.test_only_pg WHERE b = 1))
      FROM my.test_b x
      INNER JOIN pg.test_a y ON x.b = y.b
      

      I get the following exception:

      16:44:54,776 WARN  [org.teiid.CONNECTOR] (Worker2_QueryProcessorQueue28) QWfZdmacM17x Connector worker process failed for atomic-request=QWfZdmacM17x.12.7.4: org.teiid.translator.jdbc.JDBCExecutionException: 1146 TEIID11008:TEIID11004 Error executing statement(s): [Prepared Values: [] SQL: SELECT g_0.`b` AS c_0, SUM((g_0.`b` - (SELECT g_1."a" AS c_0 FROM "public"."test_only_pg" AS g_1 WHERE g_1."b" = 1 LIMIT 2))) AS c_1 FROM `test_tables`.`test_b` AS g_0 GROUP BY g_0.`b` ORDER BY c_0]
              at org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:131) [translator-jdbc-8.12.4.jar:8.12.4]
              at org.teiid.dqp.internal.datamgr.ConnectorWorkItem.execute(ConnectorWorkItem.java:356)
              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:306)
              at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:112)
              at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:108)
              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:65)
              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: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'public.test_only_pg' doesn't exist
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_67]
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_67]
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_67]
              at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_67]
              at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
              at com.mysql.jdbc.Util.getInstance(Util.java:386)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
              at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
              at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
              at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
              at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
              at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
              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.4.jar:8.12.4]
              ... 18 more
      

      I could reproduce this behavior in Teiid 8.12.4.

              rhn-engineering-shawkins Steven Hawkins
              redfox999 Salvatore R. (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: