• J
    Disable aggressive loop optimizations in GCC 4.8+ (#1200) · 2e387d0e
    Jesse Zhang 提交于
    Summary:
    * Properly propagate the C++ compiler from autoconf
    * Disable aggressive loop optimizations in GCC 4.8+
    
    This commit is in the spirit of postgres/postgres@105f3ef4 , but done
    for C++ code so that the GPORCA translator can properly build when the
    compiler is GCC 4.8+
    
    Fixes greenplum-db/gpdb#1186 .
    
    TL;DR, here is the additional context on what specific to GPORCA translator:
    
    GCC 6.2.0 compiler (which is required for codegen) got aggressive loop optimization to remove loop when enumerating variable length array.
    
    In code `CTranslatorRelcacheToDXL.cpp`, we have a loop to enumerate all
    the attributes of an index:
    
    ```
    INT iAttno = pgIndex->indkey.values[ul];
    ```
    
    Where `values[ul]` is of following data structure:
    
    ```
    typedef struct
    {
    ...
    	int2		values[1];		/* VARIABLE LENGTH ARRAY */
    } int2vector;					/* VARIABLE LENGTH STRUCT */
    ```
    
    This is standard way of dealing with variable length array in Postgres. However, optimizer
    thinking there is only 1 element, hence removed the loop.
    
    This caused wrong result when using GPDB with GPORCA. The repro is
    ```
    -- multi-column index
    create table index_test (a int, b int, c int, d int, e int,
      constraint index_test_pkey PRIMARY KEY (a, b, c, d));
    
    insert into index_test select i,i%2,i%3,i%4,i%5 from generate_series(1,100) i;
    
    -- expecting using index scan with index cond: c=5
    explain select * from index_test where c = 5;
    ```
    
    When compile with GCC 6.2.0, the `index scan` is not selected, but a `table scan` is chosen
    instead. The root cause is the compiler removed the loop, and only keep the first column.
    
    The fix is to add $CXXFLAG auto detection to add the
    `-fno-aggressive-loop-optimizations` for $CXX compilers if that version of compiler supporting
    such optimization. Hence to avoid having the above issue for gpopt component.
    2e387d0e
configure.in 74.0 KB