agora inbox for [email protected]
help / color / mirror / Atom feed[PATCH v6 1/3] CatCache expiration feature
6+ messages / 4 participants
[nested] [flat]
* [PATCH v6 1/3] CatCache expiration feature
@ 2020-11-18 07:54 Kyotaro Horiguchi <[email protected]>
0 siblings, 0 replies; 6+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-18 07:54 UTC (permalink / raw)
---
src/backend/access/transam/xact.c | 3 ++
src/backend/utils/cache/catcache.c | 87 +++++++++++++++++++++++++++++-
src/backend/utils/misc/guc.c | 12 +++++
src/include/utils/catcache.h | 19 +++++++
4 files changed, 120 insertions(+), 1 deletion(-)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index a2068e3fd4..86888d2409 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -1086,6 +1086,9 @@ static void
AtStart_Cache(void)
{
AcceptInvalidationMessages();
+
+ if (xactStartTimestamp != 0)
+ SetCatCacheClock(xactStartTimestamp);
}
/*
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index fa2b49c676..644d92dd9a 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -38,6 +38,7 @@
#include "utils/rel.h"
#include "utils/resowner_private.h"
#include "utils/syscache.h"
+#include "utils/timestamp.h"
/* #define CACHEDEBUG */ /* turns DEBUG elogs on */
@@ -60,9 +61,19 @@
#define CACHE_elog(...)
#endif
+/*
+ * GUC variable to define the minimum age of entries that will be considered
+ * to be evicted in seconds. -1 to disable the feature.
+ */
+int catalog_cache_prune_min_age = -1;
+uint64 prune_min_age_us;
+
/* Cache management header --- pointer is NULL until created */
static CatCacheHeader *CacheHdr = NULL;
+/* Clock for the last accessed time of a catcache entry. */
+uint64 catcacheclock = 0;
+
static inline HeapTuple SearchCatCacheInternal(CatCache *cache,
int nkeys,
Datum v1, Datum v2,
@@ -74,6 +85,7 @@ static pg_noinline HeapTuple SearchCatCacheMiss(CatCache *cache,
Index hashIndex,
Datum v1, Datum v2,
Datum v3, Datum v4);
+static bool CatCacheCleanupOldEntries(CatCache *cp);
static uint32 CatalogCacheComputeHashValue(CatCache *cache, int nkeys,
Datum v1, Datum v2, Datum v3, Datum v4);
@@ -99,6 +111,15 @@ static void CatCacheFreeKeys(TupleDesc tupdesc, int nkeys, int *attnos,
static void CatCacheCopyKeys(TupleDesc tupdesc, int nkeys, int *attnos,
Datum *srckeys, Datum *dstkeys);
+/* GUC assign function */
+void
+assign_catalog_cache_prune_min_age(int newval, void *extra)
+{
+ if (newval < 0)
+ prune_min_age_us = UINT64_MAX;
+ else
+ prune_min_age_us = ((uint64) newval) * USECS_PER_SEC;
+}
/*
* internal support functions
@@ -1264,6 +1285,9 @@ SearchCatCacheInternal(CatCache *cache,
*/
dlist_move_head(bucket, &ct->cache_elem);
+ /* Record the last access timestamp */
+ ct->lastaccess = catcacheclock;
+
/*
* If it's a positive entry, bump its refcount and return it. If it's
* negative, we can report failure to the caller.
@@ -1425,6 +1449,61 @@ SearchCatCacheMiss(CatCache *cache,
return &ct->tuple;
}
+/*
+ * CatCacheCleanupOldEntries - Remove infrequently-used entries
+ *
+ * Catcache entries happen to be left unused for a long time for several
+ * reasons. Remove such entries to prevent catcache from bloating. It is based
+ * on the similar algorithm with buffer eviction. Entries that are accessed
+ * several times in a certain period live longer than those that have had less
+ * access in the same duration.
+ */
+static bool
+CatCacheCleanupOldEntries(CatCache *cp)
+{
+ int nremoved = 0;
+ int i;
+ long oldest_ts = catcacheclock;
+ uint64 prune_threshold = catcacheclock - prune_min_age_us;
+
+ /* Scan over the whole hash to find entries to remove */
+ for (i = 0 ; i < cp->cc_nbuckets ; i++)
+ {
+ dlist_mutable_iter iter;
+
+ dlist_foreach_modify(iter, &cp->cc_bucket[i])
+ {
+ CatCTup *ct = dlist_container(CatCTup, cache_elem, iter.cur);
+
+ /* Don't remove referenced entries */
+ if (ct->refcount == 0 &&
+ (ct->c_list == NULL || ct->c_list->refcount == 0))
+ {
+ if (ct->lastaccess < prune_threshold)
+ {
+ CatCacheRemoveCTup(cp, ct);
+ nremoved++;
+
+ /* don't let the removed entry update oldest_ts */
+ continue;
+ }
+ }
+
+ /* update the oldest timestamp if the entry remains alive */
+ if (ct->lastaccess < oldest_ts)
+ oldest_ts = ct->lastaccess;
+ }
+ }
+
+ cp->cc_oldest_ts = oldest_ts;
+
+ if (nremoved > 0)
+ elog(DEBUG1, "pruning catalog cache id=%d for %s: removed %d / %d",
+ cp->id, cp->cc_relname, nremoved, cp->cc_ntup + nremoved);
+
+ return nremoved > 0;
+}
+
/*
* ReleaseCatCache
*
@@ -1888,6 +1967,7 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments,
ct->dead = false;
ct->negative = negative;
ct->hash_value = hashValue;
+ ct->lastaccess = catcacheclock;
dlist_push_head(&cache->cc_bucket[hashIndex], &ct->cache_elem);
@@ -1899,7 +1979,12 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments,
* arbitrarily, we enlarge when fill factor > 2.
*/
if (cache->cc_ntup > cache->cc_nbuckets * 2)
- RehashCatCache(cache);
+ {
+ /* try removing old entries before expanding hash */
+ if (catcacheclock - cache->cc_oldest_ts < prune_min_age_us ||
+ !CatCacheCleanupOldEntries(cache))
+ RehashCatCache(cache);
+ }
return ct;
}
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 17579eeaca..255e9fa73d 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -88,6 +88,7 @@
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
+#include "utils/catcache.h"
#include "utils/float.h"
#include "utils/guc_tables.h"
#include "utils/memutils.h"
@@ -3445,6 +3446,17 @@ static struct config_int ConfigureNamesInt[] =
NULL, NULL, NULL
},
+ {
+ {"catalog_cache_prune_min_age", PGC_USERSET, RESOURCES_MEM,
+ gettext_noop("System catalog cache entries that are living unused more than this seconds are considered for removal."),
+ gettext_noop("The value of -1 turns off pruning."),
+ GUC_UNIT_S
+ },
+ &catalog_cache_prune_min_age,
+ -1, -1, INT_MAX,
+ NULL, assign_catalog_cache_prune_min_age, NULL
+ },
+
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h
index ddc2762eb3..291e857e38 100644
--- a/src/include/utils/catcache.h
+++ b/src/include/utils/catcache.h
@@ -22,6 +22,7 @@
#include "access/htup.h"
#include "access/skey.h"
+#include "datatype/timestamp.h"
#include "lib/ilist.h"
#include "utils/relcache.h"
@@ -61,6 +62,7 @@ typedef struct catcache
slist_node cc_next; /* list link */
ScanKeyData cc_skey[CATCACHE_MAXKEYS]; /* precomputed key info for heap
* scans */
+ uint64 cc_oldest_ts; /* timestamp (us) of the oldest tuple */
/*
* Keep these at the end, so that compiling catcache.c with CATCACHE_STATS
@@ -119,6 +121,7 @@ typedef struct catctup
bool dead; /* dead but not yet removed? */
bool negative; /* negative cache entry? */
HeapTupleData tuple; /* tuple management header */
+ uint64 lastaccess; /* timestamp in us of the last usage */
/*
* The tuple may also be a member of at most one CatCList. (If a single
@@ -189,6 +192,22 @@ typedef struct catcacheheader
/* this extern duplicates utils/memutils.h... */
extern PGDLLIMPORT MemoryContext CacheMemoryContext;
+
+/* for guc.c, not PGDLLPMPORT'ed */
+extern int catalog_cache_prune_min_age;
+
+/* source clock for access timestamp of catcache entries */
+extern uint64 catcacheclock;
+
+/* SetCatCacheClock - set catcache timestamp source clock */
+static inline void
+SetCatCacheClock(TimestampTz ts)
+{
+ catcacheclock = (uint64) ts;
+}
+
+extern void assign_catalog_cache_prune_min_age(int newval, void *extra);
+
extern void CreateCacheMemoryContext(void);
extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
--
2.27.0
----Next_Part(Thu_Jan_14_17_32_27_2021_995)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v6-0002-Remove-dead-flag-from-catcache-tuple.patch"
^ permalink raw reply [nested|flat] 6+ messages in thread
* Bug: pg_regress makefile does not always copy refint.so
@ 2022-10-14 06:31 Donghang Lin <[email protected]>
2022-10-14 18:14 ` Re: Bug: pg_regress makefile does not always copy refint.so Alvaro Herrera <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: Donghang Lin @ 2022-10-14 06:31 UTC (permalink / raw)
To: [email protected] <[email protected]>
Hi hackers,
When I was building pg_regress, it didn’t always copy a rebuilt version of refint.so to the folder.
Steps to reproduce:
OS: centos7
PSQL version: 14.5
1. configure and build postgres
2. edit file src/include/utils/rel.h so that contrib/spi will rebuild
3. cd ${builddir}/src/test/regress
4. make
We’ll find refint.so is rebuilt in contrib/spi, but not copied over to regress folder.
While autoinc.so is rebuilt and copied over.
Attach the potential patch to fix the issue.
Regards,
Donghang Lin
(ServiceNow)
Attachments:
[application/octet-stream] fix-pgregress-makefile.patch (744B, ../../CO2PR0801MB2247B27C81C40D853A46954EF9249@CO2PR0801MB2247.namprd08.prod.outlook.com/3-fix-pgregress-makefile.patch)
download | inline diff:
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index fe6e0c98aa..52ca7f79d4 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -105,9 +105,9 @@ refint$(DLSUFFIX): $(top_builddir)/contrib/spi/refint$(DLSUFFIX)
autoinc$(DLSUFFIX): $(top_builddir)/contrib/spi/autoinc$(DLSUFFIX)
cp $< $@
-$(top_builddir)/contrib/spi/refint$(DLSUFFIX): | submake-contrib-spi ;
+$(top_builddir)/contrib/spi/refint$(DLSUFFIX): submake-contrib-spi ;
-$(top_builddir)/contrib/spi/autoinc$(DLSUFFIX): | submake-contrib-spi ;
+$(top_builddir)/contrib/spi/autoinc$(DLSUFFIX): submake-contrib-spi ;
submake-contrib-spi: | submake-libpgport submake-generated-headers
$(MAKE) -C $(top_builddir)/contrib/spi
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug: pg_regress makefile does not always copy refint.so
2022-10-14 06:31 Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
@ 2022-10-14 18:14 ` Alvaro Herrera <[email protected]>
2022-10-18 19:48 ` Re: Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: Alvaro Herrera @ 2022-10-14 18:14 UTC (permalink / raw)
To: Donghang Lin <[email protected]>; +Cc: [email protected] <[email protected]>
On 2022-Oct-14, Donghang Lin wrote:
> Hi hackers,
>
> When I was building pg_regress, it didn’t always copy a rebuilt version of refint.so to the folder.
>
> Steps to reproduce:
> OS: centos7
> PSQL version: 14.5
>
> 1. configure and build postgres
> 2. edit file src/include/utils/rel.h so that contrib/spi will rebuild
> 3. cd ${builddir}/src/test/regress
> 4. make
> We’ll find refint.so is rebuilt in contrib/spi, but not copied over to regress folder.
> While autoinc.so is rebuilt and copied over.
I have a somewhat-related-but-not-really complaint. I recently had need to
have refint.so, autoinc.so and regress.so in the install directory; but it
turns out that there's no provision at all to get them installed.
Packagers have long have had a need for this; for example the postgresql-test
RPM file is built using this icky recipe:
%if %test
# tests. There are many files included here that are unnecessary,
# but include them anyway for completeness. We replace the original
# Makefiles, however.
%{__mkdir} -p %{buildroot}%{pgbaseinstdir}/lib/test
%{__cp} -a src/test/regress %{buildroot}%{pgbaseinstdir}/lib/test
%{__install} -m 0755 contrib/spi/refint.so %{buildroot}%{pgbaseinstdir}/lib/test/regress
%{__install} -m 0755 contrib/spi/autoinc.so %{buildroot}%{pgbaseinstdir}/lib/test/regress
I assume that the DEB does something similar, but I didn't look.
I think it would be better to provide a Make rule to allow these files to be
installed. I'll see about a proposed patch.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Saca el libro que tu religión considere como el indicado para encontrar la
oración que traiga paz a tu alma. Luego rebootea el computador
y ve si funciona" (Carlos Duclós)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug: pg_regress makefile does not always copy refint.so
2022-10-14 06:31 Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
2022-10-14 18:14 ` Re: Bug: pg_regress makefile does not always copy refint.so Alvaro Herrera <[email protected]>
@ 2022-10-18 19:48 ` Donghang Lin <[email protected]>
2022-10-19 06:27 ` Re: Bug: pg_regress makefile does not always copy refint.so Alvaro Herrera <[email protected]>
0 siblings, 1 reply; 6+ messages in thread
From: Donghang Lin @ 2022-10-18 19:48 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; +Cc: [email protected] <[email protected]>
Hi Alvaro,
> I have a somewhat-related-but-not-really complaint. I recently had need to
> have refint.so, autoinc.so and regress.so in the install directory; but it
> turns out that there's no provision at all to get them installed.
True, we also noticed this build bug described above by copying *.so and pg_regress binary around.
> I think it would be better to provide a Make rule to allow these files to be
> installed.
I looked at what postgresql-test package<https://ftp.postgresql.org/pub/repos/yum/15/redhat/rhel-7.9-x86_64/postgresql15-test-15.0-1PGDG.rhel...; provides today :
$ ls /usr/pgsql-15/lib/test/regress
autoinc.so data expected Makefile parallel_schedule pg_regress pg_regress.c pg_regress.h pg_regress_main.c README refint.so regress.c regressplans.sh regress.so resultmap sql
(I’m not sure what this package is supposed to do, it contains both source files and the executables.
The current pgsql install directory of regress only contains pg_regress binary,
Do you suggest we add these files (excluding the scratched files) to the regress install directory?
autoinc.so data expected Makefile parallel_schedule pg_regress pg_regress.c pg_regress.h pg_regress_main.c README refint.so regress.c regressplans.sh regress.so resultmap sql
>> 1. configure and build postgres
>> 2. edit file src/include/utils/rel.h so that contrib/spi will rebuild
>> 3. cd ${builddir}/src/test/regress
>> 4. make
>> We’ll find refint.so is rebuilt in contrib/spi, but not copied over to regress folder.
>> While autoinc.so is rebuilt and copied over.
I think this build bug is orthogonal to the inconvenient installation/packaging.
It produces inconsistent build result, e.g you have to run `make` twice to ensure newly built refint.so is copied to the build dir.
Regards,
Donghang Lin
(ServiceNow)
From: Alvaro Herrera <[email protected]>
Date: Friday, October 14, 2022 at 8:15 PM
To: Donghang Lin <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Bug: pg_regress makefile does not always copy refint.so
[External Email]
On 2022-Oct-14, Donghang Lin wrote:
> Hi hackers,
>
> When I was building pg_regress, it didn’t always copy a rebuilt version of refint.so to the folder.
>
> Steps to reproduce:
> OS: centos7
> PSQL version: 14.5
>
> 1. configure and build postgres
> 2. edit file src/include/utils/rel.h so that contrib/spi will rebuild
> 3. cd ${builddir}/src/test/regress
> 4. make
> We’ll find refint.so is rebuilt in contrib/spi, but not copied over to regress folder.
> While autoinc.so is rebuilt and copied over.
I have a somewhat-related-but-not-really complaint. I recently had need to
have refint.so, autoinc.so and regress.so in the install directory; but it
turns out that there's no provision at all to get them installed.
Packagers have long have had a need for this; for example the postgresql-test
RPM file is built using this icky recipe:
%if %test
# tests. There are many files included here that are unnecessary,
# but include them anyway for completeness. We replace the original
# Makefiles, however.
%{__mkdir} -p %{buildroot}%{pgbaseinstdir}/lib/test
%{__cp} -a src/test/regress %{buildroot}%{pgbaseinstdir}/lib/test
%{__install} -m 0755 contrib/spi/refint.so %{buildroot}%{pgbaseinstdir}/lib/test/regress
%{__install} -m 0755 contrib/spi/autoinc.so %{buildroot}%{pgbaseinstdir}/lib/test/regress
I assume that the DEB does something similar, but I didn't look.
I think it would be better to provide a Make rule to allow these files to be
installed. I'll see about a proposed patch.
--
Álvaro Herrera Breisgau, Deutschland — https://urldefense.com/v3/__https://www.EnterpriseDB.com/__;!!N4vogdjhuJM!Gz471V39hPgZI8Uabm3fUUHoZI...;
"Saca el libro que tu religión considere como el indicado para encontrar la
oración que traiga paz a tu alma. Luego rebootea el computador
y ve si funciona" (Carlos Duclós)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug: pg_regress makefile does not always copy refint.so
2022-10-14 06:31 Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
2022-10-14 18:14 ` Re: Bug: pg_regress makefile does not always copy refint.so Alvaro Herrera <[email protected]>
2022-10-18 19:48 ` Re: Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
@ 2022-10-19 06:27 ` Alvaro Herrera <[email protected]>
0 siblings, 0 replies; 6+ messages in thread
From: Alvaro Herrera @ 2022-10-19 06:27 UTC (permalink / raw)
To: Donghang Lin <[email protected]>; +Cc: [email protected] <[email protected]>
Hi,
On 2022-Oct-18, Donghang Lin wrote:
> > I have a somewhat-related-but-not-really complaint. I recently had need to
> > have refint.so, autoinc.so and regress.so in the install directory; but it
> > turns out that there's no provision at all to get them installed.
> The current pgsql install directory of regress only contains pg_regress binary,
> Do you suggest we add these files (excluding the scratched files) to the regress install directory?
> autoinc.so data expected Makefile parallel_schedule pg_regress pg_regress.c pg_regress.h pg_regress_main.c README refint.so regress.c regressplans.sh regress.so resultmap sql
No, I think the .c/.h files are likely included only because the RPM
rule is written somewhat carelessly. If we add support in our
makefiles, it would have to be something better-considered.
> I think this build bug is orthogonal to the inconvenient installation/packaging.
> It produces inconsistent build result, e.g you have to run `make` twice to ensure newly built refint.so is copied to the build dir.
Yes, I agree that it is orthogonal. I'm not sure that what you propose
(changing these order-only dependencies into regular dependencies) is
the best possible fix, but I agree we need *some* fix.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
^ permalink raw reply [nested|flat] 6+ messages in thread
* [PATCH v9 3/7] Row pattern recognition patch (planner).
@ 2023-10-04 05:51 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 6+ messages in thread
From: Tatsuo Ishii @ 2023-10-04 05:51 UTC (permalink / raw)
---
src/backend/optimizer/plan/createplan.c | 23 ++++++++++++++++++-----
src/backend/optimizer/plan/setrefs.c | 23 +++++++++++++++++++++++
src/include/nodes/plannodes.h | 15 +++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 34ca6d4ac2..469fcd156b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -286,9 +286,10 @@ static WindowAgg *make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow,
- Plan *lefttree);
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree);
static Group *make_group(List *tlist, List *qual, int numGroupCols,
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
Plan *lefttree);
@@ -2698,6 +2699,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
wc->inRangeAsc,
wc->inRangeNullsFirst,
wc->runCondition,
+ wc->rpSkipTo,
+ wc->patternVariable,
+ wc->patternRegexp,
+ wc->defineClause,
+ wc->defineInitial,
best_path->qual,
best_path->topwindow,
subplan);
@@ -6601,8 +6607,10 @@ make_windowagg(List *tlist, Index winref,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
int frameOptions, Node *startOffset, Node *endOffset,
Oid startInRangeFunc, Oid endInRangeFunc,
- Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst,
- List *runCondition, List *qual, bool topWindow, Plan *lefttree)
+ Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, List *runCondition,
+ RPSkipTo rpSkipTo, List *patternVariable, List *patternRegexp, List *defineClause,
+ List *defineInitial,
+ List *qual, bool topWindow, Plan *lefttree)
{
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
@@ -6628,6 +6636,11 @@ make_windowagg(List *tlist, Index winref,
node->inRangeAsc = inRangeAsc;
node->inRangeNullsFirst = inRangeNullsFirst;
node->topWindow = topWindow;
+ node->rpSkipTo = rpSkipTo,
+ node->patternVariable = patternVariable;
+ node->patternRegexp = patternRegexp;
+ node->defineClause = defineClause;
+ node->defineInitial = defineInitial;
plan->targetlist = tlist;
plan->lefttree = lefttree;
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 7962200885..20ce399763 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -2456,6 +2456,29 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
NRM_EQUAL,
NUM_EXEC_QUAL(plan));
+ /*
+ * Modifies an expression tree in each DEFINE clause so that all Var
+ * nodes reference outputs of a subplan.
+ */
+ if (IsA(plan, WindowAgg))
+ {
+ WindowAgg *wplan = (WindowAgg *) plan;
+
+ foreach(l, wplan->defineClause)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ tle->expr = (Expr *)
+ fix_upper_expr(root,
+ (Node *) tle->expr,
+ subplan_itlist,
+ OUTER_VAR,
+ rtoffset,
+ NRM_EQUAL,
+ NUM_EXEC_QUAL(plan));
+ }
+ }
+
pfree(subplan_itlist);
}
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 8cafbf3f8a..e48b59517d 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -1096,6 +1096,21 @@ typedef struct WindowAgg
/* nulls sort first for in_range tests? */
bool inRangeNullsFirst;
+ /* Row Pattern Recognition AFTER MACH SKIP clause */
+ RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
+
+ /* Row Pattern PATTERN variable name (list of String) */
+ List *patternVariable;
+
+ /* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of String) */
+ List *patternRegexp;
+
+ /* Row Pattern DEFINE clause (list of TargetEntry) */
+ List *defineClause;
+
+ /* Row Pattern DEFINE variable initial names (list of String) */
+ List *defineInitial;
+
/*
* false for all apart from the WindowAgg that's closest to the root of
* the plan
--
2.25.1
----Next_Part(Wed_Oct__4_15_03_28_2023_821)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v9-0004-Row-pattern-recognition-patch-executor.patch"
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2023-10-04 05:51 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 07:54 [PATCH v6 1/3] CatCache expiration feature Kyotaro Horiguchi <[email protected]>
2022-10-14 06:31 Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
2022-10-14 18:14 ` Re: Bug: pg_regress makefile does not always copy refint.so Alvaro Herrera <[email protected]>
2022-10-18 19:48 ` Re: Bug: pg_regress makefile does not always copy refint.so Donghang Lin <[email protected]>
2022-10-19 06:27 ` Re: Bug: pg_regress makefile does not always copy refint.so Alvaro Herrera <[email protected]>
2023-10-04 05:51 [PATCH v9 3/7] Row pattern recognition patch (planner). Tatsuo Ishii <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox