[teiid-issues] [JBoss JIRA] (TEIID-3568) Order By and Limit are not getting pushed to the database, when Union and join are used together.

Guru Prasad (JIRA) issues at jboss.org
Thu Aug 20 05:43:26 EDT 2015


    [ https://issues.jboss.org/browse/TEIID-3568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13100121#comment-13100121 ] 

Guru Prasad commented on TEIID-3568:
------------------------------------

I have tried analyzing the plan for a similar query(PushOrderByLimitTest1.java) using
teiid-engine-8.12.0.Alpha3-SNAPSHOT.jar. 

This works perfect even when the translator has no support for union. 

In the case of when the translator has no support for InlineViews, the ordered limit still doesn't get pushed to the db.

*Query:*
SELECT u.uniqueName, u.majorsubject, u.minorsubject FROM
(select uniqueName, majorsubject, minorsubject, cityid from TESTSCHEMA.student
UNION ALL
select uniqueName, majorsubject, minorsubject, cityid from TESTSCHEMA.student1) as u
LEFT OUTER JOIN TESTSCHEMA.city AS tp ON tp.cityid = u.cityid
where u.uniqueName is null ORDER BY u.uniqueName LIMIT 8

*Plan:*
ProjectNode
  + Relational Node ID:0
  + Output Columns:
    0: UNIQUENAME (string)
    1: MAJORSUBJECT (string)
    2: MINORSUBJECT (string)
  + Statistics:
    0: Node Output Rows: 0
    1: Node Next Batch Process Time: 0
    2: Node Cumulative Next Batch Process Time: 0
    3: Node Cumulative Process Time: 0
    4: Node Next Batch Calls: 0
    5: Node Blocks: 0
  + Cost Estimates:Estimated Node Cardinality: 8.0
  + Child 0:
    LimitNode
      + Relational Node ID:1
      + Output Columns:
        0: UNIQUENAME (string)
        1: MAJORSUBJECT (string)
        2: MINORSUBJECT (string)
      + Statistics:
        0: Node Output Rows: 0
        1: Node Next Batch Process Time: 0
        2: Node Cumulative Next Batch Process Time: 0
        3: Node Cumulative Process Time: 0
        4: Node Next Batch Calls: 0
        5: Node Blocks: 0
      + Cost Estimates:Estimated Node Cardinality: 8.0
      + Child 0:
        SortNode
          + Relational Node ID:2
          + Output Columns:
            0: UNIQUENAME (string)
            1: MAJORSUBJECT (string)
            2: MINORSUBJECT (string)
          + Statistics:
            0: Node Output Rows: 0
            1: Node Next Batch Process Time: 0
            2: Node Cumulative Next Batch Process Time: 0
            3: Node Cumulative Process Time: 0
            4: Node Next Batch Calls: 0
            5: Node Blocks: 0
          + Cost Estimates:Estimated Node Cardinality: -1.0
          + Child 0:
            JoinNode
              + Relational Node ID:3
              + Output Columns:
                0: UNIQUENAME (string)
                1: MAJORSUBJECT (string)
                2: MINORSUBJECT (string)
              + Statistics:
                0: Node Output Rows: 0
                1: Node Next Batch Process Time: 10
                2: Node Cumulative Next Batch Process Time: 20
                3: Node Cumulative Process Time: 57
                4: Node Next Batch Calls: 2
                5: Node Blocks: 1
              + Cost Estimates:Estimated Node Cardinality: -1.0
              + Child 0:
                LimitNode
                  + Relational Node ID:4
                  + Output Columns:
                    0: CITYID (integer)
                    1: UNIQUENAME (string)
                    2: MAJORSUBJECT (string)
                    3: MINORSUBJECT (string)
                  + Statistics:
                    0: Node Output Rows: 0
                    1: Node Next Batch Process Time: 0
                    2: Node Cumulative Next Batch Process Time: 0
                    3: Node Cumulative Process Time: 0
                    4: Node Next Batch Calls: 0
                    5: Node Blocks: 0
                  + Cost Estimates:Estimated Node Cardinality: 8.0
                  + Child 0:
                    SortNode
                      + Relational Node ID:5
                      + Output Columns:
                        0: CITYID (integer)
                        1: UNIQUENAME (string)
                        2: MAJORSUBJECT (string)
                        3: MINORSUBJECT (string)
                      + Statistics:
                        0: Node Output Rows: 0
                        1: Node Next Batch Process Time: 0
                        2: Node Cumulative Next Batch Process Time: 0
                        3: Node Cumulative Process Time: 0
                        4: Node Next Batch Calls: 0
                        5: Node Blocks: 0
                      + Cost Estimates:Estimated Node Cardinality: -1.0
                      + Child 0:
                        AccessNode
                          + Relational Node ID:6
                          + Output Columns:
                            0: CITYID (integer)
                            1: UNIQUENAME (string)
                            2: MAJORSUBJECT (string)
                            3: MINORSUBJECT (string)
                          + Statistics:
                            0: Node Output Rows: 0
                            1: Node Next Batch Process Time: 0
                            2: Node Cumulative Next Batch Process Time: 0
                            3: Node Cumulative Process Time: 37
                            4: Node Next Batch Calls: 3
                            5: Node Blocks: 2
                          + Cost Estimates:Estimated Node Cardinality: -1.0
                          + Query:SELECT g_1.CITYID AS c_0, g_1.UNIQUENAME AS c_1, g_1.MAJORSUBJECT AS c_2, g_1.MINORSUBJECT AS c_3 FROM actions.ACTIONS.TESTSCHEMA.STUDENT AS g_1 WHERE g_1.UNIQUENAME IS NULL UNION ALL SELECT g_0.CITYID AS c_0, g_0.UNIQUENAME AS c_1, g_0.MAJORSUBJECT AS c_2, g_0.MINORSUBJECT AS c_3 FROM actions.ACTIONS.TESTSCHEMA.STUDENT1 AS g_0 WHERE g_0.UNIQUENAME IS NULL
                          + Model Name:actions
                      + Sort Columns:[actions.ACTIONS.TESTSCHEMA.STUDENT.UNIQUENAME]
                      + Sort Mode:SORT
                  + Row Offset:null
                  + Row Limit:8
              + Child 1:
                AccessNode
                  + Relational Node ID:7
                  + Output Columns:CITYID (integer)
                  + Statistics:
                    0: Node Output Rows: 0
                    1: Node Next Batch Process Time: 10
                    2: Node Cumulative Next Batch Process Time: 10
                    3: Node Cumulative Process Time: 47
                    4: Node Next Batch Calls: 2
                    5: Node Blocks: 1
                  + Cost Estimates:Estimated Node Cardinality: -1.0
                  + Query:SELECT g_0.CITYID AS c_0 FROM actions.ACTIONS.TESTSCHEMA.CITY AS g_0 ORDER BY c_0
                  + Model Name:actions
              + Join Strategy:ENHANCED SORT JOIN RAN AS SORT MERGE (SORT/ALREADY_SORTED)
              + Join Type:LEFT OUTER JOIN
              + Join Criteria:u.CITYID=tp.CITYID
          + Sort Columns:[u.UNIQUENAME]
          + Sort Mode:SORT
      + Row Offset:null
      + Row Limit:8
  + Select Columns:
    0: u.UNIQUENAME
    1: u.MAJORSUBJECT
    2: u.MINORSUBJECT
  + Data Bytes Sent:0
  + Planning Time:80

> Order By and Limit are not getting pushed to the database, when Union and join are used together. 
> --------------------------------------------------------------------------------------------------
>
>                 Key: TEIID-3568
>                 URL: https://issues.jboss.org/browse/TEIID-3568
>             Project: Teiid
>          Issue Type: Enhancement
>          Components: Query Engine
>    Affects Versions: 8.1
>            Reporter: Guru Prasad
>            Assignee: Steven Hawkins
>             Fix For: 8.12
>
>         Attachments: Jars in build path.txt, PushOrderByLimitTest1.java, ShowPlan.txt
>
>
> Order By and Limit are not getting pushed to the database, when Union and join are used together. 
> In this scenario there if the underlying table has millions of records the query never returns with data.
> *Query 1*: Using only Join without union, this works fine.
> SELECT u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode FROM ( 	
> 	select evttypecode, evtsysid, evtutctod, evtsystod, evtcatcode from XYZ.Tab1 
> ) as u 
> LEFT OUTER JOIN XYZ.CATEGORY AS ct ON u.evtcatcode = ct.evtcatcode 
> WHERE (u.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (u.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) ORDER BY u.evtsysid LIMIT 8
> PROCESSOR PLAN:
> AccessNode(0) output=[evttypecode AS evttypecode, evtsysid AS evtsysid, evtutctod AS evtutctod, evtsystod AS evtsystod, evtcatcode AS evtcatcode] 
> SELECT g_0.EVTTYPECODE AS c_0, g_0.EVTSYSID AS c_1, g_0.EVTUTCTOD AS c_2, g_0.EVTSYSTOD AS c_3, g_0.EVTCATCODE AS c_4 FROM ABC.Tab1 AS g_0 LEFT OUTER JOIN ABC.CATEGORY AS g_1 ON g_0.EVTCATCODE = g_1.EVTCATCODE WHERE (g_0.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (g_0.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) ORDER BY c_1 LIMIT 8
> *Query 2*: Using only Union without any join, this also works fine.
> SELECT u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode FROM ( 	
> 	select evttypecode, evtsysid, evtutctod, evtsystod, evtcatcode from XYZ.Tab1 
> 	UNION ALL 
> 	select evttypecode, evtsysid, evtutctod, evtsystod, evtcatcode from XYZ.Tab2
> ) as u 
> WHERE (u.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (u.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) ORDER BY u.evtsysid LIMIT 8
> PROCESSOR PLAN:
> AccessNode(0) output=[evttypecode AS evttypecode, evtsysid AS evtsysid, evtutctod AS evtutctod, evtsystod AS evtsystod, evtcatcode AS evtcatcode] 
> SELECT g_1.EVTTYPECODE AS c_0, g_1.EVTSYSID AS c_1, g_1.EVTUTCTOD AS c_2, g_1.EVTSYSTOD AS c_3, g_1.EVTCATCODE AS c_4 FROM ABC.Tab1 AS g_1 WHERE (g_1.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (g_1.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) UNION ALL 
> SELECT g_0.EVTTYPECODE AS c_0, g_0.EVTSYSID AS c_1, g_0.EVTUTCTOD AS c_2, g_0.EVTSYSTOD AS c_3, g_0.EVTCATCODE AS c_4 FROM ABC.Tab2 AS g_0 WHERE (g_0.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (g_0.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) ORDER BY c_1 LIMIT 8
> *Query 3*: Using both Union and join, this does not push down the order by and limit.
> SELECT u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode FROM ( 	
> 	select evttypecode, evtsysid, evtutctod, evtsystod, evtcatcode from XYZ.Tab1 
> 	UNION ALL 
> 	select evttypecode, evtsysid, evtutctod, evtsystod, evtcatcode from XYZ.Tab2
> ) as u 
> LEFT OUTER JOIN XYZ.EVTTYPE AS tp ON tp.evttypecode = u.evttypecode 
> LEFT OUTER JOIN XYZ.CATEGORY AS ct ON u.evtcatcode = ct.evtcatcode 
> WHERE (u.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (u.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) ORDER BY u.evtsysid LIMIT 8
> PROCESSOR PLAN:
> ProjectNode(0) output=[u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode] [u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode]
>   LimitNode(1) output=[u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode] limit 8
>     SortNode(2) output=[u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode] [SORT] [u.evtsysid]
>       JoinNode(3) [MERGE JOIN (SORT/ALREADY_SORTED)] [LEFT OUTER JOIN] criteria=[u.evtcatcode=evtcatcode] output=[u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod, u.evtcatcode]
>         JoinNode(4) [MERGE JOIN (SORT/ALREADY_SORTED)] [LEFT OUTER JOIN] criteria=[u.evttypecode=evttypecode] output=[u.evtcatcode, u.evttypecode, u.evtsysid, u.evtutctod, u.evtsystod]
>           AccessNode(5) output=[u.evttypecode, u.evtcatcode, u.evtsysid, u.evtutctod, u.evtsystod] 
> 					SELECT g_1.EVTTYPECODE AS c_0, g_1.EVTCATCODE AS c_1, g_1.EVTSYSID AS c_2, g_1.EVTUTCTOD AS c_3, g_1.EVTSYSTOD AS c_4 FROM ABC.Tab1 AS g_1 WHERE (g_1.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (g_1.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'}) 
> 		  UNION ALL SELECT g_0.EVTTYPECODE AS c_0, g_0.EVTCATCODE AS c_1, g_0.EVTSYSID AS c_2, g_0.EVTUTCTOD AS c_3, g_0.EVTSYSTOD AS c_4 FROM ABC.Tab2 AS g_0 WHERE (g_0.EVTUTCTOD >= {ts'2015-06-03 19:20:00.8'}) AND (g_0.EVTUTCTOD <= {ts'2015-06-03 19:20:01.0'})
>           AccessNode(6) output=[evttypecode] SELECT g_0.EVTTYPECODE AS c_0 FROM ABC.EVTTYPE AS g_0 ORDER BY c_0
>         AccessNode(7) output=[evtcatcode] SELECT g_0.EVTCATCODE AS c_0 FROM ABC.CATEGORY AS g_0 ORDER BY c_0



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the teiid-issues mailing list