From d695deae166c16a4c94d300a913470a68d96c2d6 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Wed, 20 Oct 2021 17:02:24 +0200 Subject: [PATCH] Support operator class parameters in indexes (cherry picked from commit defb97b7f50b0f6da3e4225e5893220784f122a2) --- .../distributed/deparser/citus_ruleutils.c | 23 ++++++++----------- src/test/regress/expected/pg13.out | 3 +-- src/test/regress/sql/pg13.sql | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/backend/distributed/deparser/citus_ruleutils.c b/src/backend/distributed/deparser/citus_ruleutils.c index 5ad05fc82..07982d029 100644 --- a/src/backend/distributed/deparser/citus_ruleutils.c +++ b/src/backend/distributed/deparser/citus_ruleutils.c @@ -756,10 +756,15 @@ deparse_shard_index_statement(IndexStmt *origStmt, Oid distrelid, int64 shardid, { appendStringInfoString(buffer, "INCLUDE ("); deparse_index_columns(buffer, indexStmt->indexIncludingParams, deparseContext); - appendStringInfoChar(buffer, ')'); + appendStringInfoString(buffer, ") "); } - AppendStorageParametersToString(buffer, indexStmt->options); + if (indexStmt->options != NIL) + { + appendStringInfoString(buffer, "WITH ("); + AppendStorageParametersToString(buffer, indexStmt->options); + appendStringInfoString(buffer, ") "); + } if (indexStmt->whereClause != NULL) { @@ -958,8 +963,9 @@ deparse_index_columns(StringInfo buffer, List *indexParameterList, List *deparse /* Commit on postgres: 911e70207703799605f5a0e8aad9f06cff067c63*/ if (indexElement->opclassopts != NIL) { - ereport(ERROR, errmsg( - "citus currently doesn't support operator class parameters in indexes")); + appendStringInfoString(buffer, "("); + AppendStorageParametersToString(buffer, indexElement->opclassopts); + appendStringInfoString(buffer, ") "); } #endif @@ -1091,13 +1097,6 @@ AppendStorageParametersToString(StringInfo stringBuffer, List *optionList) ListCell *optionCell = NULL; bool firstOptionPrinted = false; - if (optionList == NIL) - { - return; - } - - appendStringInfo(stringBuffer, " WITH ("); - foreach(optionCell, optionList) { DefElem *option = (DefElem *) lfirst(optionCell); @@ -1114,8 +1113,6 @@ AppendStorageParametersToString(StringInfo stringBuffer, List *optionList) quote_identifier(optionName), quote_literal_cstr(optionValue)); } - - appendStringInfo(stringBuffer, ")"); } diff --git a/src/test/regress/expected/pg13.out b/src/test/regress/expected/pg13.out index 01a93afe0..7e91e3d2a 100644 --- a/src/test/regress/expected/pg13.out +++ b/src/test/regress/expected/pg13.out @@ -169,9 +169,8 @@ SELECT create_distributed_table('test_table', 'a'); (1 row) --- we currently don't support this +-- operator class options are supported CREATE INDEX test_table_index ON test_table USING gist (b tsvector_ops(siglen = 100)); -ERROR: citus currently doesn't support operator class parameters in indexes -- testing WAL CREATE TABLE test_wal(a int, b int); -- test WAL without ANALYZE, this should raise an error diff --git a/src/test/regress/sql/pg13.sql b/src/test/regress/sql/pg13.sql index 8c1e1b771..e33751b89 100644 --- a/src/test/regress/sql/pg13.sql +++ b/src/test/regress/sql/pg13.sql @@ -94,7 +94,7 @@ SELECT create_distributed_table('my_table', 'a'); CREATE TABLE test_table(a int, b tsvector); SELECT create_distributed_table('test_table', 'a'); --- we currently don't support this +-- operator class options are supported CREATE INDEX test_table_index ON test_table USING gist (b tsvector_ops(siglen = 100)); -- testing WAL