Skip to content

Instantly share code, notes, and snippets.

View amitlan's full-sized avatar

Amit Langote amitlan

View GitHub Profile
### Keybase proof
I hereby claim:
* I am amitlan on github.
* I am amitlan (https://keybase.io/amitlan) on keybase.
* I have a public key ASBrTN93IP7G3arOBGHIzS9R-5j8ZUfwzLLOscE-mmEnGgo
To claim this, I am signing this object:
@amitlan
amitlan / pgconf.asia-unconf-RI-trigger-efficiency.md
Last active December 10, 2018 03:58
RI trigger efficiency

Improve RI trigger efficiency with transition tables (Corey Huinker)

Common approach in DW environments it to disable constraints before loading and validate later. Disabling is a workaround for inefficient constraint checking which occurs per-row, per-constraint. Transition tables in PG 10 for statement level triggers are promising to implementing those checks more efficiently, but benchmarks shown initially were a bit artificial. Corey is considering making RI checking efficient with statement-level triggers based on transition tables. Discussion on which offending rows are shown in the error message. Possibility of a feature to ignore failed rows and store failing rows in a separate "rejection" table. It seems it makes sense to make a PoC patch as the approach seems promising and figure out the details later, including whether to allow users to specify whether to use per-row trigger based approach or statement level triggers.

@amitlan
amitlan / pg11-partition-opt.md
Last active April 17, 2024 10:28
PG 11 Partitioning Optimization Features

PostgreSQL 11 release contains features to improve the performance of DML operations on partitioned tables by enhancing the planner and the executor to use partition metadata more effectively. Those features include a new implementation of partition pruning, execution-time partition pruning (also known as dynamic pruning), partition-wise join and aggregation.

Improved partition pruning

Partition pruning is the ability to skip scanning of partitions that would

@amitlan
amitlan / dyn-pruning.md
Last active November 16, 2018 01:14
Dynamic Partition Pruning in PG 11

Following tables are used in the examples below:

create table foo (a int);
insert into foo values (2), (3);

create table p (a int) partition by list (a);
create index on p (a);
create table p1 partition of p for values in (1);
create table p2 partition of p for values in (2);
@amitlan
amitlan / partition-view.md
Last active November 14, 2018 10:31
Viewing partitions in PG 12 with pg_partition_tree and friends
create table p (a int unique, b int) partition by hash (a);
create table p1 partition of p for values with (modulus 2, remainder 0) partition by hash (a);
create table p11 (b int, a int);
alter table p1 attach partition p11 for values with (modulus 1, remainder 0);
create table p2 partition of p for values with (modulus 2, remainder 1);

select  p.*,
        pg_get_expr(relpartbound, relid) as partbound,
        pg_get_partkeydef(relid) as partkey