Repository navigation
v2.1.1 - Fix "cannot start commands during a parallel operation"
π Version 2.1.1
π Fixes:
PARALLEL UNSAFEdeclarations:nanoid()andnanoid_optimized()are now declaredPARALLEL UNSAFEinstead ofPARALLEL 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 raisedcannot start commands during a parallel operationin parallel query contexts (for exampleCREATE TABLE ... AS SELECT nanoid() FROM ...on PostgreSQL 11+, or parallelizedINSERT ... SELECTon AlloyDB).PARALLEL RESTRICTEDwas 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.shinstallsnanoid.sqlinto 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 indev/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
PARALLELclause used since v2.0.0 requires it) and documented how to run the test suite. LEAKPROOFnow also disabled by default onnanoid_optimized(): v2.1.0 only changed the default fornanoid(); this release comments out the attribute onnanoid_optimized()as well (#11). Uncomment theLEAKPROOFline innanoid.sqlif 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