Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5380e20

Browse files
committed
Foreign tables now prefixed with fdw.
It is easier for copying partitions and generally better.
1 parent 79acf9e commit 5380e20

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

bin/shardman_init.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ psql -p 5433 -c "INSERT INTO partitioned_table SELECT generate_series(1, 1000),
4141
psql -c "select shardman.add_node('port=5433');"
4242
psql -c "select shardman.add_node('port=5434');"
4343

44+
psql -c "select shardman.create_hash_partitions(2, 'partitioned_table', 'id', 2);"
45+
4446
psql

pg_shardman--0.0.1.sql

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ BEGIN
6464
IF NEW.initial_node != (SELECT shardman.get_node_id()) THEN
6565
EXECUTE format ('DROP TABLE IF EXISTS %I CASCADE;', NEW.relation);
6666
EXECUTE format('%s', NEW.create_sql);
67-
-- We are adding '_tmp' to default names, because
68-
-- these partitions will be immediately replaced with foreign tables
69-
-- having conventional names.
7067
EXECUTE format('select create_hash_partitions(%L, %L, %L, true, %L);',
7168
NEW.relation, NEW.expr, NEW.partitions_count,
7269
(SELECT ARRAY(SELECT part_name FROM shardman.gen_part_names(
73-
NEW.relation, NEW.partitions_count, '_tmp'))));
70+
NEW.relation, NEW.partitions_count))));
7471
END IF;
7572
RETURN NULL;
7673
END
@@ -110,6 +107,7 @@ DECLARE
110107
um_opts text default '';
111108
server_opts_first_time_through bool DEFAULT true;
112109
um_opts_first_time_through bool DEFAULT true;
110+
fdw_part_name text;
113111
BEGIN
114112
IF NEW.owner != (SELECT shardman.get_node_id()) THEN
115113
raise info 'creating foreign table';
@@ -163,7 +161,10 @@ BEGIN
163161
NEW.part_name);
164162
EXECUTE format('CREATE USER MAPPING FOR CURRENT_USER SERVER %I
165163
%s;', NEW.part_name, um_opts);
166-
EXECUTE format('DROP FOREIGN TABLE IF EXISTS %I;', NEW.part_name);
164+
-- We use _fdw suffix for foreign tables to avoid interleaving with real
165+
-- ones.
166+
SELECT format('%s_fdw', NEW.part_name) INTO fdw_part_name;
167+
EXECUTE format('DROP FOREIGN TABLE IF EXISTS %I;', fdw_part_name);
167168

168169
-- Generate and execute CREATE FOREIGN TABLE sql statement which will
169170
-- clone the existing local table schema. In constrast to
@@ -176,14 +177,18 @@ BEGIN
176177
-- unneccessary involves network (we already have this schema locally)
177178
-- and dangerous: what if table was created and dropped before this
178179
-- change reached us?
180+
179181
EXECUTE format('CREATE FOREIGN TABLE %I %s SERVER %I',
180-
NEW.part_name,
181-
(select
182-
shardman.reconstruct_table_attrs('partitioned_table_0_tmp')),
182+
fdw_part_name,
183+
(SELECT
184+
shardman.reconstruct_table_attrs(
185+
format('%I', NEW.part_name))),
183186
NEW.part_name);
184187
-- Finally, replace empty local tmp partition with foreign table
185188
EXECUTE format('SELECT replace_hash_partition(%L, %L)',
186-
format('%s_tmp', NEW.part_name), NEW.part_name);
189+
NEW.part_name, fdw_part_name);
190+
-- And drop old empty table
191+
EXECUTE format('DROP TABLE %I', NEW.part_name);
187192
END IF;
188193
RETURN NULL;
189194
END

0 commit comments

Comments
 (0)