• Tom Lane's avatar
    Don't fetch partition check expression during InitResultRelInfo. · 2000b6c1
    Tom Lane authored
    Since there is only one place that actually needs the partition check
    expression, namely ExecPartitionCheck, it's better to fetch it from
    the relcache there.  In this way we will never fetch it at all if
    the query never has use for it, and we still fetch it just once when
    we do need it.
    
    The reason for taking an interest in this is that if the relcache
    doesn't already have the check expression cached, fetching it
    requires obtaining AccessShareLock on the partition root.  That
    means that operations that look like they should only touch the
    partition itself will also take a lock on the root.  In particular
    we observed that TRUNCATE on a partition may take a lock on the
    partition's root, contributing to a deadlock situation in parallel
    pg_restore.
    
    As written, this patch does have a small cost, which is that we
    are microscopically reducing efficiency for the case where a partition
    has an empty check expression.  ExecPartitionCheck will be called,
    and will go through the motions of setting up and checking an empty
    qual, where before it would not have been called at all.  We could
    avoid that by adding a separate boolean flag to track whether there
    is a partition expression to test.  However, this case only arises
    for a default partition with no siblings, which surely is not an
    interesting case in practice.  Hence adding complexity for it
    does not seem like a good trade-off.
    
    Amit Langote, per a suggestion by me
    
    Discussion: https://postgr.es/m/VI1PR03MB31670CA1BD9625C3A8C5DD05EB230@VI1PR03MB3167.eurprd03.prod.outlook.com
    2000b6c1
nodeModifyTable.c 88.2 KB