• Tom Lane's avatar
    Micro-optimize some slower queries in the opr_sanity regression test. · c2384421
    Tom Lane authored
    Convert the binary_coercible() and physically_coercible() functions from
    SQL to plpgsql.  It's not that plpgsql is inherently better at doing
    queries; if you simply convert the previous single SQL query into one
    RETURN expression, it's no faster.  The problem with the existing code
    is that it fools the plancache into deciding that it's worth re-planning
    the query every time, since constant-folding with a concrete value for $2
    allows elimination of at least one sub-SELECT.  In reality that's using the
    planner to do the equivalent of a few runtime boolean tests, causing the
    function to run much slower than it should.  Splitting the AND/OR logic
    into separate plpgsql statements allows each if-expression to acquire a
    static plan.
    
    Also, get rid of some uses of obj_description() in favor of explicitly
    joining to pg_description, allowing the joins to be optimized better.
    (Someday we might improve the SQL-function-inlining logic enough that
    this happens automatically, but today is not that day.)
    
    Together, these changes reduce the runtime of the opr_sanity regression
    test by about a factor of two on one of my slower machines.  They don't
    seem to help as much on a fast machine, but this should at least benefit
    the buildfarm.
    c2384421
opr_sanity.out 70.4 KB