-
Notifications
You must be signed in to change notification settings - Fork 0
Description
--- As of 2026-02-04T11:30:19.000Z ---
The discussion focuses on adding expression support to pg_restore_extended_stats() function. Michael Paquier analyzed how PostgreSQL's ANALYZE computes and stores expression statistics, discovering that serialize_expr_stats() can skip inserting pg_statistic tuples for expressions with invalid data, storing NULL values instead. This means the restore function must handle variable numbers of valid expressions flexibly.
Corey Huinker initially worried about misalignment between expressions and their statistics when some are missing, but Michael clarified that accumArrayResult() always maintains array length equal to expression count by inserting NULLs for invalid entries. They agreed the restore function should accept JSON arrays with NULL elements representing missing expression statistics, maintaining positional correspondence.
The current patch incorrectly assumes all expressions have valid statistics and creates tuples for empty objects. Michael suggested allowing NULLs in the JSON array and using accumArrayResult() with disnull=true for consistency with backend behavior. Corey agreed to implement this approach and add tests for leading/trailing missing expressions.
Additional issues discussed include improving error messages with expression context and cleaning up the patch, which Michael noted contains formatting problems, inappropriate warning message changes, and unclear comments requiring resolution before acceptance.
讨论重点是为 pg_restore_extended_stats() 函数添加表达式支持。Michael Paquier 分析了 PostgreSQL 的 ANALYZE 如何计算和存储表达式统计信息,发现 serialize_expr_stats() 可以跳过为无效数据的表达式插入 pg_statistic 元组,转而存储 NULL 值。这意味着恢复函数必须灵活处理可变数量的有效表达式。
Corey Huinker 最初担心当某些表达式缺失时,表达式与其统计信息之间会出现错位,但 Michael 澄清了 accumArrayResult() 总是通过为无效条目插入 NULL 来保持数组长度等于表达式计数。他们同意恢复函数应该接受包含 NULL 元素的 JSON 数组来表示缺失的表达式统计信息,保持位置对应关系。
当前补丁错误地假设所有表达式都有有效统计信息,并为空对象创建元组。Michael 建议允许 JSON 数组中包含 NULL,并使用带有 disnull=true 的 accumArrayResult() 以与后端行为保持一致。Corey 同意实现这种方法并添加针对前导/尾随缺失表达式的测试。
讨论的其他问题包括通过表达式上下文改进错误消息以及清理补丁,Michael 指出补丁包含格式问题、不当的警告消息更改和需要在接受前解决的不清楚注释。
participants - 参与者: