Re: Make tuple deformation faster

Alexander Lakhin <exclusion@gmail.com>

From: Alexander Lakhin <exclusion@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>, Andres Freund <andres@anarazel.de>
Cc: Victor Yegorov <vyegorov@gmail.com>, Matthias van de Meent <boekewurm+postgres@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-23T13:00:00Z
Lists: pgsql-hackers
Hello David,

20.12.2024 12:31, David Rowley wrote:
> The attcacheoff removal is now pushed. I've attached the two remaining patches.

Please look at the following query, which triggers (sometimes not on a
first run) an assert added with 5983a4cff:
regression=# SELECT COUNT(*) FROM
(SELECT (aclexplode(proacl)).* FROM pg_proc) a,
(SELECT oid FROM pg_proc UNION ALL SELECT oid FROM pg_proc) b;
  count
--------
  520366
(1 row)

regression=# SELECT COUNT(*) FROM
(SELECT (aclexplode(proacl)).* FROM pg_proc) a,
(SELECT oid FROM pg_proc UNION ALL SELECT oid FROM pg_proc) b;
WARNING:  terminating connection because of crash of another server process
...
TRAP: failed Assert("memcmp(&snapshot, cattr, sizeof(CompactAttribute)) == 0"), File: 
"../../../../src/include/access/tupdesc.h", Line: 191, PID: 1302048
ExceptionalCondition at assert.c:52:13
TupleDescCompactAttr at tupdesc.h:195:1
nocachegetattr at heaptuple.c:668:8
fastgetattr at htup_details.h:768:11
heap_getattr at htup_details.h:804:11
ExecEvalFieldSelect at execExprInterp.c:3623:17
ExecInterpExpr at execExprInterp.c:1542:4
MemoryContextSwitchTo at palloc.h:128:23
  (inlined by) ExecEvalExprSwitchContext at executor.h:370:2
ExecProject at executor.h:409:18
ExecResult at nodeResult.c:139:1
ExecProcNode at executor.h:273:1
SubqueryNext at nodeSubqueryscan.c:61:1
ExecScanFetch at execScan.c:131:10
ExecScan at execScan.c:197:10
ExecSubqueryScan at nodeSubqueryscan.c:90:1
ExecProcNode at executor.h:273:1
ExecMaterial at nodeMaterial.c:134:15
ExecProcNode at executor.h:273:1
ExecNestLoop at nodeNestloop.c:160:29
ExecProcNode at executor.h:273:1
fetch_input_tuple at nodeAgg.c:561:10
agg_retrieve_direct at nodeAgg.c:2459:18
...
LaunchMissingBackgroundProcesses at postmaster.c:3220:1

(I've discovered this with SQLsmith.)

Best regards,
Alexander

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix possible Assert failure in verify_compact_attribute()

  2. Speedup tuple deformation with additional function inlining

  3. Fix race condition in TupleDescCompactAttr assert code

  4. Optimize alignment calculations in tuple form/deform

  5. Remove pg_attribute.attcacheoff column

  6. Introduce CompactAttribute array in TupleDesc, take 2

  7. Introduce CompactAttribute array in TupleDesc

  8. Use TupleDescAttr macro consistently