From 6569ca43973b754e8213072c8ddcae9e7baf2aaa Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 17 Aug 2022 15:35:51 -0400 Subject: Make PlaceHolderInfo lookup O(1). Up to now we've just searched the placeholder_list when we want to find the PlaceHolderInfo with a given ID. While there's no evidence of that being a problem in the field, an upcoming patch will add find_placeholder_info() calls in build_joinrel_tlist(), which seems likely to make it more of an issue: a joinrel emitting lots of PlaceHolderVars would incur O(N^2) cost, and we might be building a lot of joinrels in complex queries. Hence, add an array that can be indexed directly by phid to make the lookups constant-time. Discussion: https://postgr.es/m/1405792.1660677844@sss.pgh.pa.us --- src/backend/optimizer/util/var.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/backend/optimizer/util/var.c') diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c index ebc6ce84b0b..7db86c39efc 100644 --- a/src/backend/optimizer/util/var.c +++ b/src/backend/optimizer/util/var.c @@ -210,15 +210,8 @@ pull_varnos_walker(Node *node, pull_varnos_context *context) if (phv->phlevelsup == 0) { - ListCell *lc; - - foreach(lc, context->root->placeholder_list) - { - phinfo = (PlaceHolderInfo *) lfirst(lc); - if (phinfo->phid == phv->phid) - break; - phinfo = NULL; - } + if (phv->phid < context->root->placeholder_array_size) + phinfo = context->root->placeholder_array[phv->phid]; } if (phinfo == NULL) { -- cgit v1.2.3