Skip to content

pg_sift 5.1.0

Latest

Choose a tag to compare

@github-actions github-actions released this 20 Nov 07:39
· 1 commit to main since this release

pg_sift 5.1.0: a directory that is no longer limited to 128 segments, builds that read the cheapest source of rows (a btree in key order, or the index a REINDEX replaces) instead of always the heap and its temporary files, one deletion record per unit between a DELETE and the fold, reads of a write buffer and of a key_cut index that open only what can hold the keys, and a smaller default cache for each backend. Update the library and run ALTER EXTENSION pg_sift UPDATE; no REINDEX is needed, and indexes of 5.0 are read as they are.

What 5.1 changes for you

Nothing is rebuilt: an index of 5.0 keeps its files and its answers, and a query keeps PostgreSQL's plan unless an index proves it can answer the same rows. docs/UPGRADING.md has the steps in full.

To upgrade from 5.0 (any patch release)

  1. Run the preflight of the 5.1 files before the update (scripts/upgrade-check.sh, or pg_sift_upgrade_check.sql, installed with the extension files). Each row is an index or setting to deal with, with its command. Nothing blocks an update from 5.0: the blockers it lists are only for going back (sift.upgrade_check('5.0')).
  2. Install the files and restart the server (a standby too: a 5.0 standby refuses an index that a 5.1 primary has written in the formats below, and reads the others), then ALTER EXTENSION pg_sift UPDATE in each database. The script replaces sift.upgrade_check and changes no other object; the library runs without it.
  3. The first write that needs one of three formats writes it: a statement that deletes many rows of an index with track_changes (deletion records, column format minor 52), the first write buffer of an integer key_cut index (key ranges in its pages, column format minor 55, which raises the metapage to 1.7) and a directory that outgrows one page (a chain of pages, metapage 1.7). A 5.0 library refuses such an index with the format error and the REINDEX hint, never as damage.
  4. To go back to 5.0: SELECT * FROM sift.upgrade_check('5.0') lists the indexes to rewrite. VACUUM the table (the deletion records are folded into the liveness and dropped), run ALTER EXTENSION pg_sift UPDATE TO '5.0' if you ran the update, stop the server, install the 5.0 files, start it and REINDEX each index listed: a REINDEX under 5.1 can write them again (a key_cut index records its partitions, a chained directory, at its first rewrite).

To adopt what 5.1 builds an index of 5.0 needs a REINDEX: it takes its rows from the cheapest source, writes its partitions into the directory and stamps the buffers with key ranges. Without it the index keeps working as it was; the key ranges of the buffer apply to the indexes that 5.1 builds, and an index of 5.0 with a key_cut records its partitions at its first maintenance step (one directory update that writes no segment, after which 5.0 refuses it).

