1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Code review of CLUSTER patch. Clean up problems with relcache getting

confused, toasted data getting lost, etc.
This commit is contained in:
Tom Lane
2002-08-11 21:17:35 +00:00
parent 9bccdf17f7
commit e44beef712
12 changed files with 560 additions and 431 deletions

View File

@ -8,6 +8,7 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'clstr_tst_s_pkey
CREATE TABLE clstr_tst (a SERIAL PRIMARY KEY,
b INT,
c TEXT,
d TEXT,
CONSTRAINT clstr_tst_con FOREIGN KEY (b) REFERENCES clstr_tst_s);
NOTICE: CREATE TABLE will create implicit sequence 'clstr_tst_a_seq' for SERIAL column 'clstr_tst.a'
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'clstr_tst_pkey' for table 'clstr_tst'
@ -54,220 +55,222 @@ INSERT INTO clstr_tst (b, c) VALUES (15, 'quince');
INSERT INTO clstr_tst (b, c) VALUES (7, 'siete');
INSERT INTO clstr_tst (b, c) VALUES (16, 'dieciseis');
INSERT INTO clstr_tst (b, c) VALUES (8, 'ocho');
INSERT INTO clstr_tst (b, c) VALUES (6, 'seis');
-- This entry is needed to test that TOASTED values are copied correctly.
INSERT INTO clstr_tst (b, c, d) VALUES (6, 'seis', repeat('xyzzy', 100000));
CLUSTER clstr_tst_c ON clstr_tst;
SELECT * from clstr_tst;
a | b | c
----+----+---------------
10 | 14 | catorce
18 | 5 | cinco
9 | 4 | cuatro
26 | 19 | diecinueve
12 | 18 | dieciocho
30 | 16 | dieciseis
24 | 17 | diecisiete
2 | 10 | diez
23 | 12 | doce
11 | 2 | dos
25 | 9 | nueve
31 | 8 | ocho
1 | 11 | once
28 | 15 | quince
32 | 6 | seis
29 | 7 | siete
15 | 13 | trece
22 | 30 | treinta
17 | 32 | treinta y dos
3 | 31 | treinta y uno
5 | 3 | tres
20 | 1 | uno
6 | 20 | veinte
14 | 25 | veinticinco
21 | 24 | veinticuatro
4 | 22 | veintidos
19 | 29 | veintinueve
16 | 28 | veintiocho
27 | 26 | veintiseis
13 | 27 | veintisiete
7 | 23 | veintitres
8 | 21 | veintiuno
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst;
a | b | c | substring | length
----+----+---------------+--------------------------------+--------
10 | 14 | catorce | |
18 | 5 | cinco | |
9 | 4 | cuatro | |
26 | 19 | diecinueve | |
12 | 18 | dieciocho | |
30 | 16 | dieciseis | |
24 | 17 | diecisiete | |
2 | 10 | diez | |
23 | 12 | doce | |
11 | 2 | dos | |
25 | 9 | nueve | |
31 | 8 | ocho | |
1 | 11 | once | |
28 | 15 | quince | |
32 | 6 | seis | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete | |
15 | 13 | trece | |
22 | 30 | treinta | |
17 | 32 | treinta y dos | |
3 | 31 | treinta y uno | |
5 | 3 | tres | |
20 | 1 | uno | |
6 | 20 | veinte | |
14 | 25 | veinticinco | |
21 | 24 | veinticuatro | |
4 | 22 | veintidos | |
19 | 29 | veintinueve | |
16 | 28 | veintiocho | |
27 | 26 | veintiseis | |
13 | 27 | veintisiete | |
7 | 23 | veintitres | |
8 | 21 | veintiuno | |
(32 rows)
SELECT * from clstr_tst ORDER BY a;
a | b | c
----+----+---------------
1 | 11 | once
2 | 10 | diez
3 | 31 | treinta y uno
4 | 22 | veintidos
5 | 3 | tres
6 | 20 | veinte
7 | 23 | veintitres
8 | 21 | veintiuno
9 | 4 | cuatro
10 | 14 | catorce
11 | 2 | dos
12 | 18 | dieciocho
13 | 27 | veintisiete
14 | 25 | veinticinco
15 | 13 | trece
16 | 28 | veintiocho
17 | 32 | treinta y dos
18 | 5 | cinco
19 | 29 | veintinueve
20 | 1 | uno
21 | 24 | veinticuatro
22 | 30 | treinta
23 | 12 | doce
24 | 17 | diecisiete
25 | 9 | nueve
26 | 19 | diecinueve
27 | 26 | veintiseis
28 | 15 | quince
29 | 7 | siete
30 | 16 | dieciseis
31 | 8 | ocho
32 | 6 | seis
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst ORDER BY a;
a | b | c | substring | length
----+----+---------------+--------------------------------+--------
1 | 11 | once | |
2 | 10 | diez | |
3 | 31 | treinta y uno | |
4 | 22 | veintidos | |
5 | 3 | tres | |
6 | 20 | veinte | |
7 | 23 | veintitres | |
8 | 21 | veintiuno | |
9 | 4 | cuatro | |
10 | 14 | catorce | |
11 | 2 | dos | |
12 | 18 | dieciocho | |
13 | 27 | veintisiete | |
14 | 25 | veinticinco | |
15 | 13 | trece | |
16 | 28 | veintiocho | |
17 | 32 | treinta y dos | |
18 | 5 | cinco | |
19 | 29 | veintinueve | |
20 | 1 | uno | |
21 | 24 | veinticuatro | |
22 | 30 | treinta | |
23 | 12 | doce | |
24 | 17 | diecisiete | |
25 | 9 | nueve | |
26 | 19 | diecinueve | |
27 | 26 | veintiseis | |
28 | 15 | quince | |
29 | 7 | siete | |
30 | 16 | dieciseis | |
31 | 8 | ocho | |
32 | 6 | seis | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
(32 rows)
SELECT * from clstr_tst ORDER BY b;
a | b | c
----+----+---------------
20 | 1 | uno
11 | 2 | dos
5 | 3 | tres
9 | 4 | cuatro
18 | 5 | cinco
32 | 6 | seis
29 | 7 | siete
31 | 8 | ocho
25 | 9 | nueve
2 | 10 | diez
1 | 11 | once
23 | 12 | doce
15 | 13 | trece
10 | 14 | catorce
28 | 15 | quince
30 | 16 | dieciseis
24 | 17 | diecisiete
12 | 18 | dieciocho
26 | 19 | diecinueve
6 | 20 | veinte
8 | 21 | veintiuno
4 | 22 | veintidos
7 | 23 | veintitres
21 | 24 | veinticuatro
14 | 25 | veinticinco
27 | 26 | veintiseis
13 | 27 | veintisiete
16 | 28 | veintiocho
19 | 29 | veintinueve
22 | 30 | treinta
3 | 31 | treinta y uno
17 | 32 | treinta y dos
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst ORDER BY b;
a | b | c | substring | length
----+----+---------------+--------------------------------+--------
20 | 1 | uno | |
11 | 2 | dos | |
5 | 3 | tres | |
9 | 4 | cuatro | |
18 | 5 | cinco | |
32 | 6 | seis | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete | |
31 | 8 | ocho | |
25 | 9 | nueve | |
2 | 10 | diez | |
1 | 11 | once | |
23 | 12 | doce | |
15 | 13 | trece | |
10 | 14 | catorce | |
28 | 15 | quince | |
30 | 16 | dieciseis | |
24 | 17 | diecisiete | |
12 | 18 | dieciocho | |
26 | 19 | diecinueve | |
6 | 20 | veinte | |
8 | 21 | veintiuno | |
4 | 22 | veintidos | |
7 | 23 | veintitres | |
21 | 24 | veinticuatro | |
14 | 25 | veinticinco | |
27 | 26 | veintiseis | |
13 | 27 | veintisiete | |
16 | 28 | veintiocho | |
19 | 29 | veintinueve | |
22 | 30 | treinta | |
3 | 31 | treinta y uno | |
17 | 32 | treinta y dos | |
(32 rows)
SELECT * from clstr_tst ORDER BY c;
a | b | c
----+----+---------------
10 | 14 | catorce
18 | 5 | cinco
9 | 4 | cuatro
26 | 19 | diecinueve
12 | 18 | dieciocho
30 | 16 | dieciseis
24 | 17 | diecisiete
2 | 10 | diez
23 | 12 | doce
11 | 2 | dos
25 | 9 | nueve
31 | 8 | ocho
1 | 11 | once
28 | 15 | quince
32 | 6 | seis
29 | 7 | siete
15 | 13 | trece
22 | 30 | treinta
17 | 32 | treinta y dos
3 | 31 | treinta y uno
5 | 3 | tres
20 | 1 | uno
6 | 20 | veinte
14 | 25 | veinticinco
21 | 24 | veinticuatro
4 | 22 | veintidos
19 | 29 | veintinueve
16 | 28 | veintiocho
27 | 26 | veintiseis
13 | 27 | veintisiete
7 | 23 | veintitres
8 | 21 | veintiuno
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst ORDER BY c;
a | b | c | substring | length
----+----+---------------+--------------------------------+--------
10 | 14 | catorce | |
18 | 5 | cinco | |
9 | 4 | cuatro | |
26 | 19 | diecinueve | |
12 | 18 | dieciocho | |
30 | 16 | dieciseis | |
24 | 17 | diecisiete | |
2 | 10 | diez | |
23 | 12 | doce | |
11 | 2 | dos | |
25 | 9 | nueve | |
31 | 8 | ocho | |
1 | 11 | once | |
28 | 15 | quince | |
32 | 6 | seis | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete | |
15 | 13 | trece | |
22 | 30 | treinta | |
17 | 32 | treinta y dos | |
3 | 31 | treinta y uno | |
5 | 3 | tres | |
20 | 1 | uno | |
6 | 20 | veinte | |
14 | 25 | veinticinco | |
21 | 24 | veinticuatro | |
4 | 22 | veintidos | |
19 | 29 | veintinueve | |
16 | 28 | veintiocho | |
27 | 26 | veintiseis | |
13 | 27 | veintisiete | |
7 | 23 | veintitres | |
8 | 21 | veintiuno | |
(32 rows)
-- Verify that inheritance link still works
INSERT INTO clstr_tst_inh VALUES (0, 100, 'in child table');
SELECT * from clstr_tst;
a | b | c
----+-----+----------------
10 | 14 | catorce
18 | 5 | cinco
9 | 4 | cuatro
26 | 19 | diecinueve
12 | 18 | dieciocho
30 | 16 | dieciseis
24 | 17 | diecisiete
2 | 10 | diez
23 | 12 | doce
11 | 2 | dos
25 | 9 | nueve
31 | 8 | ocho
1 | 11 | once
28 | 15 | quince
32 | 6 | seis
29 | 7 | siete
15 | 13 | trece
22 | 30 | treinta
17 | 32 | treinta y dos
3 | 31 | treinta y uno
5 | 3 | tres
20 | 1 | uno
6 | 20 | veinte
14 | 25 | veinticinco
21 | 24 | veinticuatro
4 | 22 | veintidos
19 | 29 | veintinueve
16 | 28 | veintiocho
27 | 26 | veintiseis
13 | 27 | veintisiete
7 | 23 | veintitres
8 | 21 | veintiuno
0 | 100 | in child table
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst;
a | b | c | substring | length
----+-----+----------------+--------------------------------+--------
10 | 14 | catorce | |
18 | 5 | cinco | |
9 | 4 | cuatro | |
26 | 19 | diecinueve | |
12 | 18 | dieciocho | |
30 | 16 | dieciseis | |
24 | 17 | diecisiete | |
2 | 10 | diez | |
23 | 12 | doce | |
11 | 2 | dos | |
25 | 9 | nueve | |
31 | 8 | ocho | |
1 | 11 | once | |
28 | 15 | quince | |
32 | 6 | seis | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete | |
15 | 13 | trece | |
22 | 30 | treinta | |
17 | 32 | treinta y dos | |
3 | 31 | treinta y uno | |
5 | 3 | tres | |
20 | 1 | uno | |
6 | 20 | veinte | |
14 | 25 | veinticinco | |
21 | 24 | veinticuatro | |
4 | 22 | veintidos | |
19 | 29 | veintinueve | |
16 | 28 | veintiocho | |
27 | 26 | veintiseis | |
13 | 27 | veintisiete | |
7 | 23 | veintitres | |
8 | 21 | veintiuno | |
0 | 100 | in child table | |
(33 rows)
-- Verify that foreign key link still works
INSERT INTO clstr_tst (b, c) VALUES (1111, 'this should fail');
ERROR: clstr_tst_con referential integrity violation - key referenced from clstr_tst not found in clstr_tst_s
SELECT conname FROM pg_constraint WHERE conrelid=(SELECT oid FROM pg_class
WHERE relname='clstr_tst');
SELECT conname FROM pg_constraint WHERE conrelid = 'clstr_tst'::regclass;
conname
----------------
clstr_tst_pkey
clstr_tst_con
(2 rows)
SELECT relname FROM pg_class WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
relname
----------------------
clstr_tst
clstr_tst_a_seq
clstr_tst_b
clstr_tst_b_c
clstr_tst_c
clstr_tst_c_b
clstr_tst_inh
clstr_tst_pkey
clstr_tst_s
clstr_tst_s_pkey
clstr_tst_s_rf_a_seq
SELECT relname, relkind,
EXISTS(SELECT 1 FROM pg_class WHERE oid = c.reltoastrelid) AS hastoast
FROM pg_class c WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
relname | relkind | hastoast
----------------------+---------+----------
clstr_tst | r | t
clstr_tst_a_seq | S | f
clstr_tst_b | i | f
clstr_tst_b_c | i | f
clstr_tst_c | i | f
clstr_tst_c_b | i | f
clstr_tst_inh | r | t
clstr_tst_pkey | i | f
clstr_tst_s | r | f
clstr_tst_s_pkey | i | f
clstr_tst_s_rf_a_seq | S | f
(11 rows)

