-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Labels
Description
The before-insert trigger in Postgres is something like:
IF NOT EXISTS(
SELECT 1 FROM information_schema.tables WHERE table_name=tablename)
THEN
BEGIN
EXECUTE 'CREATE TABLE ' || tablename || ' (
CHECK (' || checks || '),
LIKE "{{parent_table}}" INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES
) INHERITS ("{{parent_table}}");';
EXCEPTION WHEN duplicate_table THEN
-- pass
END;
END IF;
And it will check whether table's existense by SELETC 1, then create table if select failed.I tried to replace with CREATE TABLE IF NOT EXIST
BEGIN
EXECUTE 'CREATE TABLE IF NOT EXISTS ' || tablename || ' (
CHECK (' || checks || '),
LIKE "{{parent_table}}" INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES
) INHERITS ("{{parent_table}}");';
EXCEPTION WHEN duplicate_table THEN
-- pass
END;
In my case, it will speed up insert action about 25% (I really care about the decrease of insert action's speed). But I doubt that it is too special, so I open this issue to discuss about it. Thanks!