aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/index.c17
-rw-r--r--src/test/regress/expected/create_index.out37
-rw-r--r--src/test/regress/sql/create_index.sql12
3 files changed, 57 insertions, 9 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index e9955707fa7..79439a0c66d 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -313,6 +313,14 @@ ConstructTupleDescriptor(Relation heapRelation,
collationObjectId[i] : InvalidOid;
/*
+ * Set the attribute name as specified by caller.
+ */
+ if (colnames_item == NULL) /* shouldn't happen */
+ elog(ERROR, "too few entries in colnames list");
+ namestrcpy(&to->attname, (const char *) lfirst(colnames_item));
+ colnames_item = lnext(indexColNames, colnames_item);
+
+ /*
* For simple index columns, we copy some pg_attribute fields from the
* parent relation. For expressions we have to look at the expression
* result.
@@ -329,7 +337,6 @@ ConstructTupleDescriptor(Relation heapRelation,
from = TupleDescAttr(heapTupDesc,
AttrNumberGetAttrOffset(atnum));
- namecpy(&to->attname, &from->attname);
to->atttypid = from->atttypid;
to->attlen = from->attlen;
to->attndims = from->attndims;
@@ -391,14 +398,6 @@ ConstructTupleDescriptor(Relation heapRelation,
to->attrelid = InvalidOid;
/*
- * Set the attribute name as specified by caller.
- */
- if (colnames_item == NULL) /* shouldn't happen */
- elog(ERROR, "too few entries in colnames list");
- namestrcpy(&to->attname, (const char *) lfirst(colnames_item));
- colnames_item = lnext(indexColNames, colnames_item);
-
- /*
* Check the opclass and index AM to see if either provides a keytype
* (overriding the attribute type). Opclass (if exists) takes
* precedence.
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 645ae2cf343..6446907a65b 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -1281,6 +1281,23 @@ ERROR: duplicate key value violates unique constraint "func_index_index"
DETAIL: Key (textcat(f1, f2))=(ABCDEF) already exists.
-- but this shouldn't:
INSERT INTO func_index_heap VALUES('QWERTY');
+-- while we're here, see that the metadata looks sane
+\d func_index_heap
+ Table "public.func_index_heap"
+ Column | Type | Collation | Nullable | Default
+--------+------+-----------+----------+---------
+ f1 | text | | |
+ f2 | text | | |
+Indexes:
+ "func_index_index" UNIQUE, btree (textcat(f1, f2))
+
+\d func_index_index
+ Index "public.func_index_index"
+ Column | Type | Key? | Definition
+---------+------+------+-----------------
+ textcat | text | yes | textcat(f1, f2)
+unique, btree, for table "public.func_index_heap"
+
--
-- Same test, expressional index
--
@@ -1296,6 +1313,26 @@ ERROR: duplicate key value violates unique constraint "func_index_index"
DETAIL: Key ((f1 || f2))=(ABCDEF) already exists.
-- but this shouldn't:
INSERT INTO func_index_heap VALUES('QWERTY');
+-- while we're here, see that the metadata looks sane
+\d func_index_heap
+ Table "public.func_index_heap"
+ Column | Type | Collation | Nullable | Default
+--------+------+-----------+----------+---------
+ f1 | text | | |
+ f2 | text | | |
+Indexes:
+ "func_index_index" UNIQUE, btree ((f1 || f2))
+
+\d func_index_index
+ Index "public.func_index_index"
+ Column | Type | Key? | Definition
+--------+------+------+------------
+ expr | text | yes | (f1 || f2)
+unique, btree, for table "public.func_index_heap"
+
+-- this should fail because of unsafe column type (anonymous record)
+create index on func_index_heap ((f1 || f2), (row(f1, f2)));
+ERROR: column "row" has pseudo-type record
--
-- Test unique index with included columns
--
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index 73a55ead4bf..3c0c1cdc5ec 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -401,6 +401,10 @@ INSERT INTO func_index_heap VALUES('ABCD', 'EF');
-- but this shouldn't:
INSERT INTO func_index_heap VALUES('QWERTY');
+-- while we're here, see that the metadata looks sane
+\d func_index_heap
+\d func_index_index
+
--
-- Same test, expressional index
@@ -417,6 +421,14 @@ INSERT INTO func_index_heap VALUES('ABCD', 'EF');
-- but this shouldn't:
INSERT INTO func_index_heap VALUES('QWERTY');
+-- while we're here, see that the metadata looks sane
+\d func_index_heap
+\d func_index_index
+
+-- this should fail because of unsafe column type (anonymous record)
+create index on func_index_heap ((f1 || f2), (row(f1, f2)));
+
+
--
-- Test unique index with included columns
--