mirror of https://github.com/citusdata/citus.git
improve citus_shards
parent
cc587101ed
commit
d1a1ad0147
|
@ -15,23 +15,23 @@ SELECT
|
||||||
CASE
|
CASE
|
||||||
WHEN NOT pg_dist_shard.needsseparatenode THEN false
|
WHEN NOT pg_dist_shard.needsseparatenode THEN false
|
||||||
ELSE
|
ELSE
|
||||||
-- has_separate_node = true if the node doesn't have any other shards except the ones that are colocated with this shard
|
-- has_separate_node = true if the node doesn't have any other shard
|
||||||
|
-- placements except the ones that belong to the same shard group.
|
||||||
NOT EXISTS (
|
NOT EXISTS (
|
||||||
-- get all the distributed table shards that are placed on the same node as this shard
|
SELECT 1
|
||||||
SELECT pds1.shardid
|
|
||||||
FROM pg_dist_shard pds1
|
FROM pg_dist_shard pds1
|
||||||
JOIN pg_dist_placement pdp1 USING (shardid)
|
JOIN pg_dist_placement pdp1 USING (shardid)
|
||||||
JOIN pg_dist_partition pdp2 USING (logicalrelid)
|
JOIN pg_dist_partition pdp2 USING (logicalrelid)
|
||||||
WHERE pdp1.groupid = pg_dist_placement.groupid AND
|
WHERE
|
||||||
(pdp2.partkey IS NOT NULL OR (pdp2.repmodel != 't' AND pdp2.colocationid != 0))
|
-- get the distributed table placements that are placed on the same node as this placement
|
||||||
EXCEPT
|
pdp1.groupid = pg_dist_placement.groupid AND
|
||||||
-- get all the shards that are colocated with this shard
|
(pdp2.partkey IS NOT NULL OR (pdp2.repmodel != 't' AND pdp2.colocationid != 0)) AND
|
||||||
SELECT pds1.shardid
|
-- filter out all the placements that belong to the same shard group
|
||||||
FROM pg_dist_shard pds1
|
NOT (
|
||||||
JOIN pg_dist_partition pdp1 USING (logicalrelid)
|
pdp2.colocationid = pg_dist_partition.colocationid AND
|
||||||
WHERE pdp1.colocationid = pg_dist_partition.colocationid AND
|
|
||||||
((pds1.shardminvalue IS NULL AND pg_dist_shard.shardminvalue IS NULL) OR (pds1.shardminvalue = pg_dist_shard.shardminvalue))
|
((pds1.shardminvalue IS NULL AND pg_dist_shard.shardminvalue IS NULL) OR (pds1.shardminvalue = pg_dist_shard.shardminvalue))
|
||||||
)
|
)
|
||||||
|
)
|
||||||
END AS has_separate_node
|
END AS has_separate_node
|
||||||
FROM
|
FROM
|
||||||
pg_dist_shard
|
pg_dist_shard
|
||||||
|
|
|
@ -15,23 +15,23 @@ SELECT
|
||||||
CASE
|
CASE
|
||||||
WHEN NOT pg_dist_shard.needsseparatenode THEN false
|
WHEN NOT pg_dist_shard.needsseparatenode THEN false
|
||||||
ELSE
|
ELSE
|
||||||
-- has_separate_node = true if the node doesn't have any other shards except the ones that are colocated with this shard
|
-- has_separate_node = true if the node doesn't have any other shard
|
||||||
|
-- placements except the ones that belong to the same shard group.
|
||||||
NOT EXISTS (
|
NOT EXISTS (
|
||||||
-- get all the distributed table shards that are placed on the same node as this shard
|
SELECT 1
|
||||||
SELECT pds1.shardid
|
|
||||||
FROM pg_dist_shard pds1
|
FROM pg_dist_shard pds1
|
||||||
JOIN pg_dist_placement pdp1 USING (shardid)
|
JOIN pg_dist_placement pdp1 USING (shardid)
|
||||||
JOIN pg_dist_partition pdp2 USING (logicalrelid)
|
JOIN pg_dist_partition pdp2 USING (logicalrelid)
|
||||||
WHERE pdp1.groupid = pg_dist_placement.groupid AND
|
WHERE
|
||||||
(pdp2.partkey IS NOT NULL OR (pdp2.repmodel != 't' AND pdp2.colocationid != 0))
|
-- get the distributed table placements that are placed on the same node as this placement
|
||||||
EXCEPT
|
pdp1.groupid = pg_dist_placement.groupid AND
|
||||||
-- get all the shards that are colocated with this shard
|
(pdp2.partkey IS NOT NULL OR (pdp2.repmodel != 't' AND pdp2.colocationid != 0)) AND
|
||||||
SELECT pds1.shardid
|
-- filter out all the placements that belong to the same shard group
|
||||||
FROM pg_dist_shard pds1
|
NOT (
|
||||||
JOIN pg_dist_partition pdp1 USING (logicalrelid)
|
pdp2.colocationid = pg_dist_partition.colocationid AND
|
||||||
WHERE pdp1.colocationid = pg_dist_partition.colocationid AND
|
|
||||||
((pds1.shardminvalue IS NULL AND pg_dist_shard.shardminvalue IS NULL) OR (pds1.shardminvalue = pg_dist_shard.shardminvalue))
|
((pds1.shardminvalue IS NULL AND pg_dist_shard.shardminvalue IS NULL) OR (pds1.shardminvalue = pg_dist_shard.shardminvalue))
|
||||||
)
|
)
|
||||||
|
)
|
||||||
END AS has_separate_node
|
END AS has_separate_node
|
||||||
FROM
|
FROM
|
||||||
pg_dist_shard
|
pg_dist_shard
|
||||||
|
|
Loading…
Reference in New Issue