-
Notifications
You must be signed in to change notification settings - Fork 67
Some of the partition Query Plan incorrectly Seq Scan on parent table #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @kenzan100, First of all, thanks for using pg_pathman. I see that your build of pg_pathman is out of date. Could you install the fresh release and retry? |
I'd like to notice that the slowdown isn't caused by SeqScan on parent. Presumably, the real reason is that optimizations are turned off for some of your queries, which is why standard partition pruning (so-called constraint elimination mechanism) takes place and adds parent table to the plan. |
thank you for your quick reachout.
We followed your advice, and now it's
but still, the query planner returns the same result. |
Ok, could you show the contents of |
We use a range of 2 so each partition covers only one value. We can consistently reproduce older partitions having fast pathman planning and the new partitions having normal PG planning. It only seems to happen with one table and two other tables partitioned the same are unaffected. |
I see. Just to make sure this isn't a cache bug: could you execute the following in the same session (e.g. in psql):
The last one would allow us to see if the cache is working correctly. I suspect that we might not see new partitions. |
I followed
and the last SELECT does show the new partition. cc: @jamatthews |
And during this test the bad one was still slow, right? |
@funbringer yes |
Ok, have you ever dropped any columns before creating new partitions? |
@funbringer yes, we have dropped a column for this table recently. |
Finally, now it makes more sense. I guess that's the reason. You see, at the moment this optimization doesn't work if the number of attributes in partition and parent doesn't match. It's checked here (see the code). Here's how it looks like: create table test (a int, b int not null);
select create_range_partitions('test', 'b', 0, 100, 3);
select count(*) from pg_attribute where attrelid = 'test'::regclass;
count
-------
8
(1 row)
select count(*) from pg_attribute where attrelid = 'test_1'::regclass;
count
-------
8
(1 row)
/* drop the column and spawn a new partition */
alter table test drop column a;
select prepend_range_partition('test');
select count(*) from pg_attribute where attrelid = 'test_4'::regclass;
count
-------
7
(1 row)
explain update test set b = 5 where b = 50;
QUERY PLAN
---------------------------------------------------------------
Update on test_1 (cost=0.00..41.88 rows=13 width=14)
-> Seq Scan on test_1 (cost=0.00..41.88 rows=13 width=14)
Filter: (b = 50)
(3 rows)
explain update test set b = 5 where b = -50;
QUERY PLAN
---------------------------------------------------------------
Update on test (cost=0.00..41.88 rows=14 width=10)
Update on test
Update on test_4
-> Seq Scan on test (cost=0.00..0.00 rows=1 width=14)
Filter: (b = '-50'::integer)
-> Seq Scan on test_4 (cost=0.00..41.88 rows=13 width=10)
Filter: (b = '-50'::integer)
(7 rows) However, this is something we definitely can fix. I'm going to push a bugfix shortly. Thank you for the report. |
ohhh, nice input! that's awesome to know. |
@funbringer when do you think this will happen? We would like to apply this fix, preferably really soon. |
I've almost finished the patch, but you have to wait a little longer (a couple of days, probably). |
OK, thank you for the update!
…On Fri 29. Jun 2018 at 20:22, Dmitry Ivanov ***@***.***> wrote:
I've almost finished the patch, but you have to wait a little longer (a
couple of days, probably).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAizl-QBfZGQMY0L-pFD94eG3QQJVXzgks5uBnBhgaJpZM4U8KOZ>
.
|
@funbringer I'm looking forward to hearing from you and the team! sorry to bother you many times... |
Hi, I've pushed a branch called Just |
@funbringer thanks for the quick updates! |
@funbringer Right now, it's going really well, that all the partitions are having optimized query plans!! |
Hi again, Could you test the |
@funbringer We are now using 79a1b89 |
1.4.13 is now available. |
cool |
Problem description
We have a table called
customers
, and it has about 4K partition.For some of the newer partitions,
EXPLAIN UPDATE customers SET ... WHERE ...
results in Seq Scan on the parent table, making it significantly slower.
For other cases, it produces the correct query plan
Expected Result
No matter which partition it is, it should produce an optimized query plan.
Environment
The text was updated successfully, but these errors were encountered: