Hi,

40708acd65 added memory/disk usage to EXPLAIN ANALYZE for Table Function
Scan nodes.  However, when the node is rescanned with changed
parameters, ExecReScanTableFuncScan() calls tuplestore_end(), so the
statistics of the earlier rescans are lost and only those of the final
rescan are reported.

This is the same problem that David reported for Material nodes in [1],
as also mentioned in [2].

For example:

EXPLAIN ANALYZE
SELECT count(*)
FROM (VALUES ((SELECT jsonb_agg(g) FROM generate_series(1, 100000) g)),
             ('[1]'::jsonb)) v(j),
     LATERAL JSON_TABLE(v.j, '$[*]' COLUMNS (x int PATH '$')) jt;

The Table Function Scan node reports the following:

  larger document first:   master Memory 17kB   patched Disk 4096kB
  smaller document first:  master Disk 4096kB   patched Disk 4096kB

Regards,
Tatsuya Kawata

[1]
https://www.postgresql.org/message-id/flat/CAApHDvoa55vcRth05Ozu5be4FawgTH-aCsZ5%3DZ%2B_UXTUzUxdQg%40mail.gmail.com
[2]
https://www.postgresql.org/message-id/CAApHDvoFPyT10sRDY%2BbH1MOwHwWNnBQKR7xgEePDke15-EkMkQ%40mail.gmail.com

Attachment: v1-0001-Use-tuplestore_clear-instead-of-tuplestore_end-in-nodeTableFuncscan.c.patch
Description: Binary data

Reply via email to