citusdata / citusdata/citus

Using pg_partman with inherited FK from template raises error

Open
#2,064 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

We use template table for FKs inheritance. Citus raises an error when pg_partman tries to copy FKs to partition.

Steps to reproduce:

```
CREATE SCHEMA IF NOT EXISTS partman;
CREATE EXTENSION IF NOT EXISTS pg_partman SCHEMA partman;

DROP TABLE IF EXISTS public.events CASCADE ;
DROP TABLE IF EXISTS public.tenants CASCADE ;
DROP TABLE IF EXISTS public.events_template CASCADE ;

DELETE FROM partman.part_config WHERE parent_table = 'public.events';

CREATE TABLE tenants (
id UUID
);
ALTER TABLE tenants ADD PRIMARY KEY (id);

CREATE TABLE events (
id UUID,
tenant_id UUID,
created_at TIMESTAMP
) PARTITION BY RANGE (created_at);

CREATE TABLE events_template (
id UUID,
tenant_id UUID,
created_at TIMESTAMP
);

ALTER TABLE events_template ADD CONSTRAINT events_template_tenants_fk FOREIGN KEY (tenant_id) REFERENCES tenants (id);

SELECT create_distributed_table('tenants', 'id');
SELECT create_distributed_table('events', 'tenant_id');

SELECT partman.create_parent('public.events', 'created_at', 'native', 'weekly', null, 1, 'on', null, true, 'none', '', true, 'public.events_template');
```

> [2018-03-21 15:07:39] [P0001] ERROR: relation events_p2018w11 is not distributed
> [2018-03-21 15:07:39] CONTEXT: SQL statement "SELECT fk."tenant_id" FROM ONLY "public"."events_p2018w11" fk LEFT OUTER JOIN ONLY "public"."tenants" pk ON ( pk."id" OPERATOR(pg_catalog.=) fk."tenant_id") WHERE pk."id" IS NULL AND (fk."tenant_id" IS NOT NULL)"
> [2018-03-21 15:07:39] SQL statement "ALTER TABLE public.events_p2018w11 ADD FOREIGN KEY (tenant_id) REFERENCES public.tenants(id)"
> [2018-03-21 15:07:39] PL/pgSQL function inherit_template_properties(text,text,text) line 112 at EXECUTE
> [2018-03-21 15:07:39] SQL statement "SELECT partman.inherit_template_properties(p_parent_table, v_parent_schema, v_partition_name)"
> [2018-03-21 15:07:39] PL/pgSQL function create_partition_time(text,timestamp with time zone[],boolean,boolean) line 213 at PERFORM
> [2018-03-21 15:07:39] PL/pgSQL function

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.