Repository navigation
Open
Labels
Description
Environment
- Doltgres 1.4.0, Windows amd64 portable build, fresh data directory, default
postgresuser. - Client: Npgsql 10.0.3 (.NET 10), autocommit.
- Expected results: the same SQL run against PostgreSQL 18.6 and 16.2.
- After the
XX000error, the Npgsql connection was closed; the server stayed up.
Steps
Run once with <s> = public and once with <s> = s (after create schema s). The database is named r_d5.
create table <s>.p (a varchar(10), b varchar(10), primary key (a, b));
create table <s>.c (id varchar(10) primary key, a varchar(10), b varchar(10),
constraint fk_c foreign key (a, b) references <s>.p (a, b));
-- Q1
select constraint_name, table_name, column_name from information_schema.constraint_column_usage
where table_schema = '<s>' order by 1, 2, 3;
-- Q2
select constraint_name, unique_constraint_schema, unique_constraint_name, unique_constraint_name is null
from information_schema.referential_constraints where constraint_schema = '<s>';
-- Q3 (common FK listing)
select tc.table_name, kcu.column_name, ccu.table_name as ref_table, ccu.column_name as ref_column
from information_schema.table_constraints tc
join information_schema.key_column_usage kcu on tc.constraint_name = kcu.constraint_name and tc.table_schema = kcu.table_schema
join information_schema.constraint_column_usage ccu on ccu.constraint_name = tc.constraint_name and ccu.table_schema = tc.table_schema
where tc.constraint_type = 'FOREIGN KEY' and tc.table_schema = '<s>' order by 2, 4;
-- Q4 (referenced columns by position)
select kcu.table_name, kcu.column_name, pk.table_name as ref_table, pk.column_name as ref_column
from information_schema.referential_constraints rc
join information_schema.key_column_usage kcu on kcu.constraint_schema = rc.constraint_schema and kcu.constraint_name = rc.constraint_name
join information_schema.key_column_usage pk on pk.constraint_schema = rc.unique_constraint_schema and pk.constraint_name = rc.unique_constraint_name
and pk.ordinal_position = kcu.position_in_unique_constraint
where rc.constraint_schema = '<s>' order by kcu.ordinal_position;
-- Q5
select kcu.table_name, kcu.column_name from information_schema.key_column_usage kcu
where kcu.table_schema = '<s>'
and kcu.constraint_name in (select constraint_name from information_schema.table_constraints where constraint_type = 'FOREIGN KEY')
order by kcu.ordinal_position;Actual vs expected
Doltgres gave the same result for both schemas unless a schema is shown.
| Query | Doltgres 1.4.0 | PostgreSQL 18.6 / 16.2 |
|---|---|---|
| Q1 | No rows | (c_pkey,c,id) (fk_c,p,a) (fk_c,p,b) (p_pkey,p,a) (p_pkey,p,b); 18.6 also lists the NOT NULL constraints |
Q2, public |
(fk_c, r_d5, PRIMARY, false) |
(fk_c, public, p_pkey, false) |
Q2, s |
(fk_c, r_d5, NULL, true) |
(fk_c, s, p_pkey, false) |
| Q3 | No rows | (c,a,p,a) (c,a,p,b) (c,b,p,a) (c,b,p,b) |
| Q4 | No rows | (c,a,p,a) (c,b,p,b) |
| Q5 | XX000 plan is not resolved because of node '*plan.Project' |
(c,a) (c,b) |
Workaround
Read foreign keys from pg_constraint, then resolve the column numbers through pg_attribute. The query returns (fk_c, c, p, {2,3}, {1,2}) for public and (fk_c, s.c, s.p, {2,3}, {1,2}) for s.
select conname, conrelid::regclass::text, confrelid::regclass::text, conkey, confkey
from pg_constraint where contype = 'f';
Activity
Hydrocharged commentedon Nov 4, 2026
Thank you for the issue! We will look into this and try to get a fix out this week!
roxblnfk commentedon Nov 25, 2026
On 1.5.3 the FK listing join no longer returns empty results: with a filter on the table it panics. The
table_constraints⋈constraint_column_usagepart alone is enough to trigger it, on a fresh database (Windows amd64 build, PHP PDO pgsql):PostgreSQL 18 returns
a_id_not_nullanda_pkey. The same panic happens with a row-value filter (WHERE (tc.table_schema, tc.table_name) IN (('public', 'a'))); without anyWHEREthe join returns no rows.It is raised while planning the hash join:
table_constraints.constraint_namecomes from the MySQL view (see #3825), whileconstraint_column_usagealready has PostgreSQL columns, so the guess is that the hash key mixes a MySQL string type with a Doltgres one; not checked in the code. Cycle ORM (cycle/database, PHP) runs this join for every table it introspects, and 24 of its PostgreSQL tests fail on it.