mirror of https://github.com/citusdata/citus.git
v2?
parent
5c9ca154f9
commit
72401a39b9
16
dist_key.sql
16
dist_key.sql
|
@ -1,4 +1,5 @@
|
|||
-- CREATE VIEW citus_shard_key_candidates AS
|
||||
WITH initial_suggestions AS (
|
||||
WITH fkeys AS (
|
||||
select distinct on (freloid, confkey)
|
||||
c.oid as reloid, cf.oid as freloid,
|
||||
|
@ -28,7 +29,7 @@ WITH fkeys AS (
|
|||
AND c.relkind = 'r' and c.relpersistence = 'p'
|
||||
AND cf.relkind = 'r' and cf.relpersistence = 'p'
|
||||
)
|
||||
select n.nspname as schema_name, c.relname as table_name,
|
||||
select c.oid as table_oid,
|
||||
CASE WHEN pkeys.attname IS NULL THEN 'reference' ELSE 'distributed' END AS citus_table_type,
|
||||
pkeys.attname as distribution_key,
|
||||
CASE
|
||||
|
@ -67,6 +68,13 @@ select n.nspname as schema_name, c.relname as table_name,
|
|||
and d.deptype = 'e'
|
||||
)
|
||||
and not exists (select 1 from pg_dist_partition where logicalrelid = c.oid)
|
||||
group by 1,2,3,4
|
||||
order by citus_table_type, n.nspname, c.relname;
|
||||
|
||||
group by 1,2,3
|
||||
order by citus_table_type, c.oid
|
||||
)
|
||||
SELECT conrelid, confrelid
|
||||
FROM initial_suggestions t1
|
||||
JOIN pg_constraint ON (conrelid = t1.table_oid)
|
||||
WHERE confrelid != 0 AND
|
||||
-- find illegal conditions
|
||||
t1.citus_table_type = 'reference' AND
|
||||
EXISTS (SELECT 1 FROM initial_suggestions t2 WHERE t2.citus_table_type = 'distributed' AND t2.table_oid = confrelid);
|
||||
|
|
Loading…
Reference in New Issue