Re: SQL:2011 application time
Paul A Jungwirth <pj@illuminatedcomputing.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Rename gist stratnum support function
- 32edf732e8dc 18.0 landed
-
Remove support for temporal RESTRICT foreign keys
- b83e8a2ca2eb 18.0 landed
-
Cache NO ACTION foreign keys separately from RESTRICT foreign keys
- 9926f854d077 18.0 landed
-
Fix NO ACTION temporal foreign keys when the referenced endpoints change
- 1772d554b089 18.0 landed
-
Improve whitespace in without_overlaps test
- 888d4523f0c2 18.0 landed
-
Tests for logical replication with temporal keys
- 939b0908c87a 18.0 landed
-
Support for GiST in get_equal_strategy_number()
- 74edabce7a33 18.0 landed
-
Make the conditions in IsIndexUsableForReplicaIdentityFull() more explicit
- 13544e790ef8 18.0 landed
-
Replace get_equal_strategy_number_for_am() by get_equal_strategy_number()
- a2a475b011cf 18.0 landed
-
Improve internal logical replication error for missing equality strategy
- 321c287351f7 18.0 landed
-
Simplify IsIndexUsableForReplicaIdentityFull()
- 7727049e8f66 18.0 landed
-
Fix ALTER TABLE / REPLICA IDENTITY for temporal tables
- 79b575d3bc09 18.0 landed
-
doc: Update pg_constraint.conexclop docs for WITHOUT OVERLAPS
- f683ba0867da 18.0 landed
-
doc: Add PERIOD to ALTER TABLE reference docs
- d56af4c882e2 18.0 landed
-
doc: Add WITHOUT OVERLAPS to ALTER TABLE reference docs
- bf621059500b 18.0 landed
-
Add temporal FOREIGN KEY contraints
- 89f908a6d0ac 18.0 landed
- 34768ee36165 17.0 landed
-
Add temporal PRIMARY KEY and UNIQUE constraints
- fc0438b4e805 18.0 landed
- 46a0cd4cefb4 17.0 landed
-
Add stratnum GiST support function
- 7406ab623fee 18.0 landed
- 6db4598fcb82 17.0 landed
-
Avoid crashing when a JIT-inlined backend function throws an error.
- 5d6c64d29097 17.0 cited
-
Revert temporal primary keys and foreign keys
- 8aee330af55d 17.0 landed
-
Fix ON CONFLICT DO NOTHING/UPDATE for temporal indexes
- 144c2ce0cc75 17.0 landed
-
Add test for REPLICA IDENTITY with a temporal key
- 482e108cd38d 17.0 landed
-
Use half-open interval notation in without_overlaps tests
- 5577a71fb0cc 17.0 landed
-
Use daterange and YMD in without_overlaps tests instead of tsrange.
- a88c800deb6f 17.0 landed
-
Rename pg_constraint.conwithoutoverlaps to conperiod
- 030e10ff1a36 17.0 landed
-
Fix comment on gist_stratnum_btree
- 86232a49a437 17.0 landed
-
Add missing TAP test name
- 1ab763fc22ad 16.0 cited
-
Improve error handling of HMAC computations
- 5513dc6a304d 15.0 cited
-
Rename functions to avoid future conflicts
- ee419607381d 15.0 landed
Attachments
- v45.3-0001-Improve-internal-logical-replication-e.patch.nocfbot (text/plain)
- v45.3-0002-Replace-get_equal_strategy_number_for_.patch.nocfbot (text/plain)
- v45.3-0003-Make-the-conditions-in-IsIndexUsableFo.patch.nocfbot (text/plain)
- v45.3-0004-Support-for-GiST-in-get_equal_strategy.patch.nocfbot (text/plain)
- v45.3-0005-Tests-for-logical-replication-with-tem.patch.nocfbot (text/plain)
On 12/4/24 03:15, Peter Eisentraut wrote:
>> I have attached three patches that show how that could be done. (This would work in conjunction
>> with your new tests. (Although now we could also test GiST with replica identity full?))
>>
>> The comment block for IsIndexUsableForReplicaIdentityFull() makes a bunch of claims that are not
>> all explicitly supported by the code. The code doesn't actually check the AM, this is all only
>> done indirectly via other checks. The second point (about tuples_equal()) appears to be slightly
>> wrong, because while you need an equals operator from the type cache, that shouldn't prevent you
>> from also using a different index AM than btree or hash for the replica identity index. And the
>> stuff about amgettuple, if that is important, why is it only checked for assert builds?
>
> I did some more work on this approach, with the attached patches resulting. This is essentially
> what I'm describing above, which in turn is a variation of your patch v45-0001-Fix-logical-
> replication-for-temporal-tables.patch, with your tests added at the end.
>
> I also did some more work on IsIndexUsableForReplicaIdentityFull() to make the various claims in the
> comments reflected by actual code. With all of this, it can now also use gist indexes on the
> subscriber side in cases of REPLICA IDENTITY FULL. This isn't immediately visible in the tests, but
> you can see that the tests are using it internally by adding debugging elogs or something like that.
>
> Altogether, I think this fixes the original problem of temporal keys not being handled properly in
> logical replication subscribers, and it makes things less hardcoded around btree and hash in general.
>
> Please review.
These five patches all look good to me.
Note that my tests already include a section for REPLICA IDENTITY FULL, which passed. But the
subscriber was using a SeqScan to look up tuples to update.
Here are the steps (mostly just because it was confusing for me at first): First in
FindUsableIndexForReplicaIdentityFull, we would call IsIndexUsableForReplicaIdentityFull, get back
false, and decide there was no index to use. Then in FindReplTupleInLocalRel, localidxoid was 0, so
we woudln't call IsIndexUsableForReplicaIdentityFull at all.
After applying the five patches, I can see that we choose the index and call
IsIndexUsableForReplicaIdentityFull from both sites. This should make applying changes a lot faster.
Here are those patches again, but incoporating Vignesh's feedback:
On 12/5/24 01:39, vignesh C wrote:
> 1) wait_for_catchup and data validation can be done after insertion
> itself, update and delete error validation can happen later:
> +($result, $stdout, $stderr) = $node_publisher->psql('postgres',
> + "DELETE FROM temporal_no_key WHERE id = '[3,4)'");
> +is( $stderr,
> + qq(psql:<stdin>:1: ERROR: cannot delete from table
> "temporal_no_key" because it does not have a replica identity and
> publishes deletes
> +HINT: To enable deleting from the table, set REPLICA IDENTITY using
> ALTER TABLE.),
> + "can't DELETE temporal_no_key DEFAULT");
> +
> +$node_publisher->wait_for_catchup('sub1');
> +
> +$result = $node_subscriber->safe_psql('postgres',
> + "SELECT * FROM temporal_no_key ORDER BY id, valid_at");
> +is( $result, qq{[1,2)|[2000-01-01,2010-01-01)|a
> +[2,3)|[2000-01-01,2010-01-01)|a
> +[3,4)|[2000-01-01,2010-01-01)|a
> +[4,5)|[2000-01-01,2010-01-01)|a}, 'replicated temporal_no_key DEFAULT');
I'd like to keep the order of tests the same for all scenarios, and sometimes update+delete succeed
and sometimes they fail. The data validation includes changes caused by the update+delete. Even when
they fail, putting the data validation at the end shows that they had no effect.
> 2) Copyright need not mention "2021-"
> diff --git a/src/test/subscription/t/034_temporal.pl
> b/src/test/subscription/t/034_temporal.pl
> new file mode 100644
> index 00000000000..0f501f1cee8
> --- /dev/null
> +++ b/src/test/subscription/t/034_temporal.pl
> @@ -0,0 +1,673 @@
> +
> +# Copyright (c) 2021-2024, PostgreSQL Global Development Group
> +
> +# Logical replication tests for temporal tables
> +#
Okay.
> 3) This statement seems very long in a single line, could we split it
> into multiple lines:
> @@ -844,6 +842,15 @@ IsIndexUsableForReplicaIdentityFull(Relation
> idxrel, AttrMap *attrmap)
>
> Assert(idxrel->rd_index->indnatts >= 1);
>
> + indclass = (oidvector *)
> DatumGetPointer(SysCacheGetAttrNotNull(INDEXRELID,
> idxrel->rd_indextuple, Anum_pg_index_indclass));
> +
> + /* Ensure that the index has a valid equal strategy for each
> key column */
> + for (int i = 0; i < idxrel->rd_index->indnkeyatts; i++)
> + {
> + if (get_equal_strategy_number(indclass->values[i]) ==
> InvalidStrategy)
> + return false;
> + }
Reformatted.
> 4) The commit message had a small typo, should "fulfull" be "fulfill":
> IsIndexUsableForReplicaIdentityFull() described a number of conditions
> that a suitable index has to fulfull. But not all of these were
Fixed.
> 5) temporal_no_key table is not dropped:
> +$result = $node_subscriber->safe_psql('postgres',
> + "SELECT * FROM temporal_unique ORDER BY id, valid_at");
> +is( $result, qq{[1,2)|[2000-01-01,2010-01-01)|a
> +[2,3)|[2000-01-01,2010-01-01)|a
> +[3,4)|[2000-01-01,2010-01-01)|a
> +[4,5)|[2000-01-01,2010-01-01)|a}, 'replicated temporal_unique NOTHING');
> +
> +# cleanup
> +
> +$node_publisher->safe_psql('postgres', "DROP TABLE temporal_pk");
> +$node_publisher->safe_psql('postgres', "DROP TABLE temporal_unique");
> +$node_publisher->safe_psql('postgres', "DROP PUBLICATION pub1");
> +$node_subscriber->safe_psql('postgres', "DROP TABLE temporal_pk");
> +$node_subscriber->safe_psql('postgres', "DROP TABLE temporal_unique");
> +$node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION sub1");
> +
> +
> +done_testing();
> --
> 2.47.1
Fixed as part of #7 below.
> 6) Since this is common to first and last test we can have it in a
> subroutine and use it for both:
> +# create tables on publisher
> +
> +$node_publisher->safe_psql('postgres',
> + "CREATE TABLE temporal_no_key (id int4range, valid_at
> daterange, a text)"
> +);
> +
> +$node_publisher->safe_psql('postgres',
> + "CREATE TABLE temporal_pk (id int4range, valid_at daterange, a
> text, PRIMARY KEY (id, valid_at WITHOUT OVERLAPS))"
> +);
> +
> +$node_publisher->safe_psql('postgres',
> + "CREATE TABLE temporal_unique (id int4range NOT NULL, valid_at
> daterange NOT NULL, a text, UNIQUE (id, valid_at WITHOUT OVERLAPS))"
> +);
> +
> +# create tables on subscriber
> +
> +$node_subscriber->safe_psql('postgres',
> + "CREATE TABLE temporal_no_key (id int4range, valid_at
> daterange, a text)"
> +);
> +
> +$node_subscriber->safe_psql('postgres',
> + "CREATE TABLE temporal_pk (id int4range, valid_at daterange, a
> text, PRIMARY KEY (id, valid_at WITHOUT OVERLAPS))"
> +);
> +
> +$node_subscriber->safe_psql('postgres',
> + "CREATE TABLE temporal_unique (id int4range NOT NULL, valid_at
> daterange NOT NULL, a text, UNIQUE (id, valid_at WITHOUT OVERLAPS))"
> +);
> +
Done.
> 7) Similarly the drop tables can be moved to a subroutine and used as
> it is being used in multiple tests:
> +# cleanup
> +
> +$node_publisher->safe_psql('postgres', "DROP TABLE temporal_no_key");
> +$node_publisher->safe_psql('postgres', "DROP TABLE temporal_pk");
> +$node_publisher->safe_psql('postgres', "DROP TABLE temporal_unique");
> +$node_publisher->safe_psql('postgres', "DROP PUBLICATION pub1");
> +$node_subscriber->safe_psql('postgres', "DROP TABLE temporal_no_key");
> +$node_subscriber->safe_psql('postgres', "DROP TABLE temporal_pk");
> +$node_subscriber->safe_psql('postgres', "DROP TABLE temporal_unique");
> +$node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION sub1");
Done.
Thanks!
Rebased to 3220ceaf77.
Yours,
--
Paul ~{:-)
pj@illuminatedcomputing.com