Highlights

  • A directory of any size. The directory of an index is a chain of pages that an update writes first and flips to in one record, up to 32,768 entries, where it was one page of 128. A build or merge cuts a segment when its writer holds its share of maintenance_work_mem, however many segments that makes, and the writer holds the same bytes for 16,000 rows as for 132,000. The partitions of a key_cut index are leaves of the directory, named by a lineage that a rewrite keeps; sift.col_verify checks that the rows of every segment lie within the bounds of its partition. An index whose directory outgrows one page stays a chain (no path leads back), and a 5.0 library refuses it with the format error.
  • Builds choose their source of rows. CREATE INDEX, REINDEX and CREATE INDEX CONCURRENTLY of a sift_col index price the heap with the columnar files of the key ranges, a btree on the key read in key order and, for REINDEX INDEX, the index it replaces, and take the cheapest; the NOTICE names the source, the temporary bytes, the heap blocks and the predicted cost. On 300,000 rows (3 alternating rounds): heap with files 29.66 G instructions and 4.3 MB of temporary files, btree 17.02 G and none (-43%), the replaced index 8.20 G and no heap block (-72%). SET sift.col_build_source = heap reads the heap as releases before 5.1 did. A build whose key-range files would not fit temp_file_limit takes the btree instead of the error when one serves. With no btree on the key either, it builds the ranges as open units without a temporary file instead of failing.
  • One deletion record per unit. A statement that deletes many rows (at least 64 and 0.5% of the rows) of an index with track_changes writes one record for each unit it touches, in place of a 32-byte mark for each row. On 150,000 rows in 125 units, between the delete and the fold, a filtered scan takes 3.8 million instructions with 1% of the rows deleted (32.0 with marks), 9.6 with 10% (59.1) and 6.3 with 50% (65.1), and an aggregate 2.0, 5.6 and 4.9 million (49.0, 127.2 and 136.4). The statement takes 1.17, 1.08 and 1.09 times the instructions of the same statement with marks, and the fold of 15,000 marks in 125 units takes 58 million instructions where it took 349.
  • A write buffer read by key. Every page of a buffer made by 5.1 says the range of the first key_cut column (an integer), and a statement that asks for keys reads the pages that can hold them: the first statement of a backend with 40,000 buffered rows and an ordered key goes from 94.9 to 5.4 M instructions, and one for a key that is not in the buffer from 108 to 3.4 M. A key that lies in every page gains nothing (+0.3%); an INSERT batch of 2,000 rows costs 0.3% more (sift.col_wbuf_key_range, on by default).
  • Reads that open fewer partitions. An index scan or an aggregate scan whose conditions pin the leading columns of a key_cut opens the segments of the partitions that may hold those keys: a point read of one key on 43 partitions takes 233 instead of 689 thousand instructions and 72 instead of 175 blocks (an index of one partition pays 0.8% more). The directory pages that name them are read for a prefix of the key only: 104 of 1,012 for the first column of 1,000 partitions, 14 for two, 5 for three.
  • Merges that keep a key in one segment. The slices of a merge by workers and the writer of a merge into partitions cut between values of the first key leaf when a value that fits is within an eighth of a slice (12% of a partition), so a key lies in one segment unless it is bigger than that; the rewrite that ends a parallel key_cut build no longer merges the same segments again at every step (a 1,000,000-row index: 80 s and 1.9 GB written before, 1.5 s and 14 MB), and a forced merge that finds its segments already cut as a merge cuts them changes nothing.
  • Memory. sift.backend_cache_kb defaults to 128 MB, not 256 MB: 200 connections keep at most 25 GB in these caches instead of 50 GB, and the shapes matrix reads the same instructions and blocks for lookups of up to 102 MB held together. A merge into many partitions holds the memory of one, and the layout of a key_cut build no longer depends on the statistics of the table.
  • The preflight knows 5.1. sift.upgrade_check('5.0') lists as blockers, with the command, the indexes that 5.0 refuses (a log with deletion records, a buffer with key ranges, a chained directory); sift.col_segments lists the format of a log or a buffer that is one of those.

New and changed settings

  • sift.col_build_source (new). auto (the default) prices the sources of rows of a build and takes the cheapest; heap reads the heap as before 5.1, with no btree walked and no old index opened. No format change: the same rows and units, within 3% of the bytes of the heap build.
  • sift.col_wbuf_key_range (new, superuser). On by default: the pages of a write buffer hold the range of the first integer key_cut column. Off writes buffers of column format minor 51, which a 5.0 library reads; set it off only before a downgrade, or where every key of every statement is in every page of the buffer.
  • sift.backend_cache_kb (default 128 MB, was 256 MB). The total a backend keeps in its caches of parsed dictionaries, segment bytes, joined-table rows and value-store strings; raise it for a few backends that join large tables, lower it for many connections.

