wangsheng has posted comments on this change. ( 
http://gerrit.cloudera.org:8080/18023 )

Change subject: IMPALA-7942: Add query hints for cardinalities and selectivities
......................................................................


Patch Set 8:

> Code modification to facilitate above general version of grammar to
 > handle predicates and selectivity hints.
 >
 > Since we put the hint at the class Predicate, it looks like we can
 > get the hint for any simple or complex predicate at the right
 > place.
 >
 > [15:00:23 qchen@qifan-10229: Impala.07202021] git diff
 > diff --git a/fe/src/main/cup/sql-parser.cup b/fe/src/main/cup/sql-parser.cup
 > index bbd1e53d0..bef0b3c1d 100644
 > --- a/fe/src/main/cup/sql-parser.cup
 > +++ b/fe/src/main/cup/sql-parser.cup
 > @@ -307,7 +307,7 @@ terminal
 > KW_RANGE, KW_RCFILE, KW_RECOVER, KW_REFERENCES, KW_REFRESH,
 > KW_REGEXP, KW_RELY,
 > KW_RENAME, KW_REPEATABLE, KW_REPLACE, KW_REPLICATION, KW_RESTRICT,
 > KW_RETURNS,
 > KW_REVOKE, KW_RIGHT, KW_RLIKE, KW_ROLE, KW_ROLES, KW_ROLLUP,
 > KW_ROW, KW_ROWS, KW_SCHEMA,
 > -  KW_SCHEMAS, KW_SELECT, KW_SEMI, KW_SEQUENCEFILE,
 > KW_SERDEPROPERTIES, KW_SERIALIZE_FN,
 > +  KW_SCHEMAS, KW_SELECT,  KW_SELECTIVITY, KW_SEMI,
 > KW_SEQUENCEFILE, KW_SERDEPROPERTIES, KW_SERIALIZE_FN,
 > KW_SET, KW_SHOW, KW_SMALLINT, KW_SETS, KW_SORT, KW_SPEC, KW_STORED,
 > KW_STRAIGHT_JOIN,
 > KW_STRING, KW_STRUCT, KW_SYMBOL, KW_SYSTEM_TIME, KW_SYSTEM_VERSION,
 > KW_TABLE, KW_TABLES, KW_TABLESAMPLE, KW_TBLPROPERTIES,
 > @@ -431,7 +431,7 @@ nonterminal TimeTravelSpec opt_asof;
 > nonterminal Subquery subquery;
 > nonterminal JoinOperator join_operator;
 > nonterminal opt_inner, opt_outer;
 > -nonterminal PlanHint plan_hint;
 > +nonterminal PlanHint plan_hint, selectivity_hint;
 > nonterminal List<PlanHint> plan_hints, opt_plan_hints,
 > plan_hint_list;
 > nonterminal TypeDef type_def;
 > nonterminal Type type;
 > @@ -629,6 +629,8 @@ precedence left KW_INTO;
 >
 > precedence left KW_OVER;
 >
 > +precedence left COMMENTED_PLAN_HINT_START;
 > +
 > start with stmt;
 >
 > stmt ::=
 > @@ -3720,6 +3722,15 @@ function_params ::=
 > {: RESULT = new FunctionParams(false, true, exprs); :}
 > ;
 >
 > +selectivity_hint ::=
 > +  COMMENTED_PLAN_HINT_START KW_SELECTIVITY LPAREN
 > DECIMAL_LITERAL:value RPAREN
 > +      COMMENTED_PLAN_HINT_END
 > +  {:
 > +    RESULT = new PlanHint("selectivity",
 > +      new ArrayList(Arrays.asList(value.toString())));
 > +  :}
 > +  ;
 > +
 > predicate ::=
 > expr:e KW_IS KW_NULL
 > {: RESULT = new IsNullPredicate(e, false); :}
 > @@ -3746,6 +3757,8 @@ predicate ::=
 > :}
 > | expr:e1 KW_LOGICAL_OR expr:e2
 > {: RESULT = new CompoundVerticalBarExpr(e1, e2); :}
 > +  | predicate:p selectivity_hint:h
 > +  {: RESULT = p; :}
 > ;
 >
 > comparison_predicate ::=
 > diff --git a/fe/src/main/jflex/sql-scanner.flex 
 > b/fe/src/main/jflex/sql-scanner.flex
 > index e60676a9c..bc3a91513 100644
 > --- a/fe/src/main/jflex/sql-scanner.flex
 > +++ b/fe/src/main/jflex/sql-scanner.flex
 > @@ -236,6 +236,7 @@ import org.apache.impala.thrift.TReservedWordsVersion;
 > keywordMap.put("schemas", SqlParserSymbols.KW_SCHEMAS);
 > keywordMap.put("select", SqlParserSymbols.KW_SELECT);
 > keywordMap.put("semi", SqlParserSymbols.KW_SEMI);
 > +    keywordMap.put("selectivity", SqlParserSymbols.KW_SELECTIVITY);
 > keywordMap.put("sequencefile", SqlParserSymbols.KW_SEQUENCEFILE);
 > keywordMap.put("serdeproperties", SqlParserSymbols.KW_SERDEPROPERTIES);
 > keywordMap.put("serialize_fn", SqlParserSymbols.KW_SERIALIZE_FN);

Besides, different predicates have different code logic. For example, we can 
use 'p.setSelectivityHint(Double.valueOf(hint.getArgs().get(0)))' for a normal 
binary predicate, but for 'NOT LIKE' predicate, Impala will transform to 
'CompoundPredicate' with 'NOT' operator, so we set '1 - hint_value' for it's 
child, and this is what I did above. Maybe we need consider more of supporting 
selectivity hint for compund predicates.


--
To view, visit http://gerrit.cloudera.org:8080/18023
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I2776b9bbd878b8a21d9c866b400140a454f59e1b
Gerrit-Change-Number: 18023
Gerrit-PatchSet: 8
Gerrit-Owner: wangsheng <[email protected]>
Gerrit-Reviewer: Amogh Margoor <[email protected]>
Gerrit-Reviewer: Fucun Chu <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Qifan Chen <[email protected]>
Gerrit-Reviewer: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Zoltan Borok-Nagy <[email protected]>
Gerrit-Reviewer: wangsheng <[email protected]>
Gerrit-Comment-Date: Sat, 19 Mar 2022 10:37:38 +0000
Gerrit-HasComments: No

Reply via email to