View File

@ -8,6 +8,7 @@ CREATE TABLE clstr_tst_s (rf_a SERIAL PRIMARY KEY,
CREATE TABLE clstr_tst (a SERIAL PRIMARY KEY,
b INT,
c TEXT,
d TEXT,
CONSTRAINT clstr_tst_con FOREIGN KEY (b) REFERENCES clstr_tst_s);
CREATE INDEX clstr_tst_b ON clstr_tst (b);
@ -55,24 +56,26 @@ INSERT INTO clstr_tst (b, c) VALUES (15, 'quince');
INSERT INTO clstr_tst (b, c) VALUES (7, 'siete');
INSERT INTO clstr_tst (b, c) VALUES (16, 'dieciseis');
INSERT INTO clstr_tst (b, c) VALUES (8, 'ocho');
INSERT INTO clstr_tst (b, c) VALUES (6, 'seis');
-- This entry is needed to test that TOASTED values are copied correctly.
INSERT INTO clstr_tst (b, c, d) VALUES (6, 'seis', repeat('xyzzy', 100000));
CLUSTER clstr_tst_c ON clstr_tst;
SELECT * from clstr_tst;
SELECT * from clstr_tst ORDER BY a;
SELECT * from clstr_tst ORDER BY b;
SELECT * from clstr_tst ORDER BY c;
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst;
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst ORDER BY a;
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst ORDER BY b;
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst ORDER BY c;
-- Verify that inheritance link still works
INSERT INTO clstr_tst_inh VALUES (0, 100, 'in child table');
SELECT * from clstr_tst;
SELECT a,b,c,substring(d for 30), length(d) from clstr_tst;
-- Verify that foreign key link still works
INSERT INTO clstr_tst (b, c) VALUES (1111, 'this should fail');
SELECT conname FROM pg_constraint WHERE conrelid=(SELECT oid FROM pg_class
WHERE relname='clstr_tst');
SELECT conname FROM pg_constraint WHERE conrelid = 'clstr_tst'::regclass;
SELECT relname FROM pg_class WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
SELECT relname, relkind,
EXISTS(SELECT 1 FROM pg_class WHERE oid = c.reltoastrelid) AS hastoast
FROM pg_class c WHERE relname LIKE 'clstr_tst%' ORDER BY relname;