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

CBO: "Struct is not null" gets evaluated as `nullable` always causing filter miss in the query

    XMLWordPrintableJSON

Details

    Description

      drop table if exists test_struct;
      CREATE external TABLE test_struct
      (
        f1 string,
        demo_struct struct<f1:string, f2:string, f3:string>,
        datestr string
      );
      
      set hive.cbo.enable=true;
      explain select * from etltmp.test_struct where datestr='2019-01-01' and demo_struct is not null;
      
      
      
      STAGE PLANS:
        Stage: Stage-0
          Fetch Operator
            limit: -1
            Processor Tree:
              TableScan
                alias: test_struct
                filterExpr: (datestr = '2019-01-01') (type: boolean) <----- Note that demo_struct filter is not added here
                Filter Operator
                  predicate: (datestr = '2019-01-01') (type: boolean)
                  Select Operator
                    expressions: f1 (type: string), demo_struct (type: struct<f1:string,f2:string,f3:string>), '2019-01-01' (type: string)
                    outputColumnNames: _col0, _col1, _col2
                    ListSink
      
      
      set hive.cbo.enable=false;
      explain select * from etltmp.test_struct where datestr='2019-01-01' and demo_struct is not null;
      
      
      STAGE PLANS:
        Stage: Stage-0
          Fetch Operator
            limit: -1
            Processor Tree:
              TableScan
                alias: test_struct
                filterExpr: ((datestr = '2019-01-01') and demo_struct is not null) (type: boolean) <----- Note that demo_struct filter is added when CBO is turned off
                Filter Operator
                  predicate: ((datestr = '2019-01-01') and demo_struct is not null) (type: boolean)
                  Select Operator
                    expressions: f1 (type: string), demo_struct (type: struct<f1:string,f2:string,f3:string>), '2019-01-01' (type: string)
                    outputColumnNames: _col0, _col1, _col2
                    ListSink
      
      

      In CalcitePlanner::genFilterRelNode, the following code misses to evaluate this filter.

      RexNode factoredFilterExpr = RexUtil
                .pullFactors(cluster.getRexBuilder(), convertedFilterExpr);
      

      Note that even if we add `demo_struct.f1` it would end up pushing the filter correctly.

      Attachments

        1. HIVE-21778.8.patch
          34 kB
          Vineet Garg
        2. HIVE-21778.7.patch
          34 kB
          Vineet Garg
        3. HIVE-21778.6.patch
          34 kB
          Vineet Garg
        4. HIVE-21778.5.patch
          33 kB
          Vineet Garg
        5. HIVE-21778.4.patch
          33 kB
          Vineet Garg
        6. HIVE-21778.3.patch
          30 kB
          Vineet Garg
        7. HIVE-21778.2.patch
          13 kB
          Vineet Garg
        8. HIVE-21778.1.patch
          4 kB
          Vineet Garg
        9. test_null.q.out
          3 kB
          Rajesh Balamohan
        10. test_null.q
          0.3 kB
          Rajesh Balamohan

        Issue Links

          Activity

            People

              vgarg Vineet Garg
              rajesh.balamohan Rajesh Balamohan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m