Skip to content

v2.1.1 - Fix "cannot start commands during a parallel operation"

Choose a tag to compare

@nik-sta nik-sta released this 13 Jul 19:22
· 6 commits to main since this release
Immutable release. Only release title and notes can be modified.

πŸš€ Version 2.1.1

πŸ› Fixes:

  • PARALLEL UNSAFE declarations: nanoid() and nanoid_optimized() are now declared PARALLEL UNSAFE instead of PARALLEL SAFE. PL/pgSQL advances the command counter and takes new snapshots when it evaluates volatile expressions, which is forbidden while a query runs in parallel mode and raised cannot start commands during a parallel operation in parallel query contexts (for example CREATE TABLE ... AS SELECT nanoid() FROM ... on PostgreSQL 11+, or parallelized INSERT ... SELECT on AlloyDB). PARALLEL RESTRICTED was evaluated and rejected because it still fails whenever the leader has already written within the same statement. See #16 and #17 for the full analysis.

βš™ Changes:

  • Multi-version test suite: dev/test/run_tests.sh installs nanoid.sql into the official PostgreSQL Docker images (every major version from 9.6 through 18, latest minor of each) and runs the unit tests plus the new regression tests in dev/test/regression_tests.sql, covering the parallel-query scenarios from #16 and large-size id generation.
  • README: corrected the minimum supported version to PostgreSQL 9.6 (the PARALLEL clause used since v2.0.0 requires it) and documented how to run the test suite.
  • LEAKPROOF now also disabled by default on nanoid_optimized(): v2.1.0 only changed the default for nanoid(); this release comments out the attribute on nanoid_optimized() as well (#11). Uncomment the LEAKPROOF line in nanoid.sql if you rely on it and have superuser privileges.

πŸ“ Migration Guide from nanoid() Version 2.1.0 to 2.1.1:

For an existing database, upgrade in place. This keeps all dependent objects (like column defaults) untouched and needs no superuser rights, just function ownership:

ALTER FUNCTION nanoid(int, text, float) PARALLEL UNSAFE;
ALTER FUNCTION nanoid_optimized(int, text, int, int) PARALLEL UNSAFE;

Re-running nanoid.sql achieves the same for fresh setups. Note that it starts with DROP FUNCTION IF EXISTS, which fails on databases where objects (for example column defaults) depend on the functions; use the ALTER FUNCTION statements above there instead.

Note: Queries referencing these functions will no longer use parallel plans. This is intentional: it is the only marking under which the functions are always correct.


Full Changelog: 2.1.0...2.1.1