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
- v22-0001-Add-stratnum-GiST-support-function.patch (text/x-patch) patch v22-0001
- v22-0002-Add-temporal-PRIMARY-KEY-and-UNIQUE-constraints.patch (text/x-patch) patch v22-0002
- v22-0003-Add-GiST-referencedagg-support-func.patch (text/x-patch) patch v22-0003
- v22-0004-Add-temporal-FOREIGN-KEYs.patch (text/x-patch) patch v22-0004
- v22-0005-Add-multi-range_without_portion-proc-operator.patch (text/x-patch) patch v22-0005
- v22-0006-Add-UPDATE-DELETE-FOR-PORTION-OF.patch (text/x-patch) patch v22-0006
- v22-0007-Add-CASCADE-SET-NULL-SET-DEFAULT-for-temporal-fo.patch (text/x-patch) patch v22-0007
- v22-0008-Add-PERIODs.patch (text/x-patch) patch v22-0008
Getting caught up on reviews from November and December:
On 11/19/23 22:57, jian he wrote:
>
> I believe the following part should fail. Similar tests on
> src/test/regress/sql/generated.sql. line begin 347.
>
> drop table if exists gtest23a,gtest23x cascade;
> CREATE TABLE gtest23a (x int4range, y int4range,
> CONSTRAINT gtest23a_pk PRIMARY KEY (x, y WITHOUT OVERLAPS));
> CREATE TABLE gtest23x (a int4range, b int4range GENERATED ALWAYS AS
> ('empty') STORED,
> FOREIGN KEY (a, PERIOD b ) REFERENCES gtest23a(x, PERIOD y) ON UPDATE
> CASCADE); -- should be error?
Okay, I've added a restriction for temporal FKs too. But note this will
change once the PERIODs patch (the last one here) is finished. When the
generated column is for a PERIOD, there will be logic to "reroute" the
updates to the constituent start/end columns instead.
> begin;
> drop table if exists fk, pk cascade;
> CREATE TABLE pk (id int4range, valid_at int4range,
> CONSTRAINT pk_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
> );
> CREATE TABLE fk (
> id int4range,valid_at tsrange, parent_id int4range,
> CONSTRAINT fk FOREIGN KEY (parent_id, valid_at)
> REFERENCES pk
> );
> rollback;
> --
> the above query will return an error: number of referencing and
> referenced columns for foreign key disagree.
> but if you look at it closely, primary key and foreign key columns both are two!
> The error should be saying valid_at should be specified with "PERIOD".
Ah okay, thanks for the clarification! This is tricky because the user
left out the PERIOD on the fk side, and left out the entire pk side, so
those columns are just implicit. So there is no PERIOD anywhere.
But I agree that if the pk has WITHOUT OVERLAPS, we should expect a
corresponding PERIOD modifier on the fk side and explain that that's
what's missing. The attached patches include that.
> I found out other issues in v18.
> I first do `git apply` then `git diff --check`, there is a white
> space error in v18-0005.
Fixed, thanks!
> You also need to change update.sgml and delete.sgml <title>Outputs</title> part.
> Since at most, it can return 'UPDATE 3' or 'DELETE 3'.
This doesn't sound correct to me. An UPDATE or DELETE can target many
rows. Also I don't think the inserted "leftovers" should be included in
these counts. They represent the rows updated/deleted.
> --the following query should work?
> drop table pk;
> CREATE table pk(a numrange PRIMARY key,b text);
> insert into pk values('[1,10]');
> create or replace function demo1() returns void as $$
> declare lb numeric default 1; up numeric default 3;
> begin
> update pk for portion of a from lb to up set b = 'lb_to_up';
> return;
> end
> $$ language plpgsql;
> select * from demo1();
Hmm this is a tough one. It is correct that the `FROM __ TO __` values cannot be column references.
They are computed up front, not per row. One reason is they are used to search the table. In fact
the standard basically allows nothing but literal strings here. See section 14.14, page 971 then
look up <point in time> on page 348 and <datetime value expression> on page 308. The most
flexibility you get is you can add/subtract an interval to the datetime literal. We are already well
past that by allowing expressions, (certain) functions, parameters, etc.
OTOH in your plpgsql example they are not really columns. They just get represented as ColumnRefs
and then passed to transformColumnRef. I'm surprised plpgsql does it that way. As a workaround you
could use `EXECUTE format(...)`, but I'd love to make that work as you show instead. I'll keep
working on this one but it's not done yet. Perhaps I can move the restriction into
analysis/planning. If anyone has any advice it'd be welcome.
On 12/6/23 05:22, jian he wrote:
> this TODO:
> * TODO: It sounds like FOR PORTION OF might need to do something here too?
> based on comments on ExprContext. I refactor a bit, and solved this TODO.
The patch looks wrong to me. We need to range targeted by `FROM __
TO __` to live for the whole statement, not just one tuple (see just
above). That's why it gets computed in the Init function node.
I don't think that TODO is needed anymore at all. Older versions of the
patch had more expressions besides this one, and I think it was those I
was concerned about. So I've removed the comment here.
> tring to the following TODO:
> // TODO: Need to save context->mtstate->mt_transition_capture? (See
> comment on ExecInsert)
>
> but failed.
> I also attached the trial, and also added the related test.
>
> You can also use the test to check portion update with insert trigger
> with "referencing old table as old_table new table as new_table"
> situation.
Thank you for the test case! This is very helpful. So the problem is
`referencing new table as new_table` gets lost. I don't have a fix yet
but I'll work on it.
On 12/11/23 00:31, jian he wrote:
> - false); /* quiet */
> + false); /* quiet */
>
> Is the above part unnecessary?
Good catch! Fixed.
> I am confused. so now I only apply v19, 0001 to 0003.
> period_to_range function never used. maybe we can move this part to
> 0005-Add PERIODs.patch?
> Also you add change in Makefile in 0003, meson.build change in 0005,
> better put it on in 0005?
You're right, those changes should have been in the PERIODs patch. Moved.
> +/*
> + * We need to handle this shift/reduce conflict:
> + * FOR PORTION OF valid_at FROM INTERVAL YEAR TO MONTH TO foo.
> + * This is basically the classic "dangling else" problem, and we want a
> + * similar resolution: treat the TO as part of the INTERVAL, not as part of
> + * the FROM ... TO .... Users can add parentheses if that's a problem.
> + * TO just needs to be higher precedence than YEAR_P etc.
> + * TODO: I need to figure out a %prec solution before this gets committed!
> + */
> +%nonassoc YEAR_P MONTH_P DAY_P HOUR_P MINUTE_P
> +%nonassoc TO
>
> this part will never happen?
> since "FROM INTERVAL YEAR TO MONTH TO"
> means "valid_at" will be interval range data type, which does not exist now.
It appears still needed to me. Without those lines I get 4 shift/reduce
conflicts. Are you seeing something different? Or if you have a better
solution I'd love to add it. I definitely need to fix this before that
patch gets applied.
> for all the refactor related to ri_PerformCheck, do you need (Datum) 0
> instead of plain 0?
Casts added.
> + <para>
> + If the table has a range column or
> + <link linkend="ddl-periods-application-periods"><literal>PERIOD</literal></link>,
> + you may supply a <literal>FOR PORTION OF</literal> clause, and
> your delete will
> + only affect rows that overlap the given interval. Furthermore, if
> a row's span
>
>
https://influentialpoints.com/Training/basic_statistics_ranges.htm#:~:text=A%20range%20is%20two%20numbers,or%20the%20difference%20between%20them
> So "range" is more accurate than "interval"?
I don't think we should be using R to define the terms "range" and
"interval", which both already have meanings in Postgres, SQL, and the
literature for temporal databases. But I'm planning to revise the docs'
terminology here anyway. Some temporal database texts use "interval"
in this sense, and I thought it was a decent term to mean "range or
PERIOD". But now we need something to mean "range or multirange or
custom type or PERIOD". Actually "portion" seems like maybe the best
term, since the SQL syntax `FOR PORTION OF` reinforces that term. If you
have suggestions I'm happy for ideas.
> +/* ----------
> + * ForPortionOfState()
> + *
> + * Copies a ForPortionOfState into the current memory context.
> + */
> +static ForPortionOfState *
> +CopyForPortionOfState(ForPortionOfState *src)
> +{
> + ForPortionOfState *dst = NULL;
> + if (src) {
> + MemoryContext oldctx;
> + RangeType *r;
> + TypeCacheEntry *typcache;
> +
> + /*
> + * Need to lift the FOR PORTION OF details into a higher memory context
> + * because cascading foreign key update/deletes can cause triggers to fire
> + * triggers, and the AfterTriggerEvents will outlive the FPO
> + * details of the original query.
> + */
> + oldctx = MemoryContextSwitchTo(TopTransactionContext);
>
> should it be "Copy a ForPortionOfState into the TopTransactionContext"?
You're right, the other function comments here use imperative mood. Changed.
New patches attached, rebased to 43b46aae12. I'll work on your feedback from Jan 4 next. Thanks!
--
Paul ~{:-)
pj@illuminatedcomputing.com