Skip to content

Conversation

@colm-mchugh
Copy link
Contributor

@colm-mchugh colm-mchugh commented Nov 11, 2025

PG18: syntax & semantics behavior in Citus, part 1.

Includes PG18 tests for:

  • OLD/NEW support in RETURNING clause of DML queries (PG commit 80feb727c)
  • WITHOUT OVERLAPS in PRIMARY KEY and UNIQUE constraints (PG commit fc0438b4e)
  • COLUMNS clause in JSON_TABLE (PG commit bb766cd)
  • Foreign tables created with LIKE clause (PG commit 302cf1575)
  • Foreign Key constraint with PERIOD clause (PG commit 89f908a6d)
  • COPY command REJECT_LIMIT option (PG commit 4ac2a9bec)
  • COPY TABLE TO on a materialized view (PG commit 534874fac)
  • Partially addresses issue #8250

@colm-mchugh colm-mchugh marked this pull request as draft November 11, 2025 18:59
@colm-mchugh colm-mchugh force-pushed the colm/PG18-8250-pt1 branch 3 times, most recently from f8bc384 to 8407c7a Compare November 12, 2025 16:57
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.95%. Comparing base (accd01f) to head (eba6153).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8335      +/-   ##
==========================================
+ Coverage   88.92%   88.95%   +0.02%     
==========================================
  Files         287      287              
  Lines       63151    63152       +1     
  Branches     7941     7941              
==========================================
+ Hits        56156    56175      +19     
+ Misses       4681     4668      -13     
+ Partials     2314     2309       -5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@colm-mchugh colm-mchugh self-assigned this Nov 12, 2025
@colm-mchugh colm-mchugh marked this pull request as ready for review November 12, 2025 17:34
-- (The rangetypes regression test uses the same trick.)
id int4range,
valid_at daterange,
CONSTRAINT temporal_rng_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would only work in create time. i.e. not able to add such a primary key after creating the table, so this should probably be handled separately

Copy link
Contributor Author

@colm-mchugh colm-mchugh Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually add such a primary key after creating the table does work after the table is distributed; I just added tests for the same. So adding a primary key:

ALTER TABLE temporal_rng
  ADD CONSTRAINT temporal_rng_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS);

is propagated to the table's shads:

DETAIL:  on server citus@localhost:9702 connectionId: 13
NOTICE:  issuing SELECT worker_apply_shard_ddl_command (104206, 'citus', 'ALTER TABLE temporal_rng ADD
  CONSTRAINT temporal_rng_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
;')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great then. It seems its part of the column name.

/*
 * AppendColumnNameList converts a list of columns into comma separated string format
 * (colname_1, colname_2, .., colname_n).
 */
void
AppendColumnNameList(StringInfo buf, List *columns)
{
	appendStringInfoString(buf, " (");

	ListCell *lc;
	bool firstkey = true;

	foreach(lc, columns)
	{
		if (firstkey == false)
		{
			appendStringInfoString(buf, ", ");
		}

		appendStringInfo(buf, "%s", quote_identifier(strVal(lfirst(lc))));
		firstkey = false;
	}

	appendStringInfoString(buf, " )");
}

I also tested distributing the table after adding a constraint, and also adding a new node, and it seems to propagate fine. Could you maybe include one of those tests here, just to be sure. Maybe include the one you commented here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just saw that you already added the tests!!!

INSERT INTO temporal_rng (id, valid_at) VALUES ('[3,4)', 'empty');
ERROR: empty WITHOUT OVERLAPS value found in column "valid_at" in relation "temporal_rng_4754012"
CONTEXT: while executing command on localhost:xxxxx
SELECT * FROM temporal_rng ORDER BY id, valid_at;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add order by

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an ORDER BY on both columns of the table - is that what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I added the comment at wrong line. There are some select queries with no order by.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, added.

@colm-mchugh colm-mchugh force-pushed the colm/PG18-8250-pt1 branch 2 times, most recently from 1463668 to 4a8df04 Compare November 13, 2025 12:05
Copy link
Member

@naisila naisila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot for the extensive testing. Great to see Citus's current infrastructure seamlessly propagating all these new cool PG18 features.

--
-- Add foreign key constraint with PERIOD clause
-- This is propagated to worker shards
ALTER TABLE temporal_fk_rng2rng
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested citus_add_node, propagates fine

xxx@foo.com | colm@planet.com
(1 row)

SELECT * FROM users WHERE id = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add order by

@m3hm3t m3hm3t force-pushed the m3hm3t/pg18_beta_confs branch from e302318 to 42d95c8 Compare November 17, 2025 08:09
@colm-mchugh colm-mchugh changed the base branch from m3hm3t/pg18_beta_confs to main November 17, 2025 10:39
Includes PG18 tests for:
- OLD/NEW support in RETURNING clause of DML queries (PG commit 80feb727c)
- WITHOUT OVERLAPS in PRIMARY KEY and UNIQUE constraints (PG commit fc0438b4e)
- COLUMNS clause in JSON_TABLE (PG commit bb766cd)
- Foreign tables created with LIKE <table> clause (PG commit 302cf1575)
- Foreign Key constraint with PERIOD clause (PG commit 89f908a6d)
- COPY command REJECT_LIMIT option (PG commit 4ac2a9bec)
- COPY TABLE TO on a materialized view (PG commit 534874fac)
@colm-mchugh colm-mchugh merged commit 4e47293 into main Nov 17, 2025
151 checks passed
@colm-mchugh colm-mchugh deleted the colm/PG18-8250-pt1 branch November 17, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants