v6-0002-Add-invariants-check-to-get_useful_group_keys_ord.patch
application/octet-stream
Filename: v6-0002-Add-invariants-check-to-get_useful_group_keys_ord.patch
Type: application/octet-stream
Part: 0
Message:
Re: POC: GROUP BY optimization
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v6-0002
Subject: Add invariants check to get_useful_group_keys_orderings()
| File | + | − |
|---|---|---|
| src/backend/optimizer/path/pathkeys.c | 28 | 0 |
From ad53192551dc043b2c43ff09c2097173fa6a5a9b Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Thu, 30 May 2024 22:38:53 +0300
Subject: [PATCH v6 2/5] Add invariants check to
get_useful_group_keys_orderings()
This commit introduces invariants checking of generated orderings
in get_useful_group_keys_orderings for assert-enabled builds.
Discussion: https://postgr.es/m/a663f0f6-cbf6-49aa-af2e-234dc6768a07%40postgrespro.ru
Reported-by: Tom Lane
Author: Andrei Lepikhov
Reviewed-by: Alexander Korotkov, Pavel Borisov
---
src/backend/optimizer/path/pathkeys.c | 28 +++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index df966b18f34..02e46a6eaaf 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -561,6 +561,34 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
}
}
+#ifdef USE_ASSERT_CHECKING
+ {
+ PathKeyInfo *pinfo = linitial_node(PathKeyInfo, infos);
+ ListCell *lc;
+
+ /* Test consistency of info structures */
+ for_each_from(lc, infos, 1)
+ {
+ ListCell *lc1,
+ *lc2;
+
+ info = lfirst_node(PathKeyInfo, lc);
+
+ Assert(list_length(info->clauses) == list_length(pinfo->clauses));
+ Assert(list_length(info->pathkeys) == list_length(pinfo->pathkeys));
+ Assert(list_difference(info->clauses, pinfo->clauses) == NIL);
+ Assert(list_difference_ptr(info->pathkeys, pinfo->pathkeys) == NIL);
+
+ forboth(lc1, info->clauses, lc2, info->pathkeys)
+ {
+ SortGroupClause *sgc = lfirst_node(SortGroupClause, lc1);
+ PathKey *pk = lfirst_node(PathKey, lc2);
+
+ Assert(pk->pk_eclass->ec_sortref == sgc->tleSortGroupRef);
+ }
+ }
+ }
+#endif
return infos;
}
--
2.39.3 (Apple Git-145)