forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit71f4c8c
committed
ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY
Allow a partition be detached from its partitioned table withoutblocking concurrent queries, by running in two transactions and onlyrequiring ShareUpdateExclusive in the partitioned table.Because it runs in two transactions, it cannot be used in a transactionblock. This is the main reason to use dedicated syntax: so that userscan choose to use the original mode if they need it. But also, itdoesn't work when a default partition exists (because an exclusive lockwould still need to be obtained on it, in order to change its partitionconstraint.)In case the second transaction is cancelled or a crash occurs, there'sALTER TABLE .. DETACH PARTITION .. FINALIZE, which executes the finalsteps.The main trick to make this work is the addition of columnpg_inherits.inhdetachpending, initially false; can only be set true inthe first part of this command. Once that is committed, concurrenttransactions that use a PartitionDirectory will include or ignorepartitions so marked: in optimizer they are ignored if the row is markedcommitted for the snapshot; in executor they are always included. As aresult, and because of the way PartitionDirectory caches partitiondescriptors, queries that were planned before the detach will see therows in the detached partition and queries that are planned after thedetach, won't.A CHECK constraint is created that duplicates the partition constraint.This is probably not strictly necessary, and some users will prefer toremove it afterwards, but if the partition is re-attached to apartitioned table, the constraint needn't be rechecked.Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Reviewed-by: Amit Langote <amitlangote09@gmail.com>Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>Discussion:https://postgr.es/m/20200803234854.GA24158@alvherre.pgsql1 parent650d623 commit71f4c8c
File tree
41 files changed
+2266
-168
lines changed- doc/src/sgml
- ref
- src
- backend
- catalog
- commands
- executor
- nodes
- optimizer/util
- parser
- partitioning
- tcop
- utils
- adt
- cache
- bin/psql
- include
- catalog
- nodes
- parser
- partitioning
- utils
- test
- isolation
- expected
- specs
- modules/delay_execution
- expected
- specs
- regress
- expected
- sql
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
41 files changed
+2266
-168
lines changedLines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4497 | 4497 |
| |
4498 | 4498 |
| |
4499 | 4499 |
| |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
| 4505 | + | |
| 4506 | + | |
| 4507 | + | |
| 4508 | + | |
| 4509 | + | |
4500 | 4510 |
| |
4501 | 4511 |
| |
4502 | 4512 |
| |
|
Lines changed: 24 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
39 |
| - | |
| 39 | + | |
40 | 40 |
| |
41 | 41 |
| |
42 | 42 |
| |
| |||
954 | 954 |
| |
955 | 955 |
| |
956 | 956 |
| |
957 |
| - | |
| 957 | + | |
| 958 | + | |
958 | 959 |
| |
959 | 960 |
| |
960 | 961 |
| |
| |||
965 | 966 |
| |
966 | 967 |
| |
967 | 968 |
| |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
968 | 990 |
| |
969 | 991 |
| |
970 | 992 |
| |
|
Lines changed: 14 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1923 | 1923 |
| |
1924 | 1924 |
| |
1925 | 1925 |
| |
1926 |
| - | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
1927 | 1932 |
| |
1928 | 1933 |
| |
1929 | 1934 |
| |
| |||
2559 | 2564 |
| |
2560 | 2565 |
| |
2561 | 2566 |
| |
2562 |
| - | |
2563 |
| - | |
2564 |
| - | |
2565 |
| - | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
2566 | 2573 |
| |
2567 | 2574 |
| |
2568 | 2575 |
| |
| |||
3831 | 3838 |
| |
3832 | 3839 |
| |
3833 | 3840 |
| |
3834 |
| - | |
| 3841 | + | |
| 3842 | + | |
3835 | 3843 |
| |
3836 | 3844 |
| |
3837 | 3845 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1837 | 1837 |
| |
1838 | 1838 |
| |
1839 | 1839 |
| |
1840 |
| - | |
| 1840 | + | |
1841 | 1841 |
| |
1842 | 1842 |
| |
1843 | 1843 |
| |
| |||
2487 | 2487 |
| |
2488 | 2488 |
| |
2489 | 2489 |
| |
2490 |
| - | |
| 2490 | + | |
2491 | 2491 |
| |
2492 | 2492 |
| |
2493 | 2493 |
| |
|
Lines changed: 30 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
32 | 32 |
| |
33 | 33 |
| |
34 | 34 |
| |
35 |
| - | |
| 35 | + | |
| 36 | + | |
36 | 37 |
| |
37 | 38 |
| |
38 | 39 |
| |
| |||
42 | 43 |
| |
43 | 44 |
| |
44 | 45 |
| |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 |
| |
46 | 50 |
| |
47 | 51 |
| |
48 | 52 |
| |
49 | 53 |
| |
50 |
| - | |
| 54 | + | |
51 | 55 |
| |
52 | 56 |
| |
53 | 57 |
| |
| 58 | + | |
54 | 59 |
| |
55 | 60 |
| |
56 | 61 |
| |
57 |
| - | |
| 62 | + | |
| 63 | + | |
58 | 64 |
| |
59 | 65 |
| |
60 | 66 |
| |
61 | 67 |
| |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
62 | 72 |
| |
63 | 73 |
| |
64 | 74 |
| |
| |||
68 | 78 |
| |
69 | 79 |
| |
70 | 80 |
| |
| 81 | + | |
| 82 | + | |
| 83 | + | |
71 | 84 |
| |
72 | 85 |
| |
73 |
| - | |
| 86 | + | |
74 | 87 |
| |
75 | 88 |
| |
76 | 89 |
| |
77 | 90 |
| |
78 | 91 |
| |
79 | 92 |
| |
| 93 | + | |
| 94 | + | |
80 | 95 |
| |
81 | 96 |
| |
82 | 97 |
| |
| |||
93 | 108 |
| |
94 | 109 |
| |
95 | 110 |
| |
| 111 | + | |
| 112 | + | |
| 113 | + | |
96 | 114 |
| |
97 | 115 |
| |
98 | 116 |
| |
| |||
134 | 152 |
| |
135 | 153 |
| |
136 | 154 |
| |
| 155 | + | |
137 | 156 |
| |
138 |
| - | |
139 |
| - | |
140 |
| - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
141 | 163 |
| |
142 | 164 |
| |
143 | 165 |
| |
| |||
170 | 192 |
| |
171 | 193 |
| |
172 | 194 |
| |
173 |
| - | |
| 195 | + | |
174 | 196 |
| |
175 | 197 |
| |
176 | 198 |
| |
|
0 commit comments
Comments
(0)