Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Test that a type cannot be dropped or altered in an incompatible way
# while it's being used as a column type in a concurrent CREATE TABLE
# transaction.
 
session "s1"
 
step s1_create_domain { CREATE DOMAIN testdom AS integer; }
step s1_create_rowtype_tbl { CREATE TABLE rowtype(a int8, b text); }
step s1_create_rowtype_comp { CREATE TYPE rowtype AS(a int8, b text); }
 
step s1_begin { BEGIN; }
step s1_create_testtab { CREATE TABLE testtab (a int); }
step s1_add_domain_col { ALTER TABLE testtab ADD COLUMN b testdom; }
step s1_create_testtab_with_domain { CREATE TABLE testtab (a int, b testdom); }
step s1_create_testview_with_domain { CREATE VIEW testview AS SELECT 123::testdom IS NULL; }
step s1_create_testtab_with_rowtype { CREATE TABLE testtab (a int, b rowtype); }
step s1_create_testview_with_rowtype_top { CREATE VIEW testview AS SELECT '(1,b)'::rowtype; }
step s1_create_testview_with_rowtype_sub { CREATE VIEW testview AS SELECT '(1,b)'::rowtype IS NULL; }
step s1_create_function { CREATE FUNCTION testfunc(rowtype) RETURNS rowtype AS $$ SELECT $1 $$ LANGUAGE SQL; }
step s1_alter_function_with_default { CREATE OR REPLACE FUNCTION testfunc(rowtype DEFAULT '(1,b)'::rowtype) RETURNS rowtype AS $$ SELECT $1 $$ LANGUAGE SQL; }
step s1_commit { COMMIT; }
 
step s1_drop_domain { DROP DOMAIN testdom; }
step s1_drop_testtab { DROP TABLE testtab; }
step s1_drop_testview { DROP VIEW testview; }
step s1_drop_function { DROP FUNCTION testfunc; }
step s1_drop_rowtype_tbl { DROP TABLE rowtype; }
step s1_drop_rowtype_comp { DROP TYPE rowtype; }
 
session "s2"
 
#step s2_begin { BEGIN; }
#step s2_commit { COMMIT; }
step s2_drop_domain { DROP DOMAIN testdom; }
step s2_alter_rowtype_comp_to_text { ALTER TYPE rowtype ALTER ATTRIBUTE a TYPE text; }
step s2_alter_rowtype_tbl_to_text { ALTER TABLE rowtype ALTER COLUMN a TYPE text; }
step s2_alter_rowtype_tbl_add_col { ALTER TABLE rowtype ADD COLUMN c bigint; }
step s2_drop_rowtype_tbl { DROP TABLE rowtype; }
 
# Test that when a domain is used in a new, not-yet-committed, table,
# it cannot be concurrently dropped.
permutation
    s1_create_domain
    s1_begin
    s1_create_testtab_with_domain
    s2_drop_domain
    s1_commit
    s1_drop_testtab
    s1_drop_domain
 
# Test the same race condition with ADD COLUMN to an existing table
permutation
    s1_create_domain
    s1_create_testtab
    s1_begin
    s1_add_domain_col
    s2_drop_domain
    s1_commit
    s1_drop_testtab
    s1_drop_domain
 
# Same, but it's not used as a column type, but in an expression in a view
permutation
    s1_create_domain
    s1_begin
    s1_create_testview_with_domain
    s2_drop_domain
    s1_commit
    s1_drop_testview
    s1_drop_domain
 
# Test the similar race condition where a DEFAULT expression is added
# to an existing function, which prevents altering the composite type.
permutation
    s1_create_rowtype_comp
    s1_create_function
    s1_begin
    s1_alter_function_with_default
    s2_alter_rowtype_comp_to_text
    s1_commit
    s1_drop_function
    s1_drop_rowtype_comp
 
# Test that a new reference to a rowtype that is concurrently being
# dropped is handled correctly. Here the drop happens first.
#
# XXX: Disabled for now, because the error message "could not open
# relation with OID" contains the relation's OID which is not stable.
#permutation
#    s1_create_rowtype_tbl
#    s2_begin
#    s2_drop_rowtype_tbl
#    s1_create_testtab_with_rowtype # blocks
#    s2_commit
#    # s1 errors out slightly weirdly
 
# Here the new reference happens first
permutation
    s1_create_rowtype_tbl
    s1_begin
    s1_create_testtab_with_rowtype
    s2_drop_rowtype_tbl  # blocks
    s1_commit
    # s2 errors out with dependency error
    s1_drop_testtab
    s1_drop_rowtype_tbl
 
# Like above, but with a view that uses the rowtype in the view body
permutation
    s1_create_rowtype_tbl
    s1_begin
    s1_create_testview_with_rowtype_top
    s2_drop_rowtype_tbl
    s1_commit
    s1_drop_testview
    s1_drop_rowtype_tbl
 
permutation
    s1_create_rowtype_tbl
    s1_begin
    s1_create_testview_with_rowtype_sub
    s2_drop_rowtype_tbl
    s1_commit
    s1_drop_testview
    s1_drop_rowtype_tbl
 
# Test that when a composite type is used in a new, not-yet-committed,
# table, it cannot be ALTERed concurrently in a way that would require
# rewriting the table that uses it.
permutation
    s1_create_rowtype_comp
    s1_begin
    s1_create_testtab_with_rowtype
    s2_alter_rowtype_comp_to_text
    s1_commit
    s1_drop_testtab
    s1_drop_rowtype_comp
 
# Same with a rowtype of another table rather than an explicit
# composite type.
permutation
    s1_create_rowtype_tbl
    s1_begin
    s1_create_testtab_with_rowtype
    s2_alter_rowtype_tbl_to_text
    s1_commit
    s1_drop_testtab
    s1_drop_rowtype_tbl
 
# Same, but the rowtype isn't used directly as a column in another table,
# but in an expression in a view.
permutation
    s1_create_rowtype_comp
    s1_begin
    s1_create_testview_with_rowtype_sub
    s2_alter_rowtype_comp_to_text
    s1_commit
    s1_drop_testview
    s1_drop_rowtype_comp
 
# Adding a column doesn't require rewriting existing data, so this
# could be allowed, but is blocked currently by the AccessShareLock
# that CREATE TABLE holds on the rowtype.
permutation
    s1_create_rowtype_tbl
    s1_begin
    s1_create_testtab_with_rowtype
    s2_alter_rowtype_tbl_add_col # blocks
    s1_commit
    s1_drop_testtab
    s1_drop_rowtype_tbl