Also check

  • A standby follows an update in this order: the standbys first (5.0 and 5.1 files read each other's indexes until a 5.1 primary writes one of the three formats above).
  • A 5.0 index that you REINDEX under 5.1 may be built from a btree on its key or from the index it replaces, with the NOTICE saying which and how to turn it off; the answers and the columns of the index are the same.

Known limits

What 5.1 costs more than 5.0.2, measured in instructions of a single-user backend, so that the gains above are read for what they are:

  • A statement that deletes many rows costs more than in 5.0.2 when the rows are scattered: 1.08 to 1.18 times when they are scattered over the index. When they are all in one range of the key it costs about 1.02 times. Reads between the DELETE and the next VACUUM are cheaper in exchange.
  • The first write after the server starts costs more: about 0.4 million instructions more for an INSERT and 2.5 million (about 0.6 ms) more for an UPDATE than in 5.0.2. It is not paid by every statement or every backend: the cost of the UPDATE is a planner fold over every segment that is done once for each server and set of segments (the backends share it), and the cost of the INSERT is opening the write buffer, once for each buffer. A second backend pays about 0.07 million and 0.01 million instructions more.

Compatibility

  • PostgreSQL 17, 18 and 19; the packages below cover all three (other builds from source with make USE_PGXS=1). A new minor: extension SQL 5.1 (pg_sift--5.0--5.1.sql, which replaces sift.upgrade_check; a 5.0.x extension reaches it through pg_sift--5.0.x--5.0.sql); column format minors 52 and 55 and the metapage minor 1.7 are new, and the library reads every older minor (SIFT_COL_FORMAT_MAX_READ is 55). No BM25 segment format changes; a BM25 index with a chained directory (more than 128 segments) is at metapage 1.7 and is refused by 5.0.
  • docs/FORMATS.md lists each minor with the release that first reads it.

Packages

x86-64 and arm64 packages for PostgreSQL 17, 18 and 19 are attached below (SHA256SUMS covers every asset); other versions build from source with make USE_PGXS=1.

  • Debian 12 and 13, Ubuntu 22.04 and 24.04 (PGDG postgresql-N, N = 17, 18 or 19): sudo apt install ./postgresql-N-pg-sift_5.1.0-1_amd64.deb (_arm64.deb on arm64)
  • RHEL, Rocky, Alma 9 and 10 (PGDG postgresqlN-server): sudo dnf install ./pg_sift_N-5.1.0-1.el9.x86_64.rpm (.aarch64.rpm on arm64)
  • Amazon Linux 2023 (the distribution's postgresqlN-server, N = 17 or 18): sudo dnf install ./pg_sift_N-5.1.0-1.amzn2023.x86_64.rpm (.aarch64.rpm on arm64)
  • Arch Linux: AUR pg_sift.

Every change: CHANGELOG.md.

SQLite extension

pg_sift for SQLite 5.1.0 (sift, a loadable extension; a separate component from the PostgreSQL extension above). Rebuilt with the PostgreSQL 5.1.0 release: no change to the SQL interface or the shared format.

  • No change: the changes of this release are in the PostgreSQL column index, which is not in this extension. No speed-up or slow-down is claimed.
  • Needs SQLite 3.38 or newer; Linux x86-64, glibc 2.34 or newer. Built on Debian 12, loaded into the SQLite of Debian 12, Ubuntu 24.04 and AlmaLinux 10 before release.
  • Storage format 2: tables of 3.4.0 to 3.7.0 open as they are, nothing to rebuild.

Download sift-sqlite-5.1.0-linux-x86_64.tar.gz (below, covered by SHA256SUMS with the packages), unpack it and .load ./sift from the sqlite3
shell (sha256sum --ignore-missing -c SHA256SUMS). Documentation: sqlite/README.md.
Every change: sqlite/CHANGELOG.md.

MariaDB extension

pg_sift for MariaDB 5.1.0 (sift, a UDF library and two SQL files; a separate component from the extensions above). Rebuilt with the PostgreSQL 5.1.0 release: no change to the SQL files.

  • No change: the changes of this release are in the PostgreSQL column index, which is not in this extension. No speed-up or slow-down is claimed.
  • One library per MariaDB series, because it calls the server's own symbols and refuses to load into another series: 10.11, 11.4, 11.8, 12.1 and 13.0; Linux x86-64. Each was built in the stock mariadb:<series> image against that server's headers and loaded into a server of the same image before release. BUILD-INFO in the tarball lists the server version and the glibc each library needs.
  • Index format 2: an index of 3.4.0 to 3.7.0 opens as it is, nothing to rebuild.

Download sift-mariadb-5.1.0-linux-x86_64.tar.gz (below, covered by SHA256SUMS with the packages), unpack it, copy lib/<series>/libsift_udf.so of your server's series
(SELECT VERSION()) into its plugin_dir, then SOURCE sql/functions.sql once per server and sql/sift.sql once per database (sha256sum --ignore-missing -c SHA256SUMS).
Documentation: mariadb/README.md.
Every change: mariadb/CHANGELOG.md.