• Sergei Golubchik's avatar
    MDEV-11640 gcol.gcol_select_myisam fails in buildbot on Power · 8d99166c
    Sergei Golubchik authored
    JOIN_CACHE's were initialized in  check_join_cache_usage()
    from make_join_readinfo(). After that make_join_readinfo() was looking
    whether it's possible to use keyread. Later, after make_join_readinfo(),
    optimizer decided whether to use filesort. And even later, at the
    execution time, from join_read_first(), keyread was actually enabled.
    
    The problem is, that if a query uses a vcol, base columns that it
    depends on are automatically added to the read_set - because they're
    needed to calculate the vcol. But if we're doing keyread, vcol is taken
    from the index, not calculated, and base columns do not need to  be
    in the read set (even should not be - as they aren't getting values).
    
    The bug was that JOIN_CACHE used read_set with base columns,
    they were not read because of keyread, so it was caching garbage.
    
    So read_set is only known after the keyread was decided. And after the
    filesort was decided, as filesort doesn't use keyread. But
    check_join_cache_usage() needs to be done in make_join_readinfo(),
    as the code below depends on these checks,
    
    Fix: keep JOIN_CACHE checks where they were, but move initialization
    down to the very end of JOIN::optimize_inner. If keyread was enabled,
    update the read_set to include only columns that are part of the index.
    Copy the keyread logic from join_read_first() to happen at optimize time.
    8d99166c
join_cache.result 211 KB