mirror of https://github.com/citusdata/citus.git
Better error on "CREATE INDEX already_exists ..."
Previously (if you're creating the index with the same name on different tables) we successfully ran the command on the workers before failing it on the master and leaving no record of the index. Now we check whether the index exists on the master before sending commands to the workers. -- Also make the error better when user attampts to create an index without a name. Previously those statements returned: brian=# create index on c (b); WARNING: could not receive query results from localhost:9700 DETAIL: Client error: cannot extend name for null index name ERROR: could not execute DDL command on worker node shards They now return brian=# create index on c (b); ERROR: creating index without a name on a distributed table is currently unsupportedpull/410/head
parent
1a370cd1ba
commit
1df4b8ba32
|
@ -572,6 +572,25 @@ ProcessAlterTableStmt(AlterTableStmt *alterTableStatement, const char *alterTabl
|
||||||
static void
|
static void
|
||||||
ErrorIfUnsupportedIndexStmt(IndexStmt *createIndexStatement)
|
ErrorIfUnsupportedIndexStmt(IndexStmt *createIndexStatement)
|
||||||
{
|
{
|
||||||
|
Oid namespaceId;
|
||||||
|
Oid indexRelationId;
|
||||||
|
char* indexRelationName = createIndexStatement->idxname;
|
||||||
|
|
||||||
|
if (indexRelationName == NULL)
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("creating index without a name on a distributed table is "
|
||||||
|
"currently unsupported")));
|
||||||
|
}
|
||||||
|
|
||||||
|
namespaceId = get_namespace_oid(createIndexStatement->relation->schemaname, false);
|
||||||
|
indexRelationId = get_relname_relid(indexRelationName, namespaceId);
|
||||||
|
if (indexRelationId != InvalidOid)
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE),
|
||||||
|
errmsg("relation \"%s\" already exists", indexRelationName)));
|
||||||
|
}
|
||||||
|
|
||||||
if (createIndexStatement->tableSpace != NULL)
|
if (createIndexStatement->tableSpace != NULL)
|
||||||
{
|
{
|
||||||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
|
|
@ -135,9 +135,7 @@ ERROR: creating unique indexes on append-partitioned tables is currently unsupp
|
||||||
-- Verify that we error out in case of postgres errors on supported statement
|
-- Verify that we error out in case of postgres errors on supported statement
|
||||||
-- types.
|
-- types.
|
||||||
CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey);
|
CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey);
|
||||||
WARNING: could not receive query results from localhost:57638
|
ERROR: relation "lineitem_orderkey_index" already exists
|
||||||
DETAIL: Client error: relation "lineitem_orderkey_index_102014" already exists
|
|
||||||
ERROR: could not execute DDL command on worker node shards
|
|
||||||
CREATE INDEX try_index ON lineitem USING gist (l_orderkey);
|
CREATE INDEX try_index ON lineitem USING gist (l_orderkey);
|
||||||
WARNING: could not receive query results from localhost:57638
|
WARNING: could not receive query results from localhost:57638
|
||||||
DETAIL: Client error: data type bigint has no default operator class for access method "gist"
|
DETAIL: Client error: data type bigint has no default operator class for access method "gist"
|
||||||
|
@ -146,6 +144,8 @@ CREATE INDEX try_index ON lineitem (non_existent_column);
|
||||||
WARNING: could not receive query results from localhost:57638
|
WARNING: could not receive query results from localhost:57638
|
||||||
DETAIL: Client error: column "non_existent_column" does not exist
|
DETAIL: Client error: column "non_existent_column" does not exist
|
||||||
ERROR: could not execute DDL command on worker node shards
|
ERROR: could not execute DDL command on worker node shards
|
||||||
|
CREATE INDEX ON lineitem (l_orderkey);
|
||||||
|
ERROR: creating index without a name on a distributed table is currently unsupported
|
||||||
-- Verify that none of failed indexes got created on the master node
|
-- Verify that none of failed indexes got created on the master node
|
||||||
SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname;
|
SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname;
|
||||||
schemaname | tablename | indexname | tablespace | indexdef
|
schemaname | tablename | indexname | tablespace | indexdef
|
||||||
|
|
|
@ -73,6 +73,7 @@ CREATE UNIQUE INDEX try_unique_append_index_a_b ON index_test_append(a,b);
|
||||||
CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey);
|
CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey);
|
||||||
CREATE INDEX try_index ON lineitem USING gist (l_orderkey);
|
CREATE INDEX try_index ON lineitem USING gist (l_orderkey);
|
||||||
CREATE INDEX try_index ON lineitem (non_existent_column);
|
CREATE INDEX try_index ON lineitem (non_existent_column);
|
||||||
|
CREATE INDEX ON lineitem (l_orderkey);
|
||||||
|
|
||||||
-- Verify that none of failed indexes got created on the master node
|
-- Verify that none of failed indexes got created on the master node
|
||||||
SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname;
|
SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname;
|
||||||
|
|
Loading…
Reference in New Issue