Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-23457

Hive Incorrect result with subquery while optimizer misses the aggregation stage

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 3.2.0
    • None
    • Hive
    • None

    Description

      Steps to Repro:

      create table abc (id int);
      insert into table abc values (1),(2),(3),(4),(5),(6);
      select * from abc order by id desc
      6
      5
      4
      3
      2
      1
      select `id` from (select * from abc order by id desc ) as tmp;
      1
      2
      3
      4
      5
      6
       
      

      looking at the query plan it seems while using the subquery optimizer missed the aggregation stage, I cant see any reduce stage.

      set hive.query.results.cache.enabled=false;
      explain select * from abc order by id desc;
      +----------------------------------------------------+
      |                      Explain                       |
      +----------------------------------------------------+
      | Plan optimized by CBO.                             |
      |                                                    |
      | Vertex dependency in root stage                    |
      | Reducer 2 <- Map 1 (SIMPLE_EDGE)                   |
      |                                                    |
      | Stage-0                                            |
      |   Fetch Operator                                   |
      |     limit:-1                                       |
      |     Stage-1                                        |
      |       Reducer 2 vectorized                         |
      |       File Output Operator [FS_8]                  |
      |         Select Operator [SEL_7] (rows=6 width=4)   |
      |           Output:["_col0"]                         |
      |         <-Map 1 [SIMPLE_EDGE] vectorized           |
      |           SHUFFLE [RS_6]                           |
      |             Select Operator [SEL_5] (rows=6 width=4) |
      |               Output:["_col0"]                     |
      |               TableScan [TS_0] (rows=6 width=4)    |
      |                 default@abc,abc, ACID table,Tbl:COMPLETE,Col:COMPLETE,Output:["id"] |
      |                                                    |
      +----------------------------------------------------+
      
      
      explain select `id` from (select * from abc order by id desc ) as tmp;
      +------------------------------+
      |           Explain            |
      +------------------------------+
      | Plan optimized by CBO.       |
      |                              |
      | Stage-0                      |
      |   Fetch Operator             |
      |     limit:-1                 |
      |     Select Operator [SEL_1]  |
      |       Output:["_col0"]       |
      |       TableScan [TS_0]       |
      |         Output:["id"]        |
      |                              |
      +------------------------------+
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Rajkumar Singh Rajkumar Singh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: