Skip to content

Bug fixes for primary and foreign key naming#1270

Merged
fulghum merged 1 commit intomainfrom
fulghum/key_naming
Mar 12, 2025
Merged

Bug fixes for primary and foreign key naming#1270
fulghum merged 1 commit intomainfrom
fulghum/key_naming

Conversation

@fulghum
Copy link
Copy Markdown
Contributor

@fulghum fulghum commented Mar 10, 2025

Addresses several issues around primary key and foreign key naming:

  • ability to drop a primary key using its default postgres name
  • declaring a foreign key reference inline in a column definition
  • default foreign key names now match postgres
  • fix for pg_constaints incorrectly listing non-unique and non-pk indexes

Note that the regressions listed are all related to now honoring foreign key references inline in a column definition. Before, these statements were executing, but the FK reference was ignored. Now that we honor the FK reference, several tests broke for the following reasons:

@fulghum fulghum force-pushed the fulghum/key_naming branch 2 times, most recently from 48e685d to 5057c78 Compare March 10, 2025 23:09
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2025

Main PR
covering_index_scan_postgres 362.11/s 357.48/s -1.3%
index_join_postgres 144.25/s 137.77/s -4.5%
index_join_scan_postgres 173.13/s 169.90/s -1.9%
index_scan_postgres 11.68/s 10.91/s -6.6%
oltp_point_select 2572.56/s 2466.33/s -4.2%
oltp_read_only 1722.31/s 1677.01/s -2.7%
select_random_points 101.79/s 100.71/s -1.1%
select_random_ranges 128.90/s 127.46/s -1.2%
table_scan_postgres 9.50/s 9.49/s -0.2%
types_table_scan_postgres 5.03/s 4.94/s -1.8%

@github-actions
Copy link
Copy Markdown
Contributor

Main PR
Total 42090 42090
Successful 15693 15676
Failures 26397 26414
Partial Successes1 5201 5207
Main PR
Successful 37.2844% 37.2440%
Failures 62.7156% 62.7560%

${\color{red}Regressions (26)}$

alter_table

QUERY:          alter table atref alter column c1 set data type bigint;
RECEIVED ERROR: table not found: atref (errno 1146) (sqlstate HY000)
QUERY:          alter table atref alter column c1 set data type bigint;
RECEIVED ERROR: table not found: atref (errno 1146) (sqlstate HY000)

foreign_key

QUERY:          create table fktable (ftest1 int references pktable(base1));
RECEIVED ERROR: missing index for foreign key `fktable_ftest1_fkey` on the referenced table `pktable` (errno 1105) (sqlstate HY000)
QUERY:          CREATE TEMP TABLE fktable (
        x1      INT4 REFERENCES pktable(id1),
        x2      VARCHAR(4) REFERENCES pktable(id2),
        x3      REAL REFERENCES pktable(id3),
        x4      TEXT,
        x5      INT2
);
RECEIVED ERROR: temporary tables do not support foreign keys (errno 1105) (sqlstate HY000)
QUERY:          DROP TABLE fk_notpartitioned_pk, fk_partitioned_fk;
RECEIVED ERROR: cannot drop table `fk_notpartitioned_pk` as it is referenced in foreign key `fk_partitioned_fk_a_fkey` (errno 1105) (sqlstate HY000)
QUERY:          CREATE TABLE fk_notpartitioned_pk (a int, b int, primary key (a, b));
RECEIVED ERROR: table with name fk_notpartitioned_pk already exists (errno 1105) (sqlstate HY000)
QUERY:          CREATE TABLE fk_partitioned_fk (a int default 2501, b int default 142857) PARTITION BY LIST (a);
RECEIVED ERROR: table with name fk_partitioned_fk already exists (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_notpartitioned_pk VALUES (2502, 2503);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_partitioned_fk (a,b) VALUES (NULL, NULL);
RECEIVED ERROR: Unknown column 'b' in 'fk_partitioned_fk' (errno 1054) (sqlstate HY000)
QUERY:          INSERT INTO fk_notpartitioned_pk VALUES (1, 2);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_partitioned_fk VALUES (2503, 2503);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          DELETE FROM fk_notpartitioned_pk;
RECEIVED ERROR: cannot delete or update a parent row - Foreign key violation on fk: `fk_partitioned_fk_a_fkey`, table: `fk_partitioned_fk`, referenced table: `fk_notpartitioned_pk`, key: `[1]` (errno 1451) (sqlstate HY000)
QUERY:          INSERT INTO fk_notpartitioned_pk VALUES (2502, 2503);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_notpartitioned_pk VALUES (2501, 142857);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          DELETE FROM fk_notpartitioned_pk WHERE b = 142857;
RECEIVED ERROR: column "b" could not be found in any table in scope (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_notpartitioned_pk VALUES (500, 100000), (2501, 100000);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_partitioned_fk VALUES (500, 100000);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)
QUERY:          DELETE FROM fk_notpartitioned_pk WHERE b = 142857;
RECEIVED ERROR: column "b" could not be found in any table in scope (errno 1105) (sqlstate HY000)
QUERY:          SELECT * FROM fk_partitioned_fk WHERE a = 142857;
RECEIVED ERROR: expected column count 2 but received 1
QUERY:          CREATE TABLE fk_partitioned_fk_4 (a int, b int, FOREIGN KEY (a, b) REFERENCES fk_notpartitioned_pk(a, b) ON UPDATE CASCADE ON DELETE CASCADE) PARTITION BY RANGE (b, a);
RECEIVED ERROR: table "fk_notpartitioned_pk" does not have column "b" (errno 1105) (sqlstate HY000)
QUERY:          CREATE TABLE fk_partitioned_fk_4_2 (a int, b int, FOREIGN KEY (a, b) REFERENCES fk_notpartitioned_pk(a, b) ON UPDATE SET NULL);
RECEIVED ERROR: table "fk_notpartitioned_pk" does not have column "b" (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO fk_notpartitioned_pk VALUES (1600, 601), (1600, 1601);
RECEIVED ERROR: number of values does not match number of columns provided (errno 1105) (sqlstate HY000)

generated

QUERY:          DROP TABLE gtest23a;
RECEIVED ERROR: cannot drop table `gtest23a` as it is referenced in foreign key `gtest23x_b_fkey` (errno 1105) (sqlstate HY000)
QUERY:          INSERT INTO gtest23q VALUES (1, 2);
RECEIVED ERROR: cannot add or update a child row - Foreign key violation on fk: `gtest23q_b_fkey`, table: `gtest23q`, referenced table: `gtest23p`, key: `[2]` (errno 1452) (sqlstate HY000)

truncate

QUERY:          DROP TABLE trunc_a, ref_c;
RECEIVED ERROR: cannot drop table `trunc_a` as it is referenced in foreign key `ref_c_a_fkey` (errno 1105) (sqlstate HY000)

with

QUERY:          CREATE TEMPORARY TABLE tree(
    id INTEGER PRIMARY KEY,
    parent_id INTEGER REFERENCES tree(id)
);
RECEIVED ERROR: temporary tables do not support foreign keys (errno 1105) (sqlstate HY000)

${\color{lightgreen}Progressions (13)}$

alter_table

QUERY: alter table atacc1 drop constraint "atacc1_pkey";

foreign_key

QUERY: DELETE FROM fk_notpartitioned_pk WHERE a = 1;
QUERY: INSERT INTO fk_partitioned_fk (a, b) VALUES (2502, 2503);

generated

QUERY: INSERT INTO gtest23q VALUES (2, 5);

indexing

QUERY: alter table idxpart drop constraint idxpart_pkey;

inherit

QUERY: ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id1_fkey;

rowsecurity

QUERY: DELETE FROM category WHERE cid = 33;
QUERY: SELECT * FROM category;
QUERY: SELECT * FROM category;
QUERY: SELECT * FROM category;
QUERY: SELECT * FROM category;
QUERY: SELECT * FROM category;

triggers

QUERY: select * from trigtest2;

Footnotes

  1. These are tests that we're marking as Successful, however they do not match the expected output in some way. This is due to small differences, such as different wording on the error messages, or the column names being incorrect while the data itself is correct.

@fulghum fulghum force-pushed the fulghum/key_naming branch 2 times, most recently from 961b9f3 to 4c61ee5 Compare March 11, 2025 01:32
@fulghum fulghum requested a review from Hydrocharged March 11, 2025 22:58
Copy link
Copy Markdown
Collaborator

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

LGTM!

@fulghum fulghum force-pushed the fulghum/key_naming branch from 4c61ee5 to fb38799 Compare March 12, 2025 18:32
@fulghum fulghum merged commit 6906c72 into main Mar 12, 2025
14 checks passed
@fulghum fulghum deleted the fulghum/key_naming branch March 12, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants