diff --git a/src/postgres/src/backend/tcop/utility.c b/src/postgres/src/backend/tcop/utility.c index 65c5c7dafd27..8dabf8a63703 100644 --- a/src/postgres/src/backend/tcop/utility.c +++ b/src/postgres/src/backend/tcop/utility.c @@ -1373,11 +1373,14 @@ ProcessUtilitySlow(ParseState *pstate, * build. * TODO(jason): heed issue #6240. */ - ereport(DEBUG1, + ereport(NOTICE, (errmsg("making create index for table " - "\"%s\" in transaction block " - "nonconcurrent", - stmt->relation->relname))); + "\"%s\" nonconcurrent", + stmt->relation->relname), + errdetail("Create index in transaction" + " block cannot be concurrent."), + errhint("Consider running it outside of a" + " transaction block. See https://github.com/yugabyte/yugabyte-db/issues/6240."))); stmt->concurrent = false; } else diff --git a/src/postgres/src/test/regress/expected/yb_create_table.out b/src/postgres/src/test/regress/expected/yb_create_table.out index 453705796245..3426a254c9c5 100644 --- a/src/postgres/src/test/regress/expected/yb_create_table.out +++ b/src/postgres/src/test/regress/expected/yb_create_table.out @@ -708,3 +708,9 @@ set yb_enable_create_with_table_oid=0; create table with_table_oid_variable_false (a int) with (table_oid = 55555); ERROR: create table with table_oid is not allowed HINT: Try enabling the session variable yb_enable_create_with_table_oid. +RESET yb_enable_create_with_table_oid; +-- CREATE TABLE with implicit UNIQUE INDEX shouldn't spout a notice about it +-- being nonconcurrent. +BEGIN; +CREATE TABLE tab_with_unique (i int, UNIQUE (i)); +COMMIT; diff --git a/src/postgres/src/test/regress/expected/yb_pg_create_index.out b/src/postgres/src/test/regress/expected/yb_pg_create_index.out index 2ce711142800..c557e9ff8d4b 100644 --- a/src/postgres/src/test/regress/expected/yb_pg_create_index.out +++ b/src/postgres/src/test/regress/expected/yb_pg_create_index.out @@ -27,3 +27,30 @@ CREATE INDEX iix ON ihighway USING lsm (name text_ops); ERROR: relation "ihighway" does not exist CREATE INDEX six ON shighway USING lsm (name text_ops); ERROR: relation "shighway" does not exist +-- +-- Try some concurrent index builds +-- +-- Unfortunately this only tests about half the code paths because there are +-- no concurrent updates happening to the table at the same time. +CREATE TABLE concur_heap (f1 text, f2 text); +-- empty table +CREATE INDEX CONCURRENTLY concur_index1 ON concur_heap(f2,f1); +ERROR: CREATE INDEX CONCURRENTLY not supported yet +LINE 1: CREATE INDEX CONCURRENTLY concur_index1 ON concur_heap(f2,f1... + ^ +HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues +-- You can't do a concurrent index build in a transaction +BEGIN; +CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1); +ERROR: CREATE INDEX CONCURRENTLY not supported yet +LINE 1: CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1); + ^ +HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues +COMMIT; +-- But you can do a regular index build in a transaction +BEGIN; +CREATE INDEX std_index on concur_heap(f2); +NOTICE: making create index for table "concur_heap" nonconcurrent +DETAIL: Create index in transaction block cannot be concurrent. +HINT: Consider running it outside of a transaction block. See https://github.com/yugabyte/yugabyte-db/issues/6240. +COMMIT; diff --git a/src/postgres/src/test/regress/sql/yb_create_table.sql b/src/postgres/src/test/regress/sql/yb_create_table.sql index 3332e61e6d67..a2ad58318337 100644 --- a/src/postgres/src/test/regress/sql/yb_create_table.sql +++ b/src/postgres/src/test/regress/sql/yb_create_table.sql @@ -541,3 +541,10 @@ select relname, oid from pg_class where relname = 'with_table_oid_2'; -- Test with session variable off set yb_enable_create_with_table_oid=0; create table with_table_oid_variable_false (a int) with (table_oid = 55555); +RESET yb_enable_create_with_table_oid; + +-- CREATE TABLE with implicit UNIQUE INDEX shouldn't spout a notice about it +-- being nonconcurrent. +BEGIN; +CREATE TABLE tab_with_unique (i int, UNIQUE (i)); +COMMIT; diff --git a/src/postgres/src/test/regress/sql/yb_pg_create_index.sql b/src/postgres/src/test/regress/sql/yb_pg_create_index.sql index 4012d8477d3c..9ec8b91efe53 100644 --- a/src/postgres/src/test/regress/sql/yb_pg_create_index.sql +++ b/src/postgres/src/test/regress/sql/yb_pg_create_index.sql @@ -37,3 +37,23 @@ CREATE INDEX rix ON road USING lsm (name text_ops); CREATE INDEX iix ON ihighway USING lsm (name text_ops); CREATE INDEX six ON shighway USING lsm (name text_ops); + +-- +-- Try some concurrent index builds +-- +-- Unfortunately this only tests about half the code paths because there are +-- no concurrent updates happening to the table at the same time. + +CREATE TABLE concur_heap (f1 text, f2 text); +-- empty table +CREATE INDEX CONCURRENTLY concur_index1 ON concur_heap(f2,f1); + +-- You can't do a concurrent index build in a transaction +BEGIN; +CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1); +COMMIT; + +-- But you can do a regular index build in a transaction +BEGIN; +CREATE INDEX std_index on concur_heap(f2); +COMMIT;