RE: [PATCH] Use indexes on the subscriber when REPLICA IDENTITY is full on the publisher
От | houzj.fnst@fujitsu.com |
---|---|
Тема | RE: [PATCH] Use indexes on the subscriber when REPLICA IDENTITY is full on the publisher |
Дата | |
Msg-id | OS0PR01MB57161DB32B787CD2ACA7AFE394B99@OS0PR01MB5716.jpnprd01.prod.outlook.com обсуждение исходный текст |
Ответ на | Re: [PATCH] Use indexes on the subscriber when REPLICA IDENTITY is full on the publisher (Önder Kalacı <onderkalaci@gmail.com>) |
Ответы |
Re: [PATCH] Use indexes on the subscriber when REPLICA IDENTITY is full on the publisher
|
Список | pgsql-hackers |
On Monday, March 13, 2023 2:23 PM Önder Kalacı <onderkalaci@gmail.com> wrote: Hi, > > > > > > > > > Reading [1], I think I can follow what you suggest. So, basically, > > > if the leftmost column is not filtered, we have the following: > > > > > >> but the entire index would have to be scanned, so in most cases the planner > > would prefer a sequential table scan over using the index. > > > > > > > > > So, in our case, we could follow a similar approach. If the leftmost column of > > the index > > > is not sent over the wire from the pub, we can prefer the sequential scan. > > > > > > Is my understanding of your suggestion accurate? > > > > > > > Yes. I request an opinion from Shi-San who has reported the problem. > > > > I also agree with this. > And I think we can mention this in the comments if we do so. > > Already commented on FindUsableIndexForReplicaIdentityFull() on v44. Thanks for updating the patch. I noticed one problem: +static bool +RemoteRelContainsLeftMostColumnOnIdx(IndexInfo *indexInfo, + LogicalRepRelation *remoterel) +{ + AttrNumber keycol; + + if (indexInfo->ii_NumIndexAttrs < 1) + return false; + + keycol = indexInfo->ii_IndexAttrNumbers[0]; + if (!AttributeNumberIsValid(keycol)) + return false; + + return bms_is_member(keycol-1, remoterel->attkeys); +} In this function, it used the local column number(keycol) to match the remote column number(attkeys), I think it will cause problem if the column order between pub/sub doesn't match. Like: ------- - pub CREATE TABLE test_replica_id_full (x int, y int); ALTER TABLE test_replica_id_full REPLICA IDENTITY FULL; CREATE PUBLICATION tap_pub_rep_full FOR TABLE test_replica_id_full; - sub CREATE TABLE test_replica_id_full (z int, y int, x int); CREATE unique INDEX idx ON test_replica_id_full(z); CREATE SUBSCRIPTION tap_sub_rep_full_0 CONNECTION 'dbname=postgres port=5432' PUBLICATION tap_pub_rep_full; ------- I think we need to use the attrmap->attnums to convert the column number before comparing. Just for reference, attach a diff(0001) which I noted down when trying to fix the problem. Besides, I also look at the "WIP: Optimize for non-pkey / non-RI unique indexes" patch, I think it also had a similar problem about the column matching. And another thing I think we can improved in this WIP patch is that we can cache the result of IsIdxSafeToSkipDuplicates() instead of doing it for each UPDATE, because the cost of this function becomes bigger after applying this patch. And for reference, I tried to improve the WIP for the same, and here is a slight modified version of this WIP(0002). Feel free to modify or merge it if needed. Thanks for Shi-san for helping to finish these fixes. Best Regards, Hou zj
Вложения
В списке pgsql-hackers по дате отправления: