1

I am trying out partitioning for a table(PRT_T1) with size > 1 TB. I have chosen 2 partition keys - entity_id_1 and entity_id_2 with hash partitioning. I want to understand postgres behavior when both partition keys are not part of where clause, or let's say only one of the partition key is part of where clause.

I checked explain plan for -

select * 
from PRT_T1 as T1 
where T1.entity_id_1=173.

Note that there is index on entity_id_1 and entity_id_2 columnsenter image description here The execution plan shows all partitions were scanned using Bitmap Heap Scan first and then BitMap Index scan. I've attached the screenshot of same.

Question is are these partitions scanned sequentially or parallely?

1
  • 1
    Please proof read your question. You have listed entity_id_1 as being part of the partition key (twice!) and also as being not part of the partition key. It is hard to figure out what you are really asking here. Commented Jul 2, 2020 at 22:54

1 Answer 1

2

Hash partitioning is pretty useless unless you want to distribute I/O load randomly across multiple tablespaces or you want to improve autovacuum's performance on that table.

Any query that does not have the complete partitioning key with an equality operator in the WHERE condition will have to scan all partitions. No query can become more efficient with hash partitioning than without partitioning.

All these partitions are scanned sequentially. If a PostgreSQL execution plan uses parallel query, you can always tell by the presence of a “Gather” node.

Sign up to request clarification or add additional context in comments.

2 Comments

Distributing I/O is one of objective. For legacy reasons table doesn't have timestamps that I could use for range partitioning. List partitioning is NA in my case as well, so this is the only option left to explore, depending upon performance benefit of partitioning compared to non-partitioned will take a call. Thanks about "Gather" node info was not aware. Is there any way I can influence to make these partition scans go parallel?
I don't think you can. There is force_parallel_mode - you can play with it and see what you get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.