Re: WIP: Faster Expression Processing v4
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andres Freund <andres@anarazel.de>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>, pgsql-hackers@postgresql.org
Date: 2017-03-14T18:28:51Z
Lists: pgsql-hackers
On 03/14/2017 07:31 PM, Andres Freund wrote: > On 2017-03-14 16:58:54 +0200, Heikki Linnakangas wrote: >> * How tight are we on space in the ExprEvalStep union? Currently, the >> jump-threading preparation replaces the opcodes with the goto labels, but it >> would be really nice to keep the original opcodes, for debugging purposes if >> nothing else. > > There's nothing left to spare :(. For debugging I've just used > ExecEvalStepOp() - it's inconvenient to directly print the struct > anyway, since gdb prints the whole union... This comment above the union is not accurate: > /* > * Data for an operation. Inline stored data is faster to access, but also > * bloats the size of all instructions. The union should be kept below 48 > * bytes (so the entire struct is below 64bytes, a single cacheline on > * common systems). > */ On my x86-64 system, the whole struct is 64 bytes, but the union is only 40 bytes. The fields before the union occupy 24 bytes. IOW, the union should be kept below 40 bytes, not 48. Hmm. Could we make the instructions variable size? It would allow packing the small instructions even more tight, and we wouldn't need to obsess over a particular maximum size for more complicated instructions. A compromise might be to have the fixed size, but have "continuation" opcodes for the more complicated instructions. An XmlExpr instruction, for example, could have an extra instruction after the primary one, just to hold more fields. When evaluating it, we would just increment the Program Counter by two instead of one, to skip over the extra instruction. For reference, here are the sizes of all the structs in the union: 40: xmlexpr 40: scalararrayop 40: minmax 40: iocoerce 40: convert_rowtype 32: wholerow 32: rowcompare_step 32: row 32: func 32: fieldstore 32: domaincheck 32: boolexpr 32: arrayexpr 32: arraycoerce 24: casewhen 24: casethen 24: arrayref_checksubscript 16: grouping_func 16: fieldselect 16: constval 16: casetest 16: assign_var 16: arrayref 8: window_func 8: subplan 8: sqlvaluefunction 8: param 8: nulltest_row 8: assign_tmp 8: alternative_subplan 8: aggref 4: var 4: rowcompare_final 4: qualexpr 4: fetch 4: coalesce - Heikki
Commits
-
Improve performance of ExecEvalWholeRowVar.
- 2f0903ea1965 10.0 landed
-
Remove unreachable code in expression evaluation.
- ad46a2aa79f9 10.0 landed
-
Faster expression evaluation and targetlist projection.
- b8d7f053c5c2 10.0 landed
-
Avoid syntax error on platforms that have neither LOCALE_T nor ICU.
- 457a44487328 10.0 cited
-
Add configure test to see if the C compiler has gcc-style computed gotos.
- bc18126a6bcb 10.0 landed
-
Improve regression test coverage for TID scanning.
- be6c3d19fd45 10.0 landed
-
Improve expression evaluation test coverage.
- ce38949ba23a 10.0 landed
-
Fix two errors with nested CASE/WHEN constructs.
- f0c7b789ab12 9.6.0 cited