0

I have a PostgreSQL 10 database that contains two tables which both have two levels of partitioning (by list).

The data is now stored within 5K to 10K partitioned tables (grand-children of the two tables mentioned above) depending on the day.

There are three indexes per grand-child partition table but the two columns on which partitioning is done aren't indexed. (Since I don't think this is needed no?)

The issue I'm observing is that the query planning time is very slow but the query execution time very fast.

Even when the partition values were hard-coded in the query.

Researching the issue, I thought that the linear search use by PostgreSQL 10 to find the metadata of the partition was the cause of it.

cf: https://blog.2ndquadrant.com/partition-elimination-postgresql-11/

So I decided to try out PostgreSQL 11 which includes the two aforementioned patches:

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=499be013de65242235ebdde06adb08db887f0ea5 https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=9fdb675fc5d2de825414e05939727de8b120ae81

Helas, it seems that the version change doesn't change anything.

Now I know that having lots of partitions isn't greatly appreciated by PostgreSQL but I still would like to understand why the query planner is so slow in PostgreSQL 10 and now PostgreSQL 11.

An example of a query would be:

EXPLAIN ANALYZE
SELECT
    table_a.a,
    table_b.a
FROM
    (
        SELECT
            a,
            b
        FROM
            table_a
        WHERE
            partition_level_1_column = 'foo'
            AND
            partition_level_2_column = 'bar'
    )
        AS table_a
INNER JOIN
    (
        SELECT
            a,
            b
        FROM
            table_b
        WHERE
            partition_level_1_column = 'baz'
            AND
            partition_level_2_column = 'bat'
    )
        AS table_b
        ON table_b.b = table_a.b
LIMIT
    10;

Running it will on database with 5K partitions will return Planning Time: 7155.647 ms but Execution Time: 2.827 ms.

  • This should better be asked on the Postgres performance mailing list – a_horse_with_no_name Jan 22 at 12:56
  • @a_horse_with_no_name You've answered pretty complex PostgreSQL question of mine in the past so I'm going to take your advice and try my luck there. I always saw the mailing list as a bit of a daunting task haha. – Mickael Jan 22 at 13:07
  • What "daunting"? Register, send email, read the answers - in my experience you get extremely good and in-depth answers there. Especially with questions like this – a_horse_with_no_name Jan 22 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.