Commit f00c440
committed
Ensure that expandTableLikeClause() re-examines the same table.
As it stood, expandTableLikeClause() re-did the same relation_openrv
call that transformTableLikeClause() had done. However there are
scenarios where this would not find the same table as expected.
We hold lock on the LIKE source table, so it can't be renamed or
dropped, but another table could appear before it in the search path.
This explains the odd behavior reported in bug #16758 when cloning a
table as a temp table of the same name. This case worked as expected
before commit 5028981 introduced the need to open the source table
twice, so we should fix it.
To make really sure we get the same table, let's re-open it by OID not
name. That requires adding an OID field to struct TableLikeClause,
which is a little nervous-making from an ABI standpoint, but as long
as it's at the end I don't think there's any serious risk.
Per bug #16758 from Marc Boeren. Like the previous patch,
back-patch to all supported branches.
Discussion: https://postgr.es/m/16758-840e84a6cfab276d@postgresql.org1 parent d0bbe21 commit f00c440Copy full SHA for f00c440
File tree
Expand file treeCollapse file tree
8 files changed
+43
-3
lines changedOpen diff view settings
Filter options
- src
- backend
- nodes
- parser
- include/nodes
- test/regress
- expected
- sql
Expand file treeCollapse file tree
8 files changed
+43
-3
lines changedOpen diff view settings
Collapse file
src/backend/nodes/copyfuncs.c
Copy file name to clipboardExpand all lines: src/backend/nodes/copyfuncs.c+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3025 | 3025 | |
3026 | 3026 | |
3027 | 3027 | |
| 3028 | + |
3028 | 3029 | |
3029 | 3030 | |
3030 | 3031 | |
|
Collapse file
src/backend/nodes/equalfuncs.c
Copy file name to clipboardExpand all lines: src/backend/nodes/equalfuncs.c+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1172 | 1172 | |
1173 | 1173 | |
1174 | 1174 | |
| 1175 | + |
1175 | 1176 | |
1176 | 1177 | |
1177 | 1178 | |
|
Collapse file
src/backend/nodes/outfuncs.c
Copy file name to clipboardExpand all lines: src/backend/nodes/outfuncs.c+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
2541 | 2541 | |
2542 | 2542 | |
2543 | 2543 | |
| 2544 | + |
2544 | 2545 | |
2545 | 2546 | |
2546 | 2547 | |
|
Collapse file
+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3174 | 3174 | |
3175 | 3175 | |
3176 | 3176 | |
| 3177 | + |
3177 | 3178 | |
3178 | 3179 | |
3179 | 3180 | |
|
Collapse file
src/backend/parser/parse_utilcmd.c
Copy file name to clipboardExpand all lines: src/backend/parser/parse_utilcmd.c+11-3Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
909 | 909 | |
910 | 910 | |
911 | 911 | |
912 | | - |
| 912 | + |
| 913 | + |
913 | 914 | |
914 | 915 | |
915 | 916 | |
916 | 917 | |
| 918 | + |
| 919 | + |
917 | 920 | |
| 921 | + |
918 | 922 | |
919 | 923 | |
920 | 924 | |
| ||
948 | 952 | |
949 | 953 | |
950 | 954 | |
951 | | - |
| 955 | + |
| 956 | + |
952 | 957 | |
953 | | - |
| 958 | + |
| 959 | + |
| 960 | + |
| 961 | + |
954 | 962 | |
955 | 963 | |
956 | 964 | |
|
Collapse file
src/include/nodes/parsenodes.h
Copy file name to clipboardExpand all lines: src/include/nodes/parsenodes.h+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
610 | 610 | |
611 | 611 | |
612 | 612 | |
| 613 | + |
613 | 614 | |
614 | 615 | |
615 | 616 | |
|
Collapse file
src/test/regress/expected/create_table_like.out
Copy file name to clipboardExpand all lines: src/test/regress/expected/create_table_like.out+19Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
275 | 275 | |
276 | 276 | |
277 | 277 | |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
278 | 297 | |
279 | 298 | |
280 | 299 | |
|
Collapse file
src/test/regress/sql/create_table_like.sql
Copy file name to clipboardExpand all lines: src/test/regress/sql/create_table_like.sql+8Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
122 | 122 | |
123 | 123 | |
124 | 124 | |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
125 | 133 | |
126 | 134 | |
127 | 135 | |
|
0 commit comments