• K
    Fix Relcache Translator to send CoercePath info (#2842) · cc799db4
    khannaekta 提交于
    Fix Relcache Translator to send CoercePath info
    
    Currently ORCA crashes while executing following query:
    ```
    CREATE TABLE FOO(a integer NOT NULL, b double precision[]);
    SELECT b FROM foo
    UNION ALL
    SELECT ARRAY[90, 90] as Cont_features;
    ```
    
    In the query, we are appending an integer array (ARRAY[90, 90]) to a double
    precision array (foo.b) and hence we need to apply a cast on ARRAY[90, 90] to
    generate ARRAY[90, 90]::double precision[].
    In gpdb5 there is not direct function available that can cast array of any type
    to array of any other type.
    So in relcache to dxl translator we look into the array elements and get their type
    and try to find a cast function for them.  For this query, source type is 23 i.e.
    integer and destination type is 701 i.e. double precision and we try to find if
    we have a conversion function for 23 -> 701. Since that is available we send
    that function to ORCA as follows:
    ```
    <dxl:MDCast Mdid="3.1007.1.0;1022.1.0"
    Name="float8" BinaryCoercible="false" SourceTypeId="0.1007.1.0"
    DestinationTypeId="0.1022.1.0" CastFuncId="0.316.1.0"/>
    ```
    Here we are misinforming ORCA by specifying that function with id 316 is available
    to convert type 1007 i.e. integer array to 1022 i.e. double precision array.
    However Function id 316 is simple int4 to float8 conversion function and it CAN NOT
    convert an array of int4 to array of double precision. ORCA generates a plan
    using this function but executor crashes while executing this function because
    this function can not handle arrays.
    
    This commit fixes this issue by passing a ArrayCoercePath info to ORCA.
    In Relcache Translator, The appropriate cast function is retrieved in `gpdb::FCastFunc()`
    which relies on `find_coercion_pathway()` to provide the cast function oid given the src
    and dest types.
    
    `find_coercion_pathway()` does not just determines the cast function to be used but
    also determines the coercion path; however we ignored the coercision path
    and generate a simple Cast Metadata Object.
    
    With this commit, we now pass the pathtype to relcache translator and
    generate ArrayCoerceCast Metadata object depending on the coercion path.
    
    In ORCA, when the dxl is translated to expression, we check the path type along with
    the cast function and generate `CScalarArrayCoerceExpr` if the path type is
    array coerce path; otherwise we generate simple `CScalaraCast`.
    
    Please check the corresponding ORCA PR.
    
    Bump ORCA version to 2.40
    Signed-off-by: NBhuvnesh Chaudhary <bchaudhary@pivotal.io>
    cc799db4
lsyscache.c 92.5 KB