Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc449ab

Browse files
committed
Fix error reporting for index expressions of prohibited types.
If CheckAttributeType() threw an error about the datatype of anindex expression column, it would report an empty column name,which is pretty unhelpful and certainly not the intended behavior.I (tgl) evidently broke this in commitcfc5008, by not noticingthat the column's attname was used above where I'd placed theassignment of it.In HEAD and v12, this is trivially fixable by moving up theassignment of attname. Before v12 the code is a bit more messy;to avoid doing substantial refactoring, I took the lazy way outand just put in two copies of the assignment code.Report and patch by Amit Langote. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/CA+HiwqFA+BGyBFimjiYXXMa2Hc3fcL0+OJOyzUNjhU4NCa_XXw@mail.gmail.com
1 parentfc68a10 commitfc449ab

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

‎src/backend/catalog/index.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ ConstructTupleDescriptor(Relation heapRelation,
368368
*/
369369
memcpy(to,from,ATTRIBUTE_FIXED_PART_SIZE);
370370

371+
/*
372+
* Set the attribute name as specified by caller.
373+
*/
374+
if (colnames_item==NULL)/* shouldn't happen */
375+
elog(ERROR,"too few entries in colnames list");
376+
namestrcpy(&to->attname, (constchar*)lfirst(colnames_item));
377+
colnames_item=lnext(colnames_item);
378+
371379
/*
372380
* Fix the stuff that should not be the same as the underlying
373381
* attr
@@ -392,6 +400,14 @@ ConstructTupleDescriptor(Relation heapRelation,
392400

393401
MemSet(to,0,ATTRIBUTE_FIXED_PART_SIZE);
394402

403+
/*
404+
* Set the attribute name as specified by caller.
405+
*/
406+
if (colnames_item==NULL)/* shouldn't happen */
407+
elog(ERROR,"too few entries in colnames list");
408+
namestrcpy(&to->attname, (constchar*)lfirst(colnames_item));
409+
colnames_item=lnext(colnames_item);
410+
395411
if (indexpr_item==NULL)/* shouldn't happen */
396412
elog(ERROR,"too few entries in indexprs list");
397413
indexkey= (Node*)lfirst(indexpr_item);
@@ -445,14 +461,6 @@ ConstructTupleDescriptor(Relation heapRelation,
445461
*/
446462
to->attrelid=InvalidOid;
447463

448-
/*
449-
* Set the attribute name as specified by caller.
450-
*/
451-
if (colnames_item==NULL)/* shouldn't happen */
452-
elog(ERROR,"too few entries in colnames list");
453-
namestrcpy(&to->attname, (constchar*)lfirst(colnames_item));
454-
colnames_item=lnext(colnames_item);
455-
456464
/*
457465
* Check the opclass and index AM to see if either provides a keytype
458466
* (overriding the attribute type). Opclass (if exists) takes

‎src/test/regress/expected/create_index.out

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,23 @@ ERROR: duplicate key value violates unique constraint "func_index_index"
24172417
DETAIL: Key (textcat(f1, f2))=(ABCDEF) already exists.
24182418
-- but this shouldn't:
24192419
INSERT INTO func_index_heap VALUES('QWERTY');
2420+
-- while we're here, see that the metadata looks sane
2421+
\d func_index_heap
2422+
Table "public.func_index_heap"
2423+
Column | Type | Collation | Nullable | Default
2424+
--------+------+-----------+----------+---------
2425+
f1 | text | | |
2426+
f2 | text | | |
2427+
Indexes:
2428+
"func_index_index" UNIQUE, btree (textcat(f1, f2))
2429+
2430+
\d func_index_index
2431+
Index "public.func_index_index"
2432+
Column | Type | Key? | Definition
2433+
---------+------+------+-----------------
2434+
textcat | text | yes | textcat(f1, f2)
2435+
unique, btree, for table "public.func_index_heap"
2436+
24202437
--
24212438
-- Same test, expressional index
24222439
--
@@ -2432,6 +2449,26 @@ ERROR: duplicate key value violates unique constraint "func_index_index"
24322449
DETAIL: Key ((f1 || f2))=(ABCDEF) already exists.
24332450
-- but this shouldn't:
24342451
INSERT INTO func_index_heap VALUES('QWERTY');
2452+
-- while we're here, see that the metadata looks sane
2453+
\d func_index_heap
2454+
Table "public.func_index_heap"
2455+
Column | Type | Collation | Nullable | Default
2456+
--------+------+-----------+----------+---------
2457+
f1 | text | | |
2458+
f2 | text | | |
2459+
Indexes:
2460+
"func_index_index" UNIQUE, btree ((f1 || f2))
2461+
2462+
\d func_index_index
2463+
Index "public.func_index_index"
2464+
Column | Type | Key? | Definition
2465+
--------+------+------+------------
2466+
expr | text | yes | (f1 || f2)
2467+
unique, btree, for table "public.func_index_heap"
2468+
2469+
-- this should fail because of unsafe column type (anonymous record)
2470+
create index on func_index_heap ((f1 || f2), (row(f1, f2)));
2471+
ERROR: column "row" has pseudo-type record
24352472
--
24362473
-- Test unique index with included columns
24372474
--

‎src/test/regress/sql/create_index.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ INSERT INTO func_index_heap VALUES('ABCD', 'EF');
725725
-- but this shouldn't:
726726
INSERT INTO func_index_heapVALUES('QWERTY');
727727

728+
-- while we're here, see that the metadata looks sane
729+
\d func_index_heap
730+
\d func_index_index
731+
728732

729733
--
730734
-- Same test, expressional index
@@ -741,6 +745,14 @@ INSERT INTO func_index_heap VALUES('ABCD', 'EF');
741745
-- but this shouldn't:
742746
INSERT INTO func_index_heapVALUES('QWERTY');
743747

748+
-- while we're here, see that the metadata looks sane
749+
\d func_index_heap
750+
\d func_index_index
751+
752+
-- this should fail because of unsafe column type (anonymous record)
753+
createindexon func_index_heap ((f1|| f2), (row(f1, f2)));
754+
755+
744756
--
745757
-- Test unique index with included columns
746758
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp