• H
    Transform small Array constants to ArrayExprs. · 9a817d45
    Heikki Linnakangas 提交于
    ORCA can do some optimizations - partition pruning at least - if it can
    "see" into the elements of an array in a ScalarArrayOpExpr. For example, if
    you have a qual like "column IN (1, 2, 3)", and the table is partitioned on
    column, it can eliminate partitions that don't hold those values. The
    IN-clause is converted into an ScalarArrayOpExpr, so that is really
    equivalent to "column = ANY <array>"
    
    However, ORCA doesn't know how to extract elements from an array-typed
    Const, so it can only do that if the array in the ScalarArrayOpExpr is
    an ArrayExpr. Normally, eval_const_expressions() simplifies any ArrayExprs
    into Const, if all the elements are constants, but we had disabled that
    when ORCA was used, to keep the ArrayExprs visible to it.
    
    There are a couple of reasons why that was not a very good solution. First,
    while we refrain from converting an ArrayExpr to an array Const, it doesn't
    help if the argument was an array Const to begin with. The "x IN (1,2,3)"
    construct is converted to an ArrayExpr by the parser, but we would miss the
    opportunity if it's written as "x = ANY ('{1,2,3}'::int[])" instead.
    Secondly, by not simplifying the ArrayExpr, we miss the opportunity to
    simplify the expression further. For example, if you have a qual like
    "1 IN (1,2)", we can evaluate that completely at plan time to 'true', but
    we would not do that with ORCA because the ArrayExpr was not simplified.
    
    To be able to also optimize those cases, and to slighty reduce our diff
    vs upstream in clauses.c, always simplify ArrayExprs to Consts, when
    possible. To compensate, so that ORCA still sees ArrayExprs rather than
    array Consts (in those cases where it matters), when a ScalarArrayOpExpr
    is handed over to ORCA, we check if the argument array is a Const, and
    convert it (back) to an ArrayExpr if it is.
    Signed-off-by: NJemish Patel <jpatel@pivotal.io>
    9a817d45
gpdbwrappers.cpp 38.4 KB