mirror of https://github.com/citusdata/citus.git
Properly handle index storage options for ADD CONSTRAINT / COLUMN
parent
ae142e1764
commit
6365f47b57
|
@ -11,6 +11,7 @@
|
||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "commands/defrem.h"
|
||||||
#include "distributed/commands.h"
|
#include "distributed/commands.h"
|
||||||
#include "distributed/deparser.h"
|
#include "distributed/deparser.h"
|
||||||
#include "distributed/version_compat.h"
|
#include "distributed/version_compat.h"
|
||||||
|
@ -205,6 +206,23 @@ AppendAlterTableCmdConstraint(StringInfo buf, Constraint *constraint,
|
||||||
|
|
||||||
AppendColumnNameList(buf, constraint->including);
|
AppendColumnNameList(buf, constraint->including);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (constraint->options != NIL)
|
||||||
|
{
|
||||||
|
appendStringInfoString(buf, " WITH(");
|
||||||
|
|
||||||
|
ListCell *defListCell;
|
||||||
|
foreach(defListCell, constraint->options)
|
||||||
|
{
|
||||||
|
DefElem *def = (DefElem *) lfirst(defListCell);
|
||||||
|
|
||||||
|
bool first = (defListCell == list_head(constraint->options));
|
||||||
|
appendStringInfo(buf, "%s%s=%s", first ? "" : ",",
|
||||||
|
def->defname, defGetString(def));
|
||||||
|
}
|
||||||
|
|
||||||
|
appendStringInfoChar(buf, ')');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (constraint->contype == CONSTR_EXCLUSION)
|
else if (constraint->contype == CONSTR_EXCLUSION)
|
||||||
{
|
{
|
||||||
|
|
|
@ -671,6 +671,27 @@ SELECT create_distributed_table('alter_add_unique', 'x');
|
||||||
ALTER TABLE alter_add_unique ADD CONSTRAINT unique_constraint_test UNIQUE USING INDEX alter_unique_idx;
|
ALTER TABLE alter_add_unique ADD CONSTRAINT unique_constraint_test UNIQUE USING INDEX alter_unique_idx;
|
||||||
NOTICE: ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index "alter_unique_idx" to "unique_constraint_test"
|
NOTICE: ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index "alter_unique_idx" to "unique_constraint_test"
|
||||||
ALTER TABLE alter_add_unique DROP CONSTRAINT unique_constraint_test;
|
ALTER TABLE alter_add_unique DROP CONSTRAINT unique_constraint_test;
|
||||||
|
CREATE TABLE unique_test_table_single_shard(id int, name varchar(20));
|
||||||
|
SELECT create_distributed_table('unique_test_table_single_shard', 'id', shard_count=>1);
|
||||||
|
create_distributed_table
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
ALTER TABLE unique_test_table_single_shard ADD UNIQUE(id, name) WITH (fillfactor=20);
|
||||||
|
SELECT (groupid = 0) AS is_coordinator, result FROM run_command_on_all_nodes(
|
||||||
|
$$SELECT get_index_defs FROM get_index_defs('sc3', 'unique_test_table_single_shard')$$
|
||||||
|
)
|
||||||
|
JOIN pg_dist_node USING (nodeid)
|
||||||
|
ORDER BY is_coordinator DESC, result;
|
||||||
|
is_coordinator | result
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
t | [{"indexdefs": ["CREATE UNIQUE INDEX unique_test_table_single_shard_id_name_key ON sc3.unique_test_table_single_shard USING btree (id, name) WITH (fillfactor='20')"], "indexnames": ["unique_test_table_single_shard_id_name_key"]}]
|
||||||
|
f | [{"indexdefs": ["CREATE UNIQUE INDEX unique_test_table_single_shard_id_name_key ON sc3.unique_test_table_single_shard USING btree (id, name) WITH (fillfactor='20')", "CREATE UNIQUE INDEX unique_test_table_single_shard_id_name_key_1450242 ON sc3.unique_test_table_single_shard_1450242 USING btree (id, name) WITH (fillfactor='20')"], "indexnames": ["unique_test_table_single_shard_id_name_key", "unique_test_table_single_shard_id_name_key_1450242"]}]
|
||||||
|
f | [{"indexdefs": ["CREATE UNIQUE INDEX unique_test_table_single_shard_id_name_key ON sc3.unique_test_table_single_shard USING btree (id, name) WITH (fillfactor='20')", "CREATE UNIQUE INDEX unique_test_table_single_shard_id_name_key_1450242 ON sc3.unique_test_table_single_shard_1450242 USING btree (id, name) WITH (fillfactor='20')"], "indexnames": ["unique_test_table_single_shard_id_name_key", "unique_test_table_single_shard_id_name_key_1450242"]}]
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
|
DROP TABLE unique_test_table_single_shard;
|
||||||
SET search_path TO 'public';
|
SET search_path TO 'public';
|
||||||
DROP SCHEMA sc1 CASCADE;
|
DROP SCHEMA sc1 CASCADE;
|
||||||
NOTICE: drop cascades to table sc1.alter_add_prim_key
|
NOTICE: drop cascades to table sc1.alter_add_prim_key
|
||||||
|
|
|
@ -563,6 +563,19 @@ SELECT create_distributed_table('alter_add_unique', 'x');
|
||||||
ALTER TABLE alter_add_unique ADD CONSTRAINT unique_constraint_test UNIQUE USING INDEX alter_unique_idx;
|
ALTER TABLE alter_add_unique ADD CONSTRAINT unique_constraint_test UNIQUE USING INDEX alter_unique_idx;
|
||||||
ALTER TABLE alter_add_unique DROP CONSTRAINT unique_constraint_test;
|
ALTER TABLE alter_add_unique DROP CONSTRAINT unique_constraint_test;
|
||||||
|
|
||||||
|
CREATE TABLE unique_test_table_single_shard(id int, name varchar(20));
|
||||||
|
SELECT create_distributed_table('unique_test_table_single_shard', 'id', shard_count=>1);
|
||||||
|
|
||||||
|
ALTER TABLE unique_test_table_single_shard ADD UNIQUE(id, name) WITH (fillfactor=20);
|
||||||
|
|
||||||
|
SELECT (groupid = 0) AS is_coordinator, result FROM run_command_on_all_nodes(
|
||||||
|
$$SELECT get_index_defs FROM get_index_defs('sc3', 'unique_test_table_single_shard')$$
|
||||||
|
)
|
||||||
|
JOIN pg_dist_node USING (nodeid)
|
||||||
|
ORDER BY is_coordinator DESC, result;
|
||||||
|
|
||||||
|
DROP TABLE unique_test_table_single_shard;
|
||||||
|
|
||||||
SET search_path TO 'public';
|
SET search_path TO 'public';
|
||||||
|
|
||||||
DROP SCHEMA sc1 CASCADE;
|
DROP SCHEMA sc1 CASCADE;
|
||||||
|
|
Loading…
Reference in New Issue