|
| 1 | +# De-duplication of B-tree indexes in PostgreSQL 13 |
| 2 | + |
| 3 | +## Run PostgreSQL 13.2 in Docker |
| 4 | +``` |
| 5 | +docker run --name postgres-13 -e POSTGRES_USER=testuser -e POSTGRES_PASSWORD=testpwd -e POSTGRES_DB=testdb -d -p 5432:5432 -v /absolute/path/to/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql postgres:13.2 |
| 6 | +``` |
| 7 | + |
| 8 | +## Run PostgreSQL 12.6 in Docker |
| 9 | +``` |
| 10 | +docker run --name postgres-12 -e POSTGRES_USER=testuser -e POSTGRES_PASSWORD=testpwd -e POSTGRES_DB=testdb -d -p 6432:5432 -v /absolute/path/to/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql postgres:12.6 |
| 11 | +``` |
| 12 | + |
| 13 | +## Run psql from Docker CLI |
| 14 | +``` |
| 15 | +psql -U testuser -d testdb |
| 16 | +``` |
| 17 | + |
| 18 | +## Get indexes size |
| 19 | +```sql |
| 20 | +select |
| 21 | + x.indrelid::regclass as table_name, |
| 22 | + x.indexrelid::regclass as index_name, |
| 23 | + pg_size_pretty(pg_relation_size(x.indexrelid)) as index_size |
| 24 | +from pg_index x |
| 25 | +join pg_stat_all_indexes psai on x.indexrelid = psai.indexrelid and psai.schemaname = 'public' |
| 26 | +order by 1,2; |
| 27 | +``` |
| 28 | + |
| 29 | +### PostgreSQL 12 results |
| 30 | +|table_name | index_name | index_size | percentage |
| 31 | +|-----------|---------------------------|------------|----------- |
| 32 | +|test | test_pkey | 2208 kB | - |
| 33 | +|test | i_test_fld_with_nulls | 3552 kB | - |
| 34 | +|test | i_test_fld_without_nulls | 2456 kB | 30% less |
| 35 | +|test | i_test_mark_with_nulls | 2664 kB | - |
| 36 | +|test | i_test_mark_without_nulls | 1568 kB | 41% less |
| 37 | +|test | i_test_nil_with_nulls | 2224 kB | - |
| 38 | +|test | i_test_nil_without_nulls | 8192 bytes | - |
| 39 | + |
| 40 | +### PostgreSQL 13 results |
| 41 | +|table_name | index_name | index_size | percentage |
| 42 | +|-----------|---------------------------|------------|----------- |
| 43 | +|test | test_pkey | 2208 kB | - |
| 44 | +|test | i_test_fld_with_nulls | 704 kB | - |
| 45 | +|test | i_test_fld_without_nulls | 368 kB | 47% less |
| 46 | +|test | i_test_mark_with_nulls | 696 kB | - |
| 47 | +|test | i_test_mark_without_nulls | 360 kB | 48% less |
| 48 | +|test | i_test_nil_with_nulls | 696 kB | - |
| 49 | +|test | i_test_nil_without_nulls | 8192 bytes | - |
0 commit comments