agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v5 06/12] consistent language: not implemented 10+ messages / 4 participants [nested] [flat]
* [PATCH v5 06/12] consistent language: not implemented @ 2019-05-20 17:57 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Justin Pryzby @ 2019-05-20 17:57 UTC (permalink / raw) Should we change the rest of these, too ? git grep 'errmsg.*not yet implemented' --- src/backend/catalog/index.c | 2 +- src/backend/commands/indexcmds.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index bb60b23..7f607e6 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3511,7 +3511,7 @@ reindex_relation(Oid relid, int flags, int options) { ereport(WARNING, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("REINDEX of partitioned tables is not yet implemented, skipping \"%s\"", + errmsg("REINDEX of partitioned tables is not implemented, skipping \"%s\"", RelationGetRelationName(rel)))); table_close(rel, ShareLock); return false; diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 6fa5738..5b0ae20 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -2898,7 +2898,7 @@ ReindexRelationConcurrently(Oid relationOid, int options) /* see reindex_relation() */ ereport(WARNING, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("REINDEX of partitioned tables is not yet implemented, skipping \"%s\"", + errmsg("REINDEX of partitioned tables is not implemented, skipping \"%s\"", get_rel_name(relationOid)))); return false; default: @@ -3344,7 +3344,7 @@ ReindexPartitionedIndex(Relation parentIdx) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("REINDEX is not yet implemented for partitioned indexes"))); + errmsg("REINDEX is not implemented for partitioned indexes"))); } /* -- 2.7.4 --FkmkrVfFsRoUs1wW Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0007-consistent-language-to-which.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH v3 06/12] consistent language: not implemented @ 2019-05-20 17:57 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Justin Pryzby @ 2019-05-20 17:57 UTC (permalink / raw) Should we change the rest of these, too ? git grep 'errmsg.*not yet implemented' --- src/backend/catalog/index.c | 2 +- src/backend/commands/indexcmds.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index c8d22e1..2a2dca3 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3506,7 +3506,7 @@ reindex_relation(Oid relid, int flags, int options) { ereport(WARNING, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("REINDEX of partitioned tables is not yet implemented, skipping \"%s\"", + errmsg("REINDEX of partitioned tables is not implemented, skipping \"%s\"", RelationGetRelationName(rel)))); table_close(rel, ShareLock); return false; diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 7e7c03e..b2b15ec 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -2862,7 +2862,7 @@ ReindexRelationConcurrently(Oid relationOid, int options) /* see reindex_relation() */ ereport(WARNING, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("REINDEX of partitioned tables is not yet implemented, skipping \"%s\"", + errmsg("REINDEX of partitioned tables is not implemented, skipping \"%s\"", get_rel_name(relationOid)))); return false; default: @@ -3306,7 +3306,7 @@ ReindexPartitionedIndex(Relation parentIdx) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("REINDEX is not yet implemented for partitioned indexes"))); + errmsg("REINDEX is not implemented for partitioned indexes"))); } /* -- 2.7.4 --cWoXeonUoKmBZSoM Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0007-overridden-vs-overwritten.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH] Document RelationGetIndexAttrBitmap better @ 2023-07-12 12:19 Alvaro Herrera <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Alvaro Herrera @ 2023-07-12 12:19 UTC (permalink / raw) Commit 19d8e2308bc5 changed the list of set-of-columns that can be returned by RelationGetIndexAttrBitmap, but didn't update its "documentation". That was pretty hard to read already, so rewrite to make it more comprehensible, adding the missing values while at it. Backpatch to 16, like that commit. --- src/backend/utils/cache/relcache.c | 12 +++++++++--- src/include/utils/relcache.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 8e28335915..8e08ca1c68 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -5150,9 +5150,15 @@ RelationGetIndexPredicate(Relation relation) * simple index keys, but attributes used in expressions and partial-index * predicates.) * - * Depending on attrKind, a bitmap covering the attnums for all index columns, - * for all potential foreign key columns, or for all columns in the configured - * replica identity index is returned. + * Depending on attrKind, a bitmap covering attnums for certain columns is + * returned: + * INDEX_ATTR_BITMAP_KEY Columns in non-partial unique indexes not + * in expressions (i.e., usable for FKs) + * INDEX_ATTR_BITMAP_PRIMARY_KEY Columns in the table's primary key + * INDEX_ATTR_BITMAP_IDENTITY_KEY Columns in the table's replica identity + * index (empty if FULL) + * INDEX_ATTR_BITMAP_HOT_BLOCKING Columns that block updates from being HOT + * INDEX_ATTR_BITMAP_SUMMARIZED Columns included in summarizing indexes * * Attribute numbers are offset by FirstLowInvalidHeapAttributeNumber so that * we can include system attributes (e.g., OID) in the bitmap representation. diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index beeb28b83c..38524641f4 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -54,6 +54,9 @@ extern List *RelationGetIndexPredicate(Relation relation); extern Datum *RelationGetIndexRawAttOptions(Relation indexrel); extern bytea **RelationGetIndexAttOptions(Relation relation, bool copy); +/* + * Which set of columns to return by RelationGetIndexAttrBitmap. + */ typedef enum IndexAttrBitmapKind { INDEX_ATTR_BITMAP_KEY, -- 2.39.2 --sr6mye444zs4xrf5-- ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH] Document RelationGetIndexAttrBitmap better @ 2023-07-12 12:19 Alvaro Herrera <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Alvaro Herrera @ 2023-07-12 12:19 UTC (permalink / raw) Commit 19d8e2308bc5 changed the list of set-of-columns that can be returned by RelationGetIndexAttrBitmap, but didn't update its "documentation". That was pretty hard to read already, so rewrite to make it more comprehensible, adding the missing values while at it. Backpatch to 16, like that commit. --- src/backend/utils/cache/relcache.c | 12 +++++++++--- src/include/utils/relcache.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 8e28335915..8e08ca1c68 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -5150,9 +5150,15 @@ RelationGetIndexPredicate(Relation relation) * simple index keys, but attributes used in expressions and partial-index * predicates.) * - * Depending on attrKind, a bitmap covering the attnums for all index columns, - * for all potential foreign key columns, or for all columns in the configured - * replica identity index is returned. + * Depending on attrKind, a bitmap covering attnums for certain columns is + * returned: + * INDEX_ATTR_BITMAP_KEY Columns in non-partial unique indexes not + * in expressions (i.e., usable for FKs) + * INDEX_ATTR_BITMAP_PRIMARY_KEY Columns in the table's primary key + * INDEX_ATTR_BITMAP_IDENTITY_KEY Columns in the table's replica identity + * index (empty if FULL) + * INDEX_ATTR_BITMAP_HOT_BLOCKING Columns that block updates from being HOT + * INDEX_ATTR_BITMAP_SUMMARIZED Columns included in summarizing indexes * * Attribute numbers are offset by FirstLowInvalidHeapAttributeNumber so that * we can include system attributes (e.g., OID) in the bitmap representation. diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index beeb28b83c..38524641f4 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -54,6 +54,9 @@ extern List *RelationGetIndexPredicate(Relation relation); extern Datum *RelationGetIndexRawAttOptions(Relation indexrel); extern bytea **RelationGetIndexAttOptions(Relation relation, bool copy); +/* + * Which set of columns to return by RelationGetIndexAttrBitmap. + */ typedef enum IndexAttrBitmapKind { INDEX_ATTR_BITMAP_KEY, -- 2.39.2 --sr6mye444zs4xrf5-- ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH] Document RelationGetIndexAttrBitmap better @ 2023-07-12 12:19 Alvaro Herrera <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Alvaro Herrera @ 2023-07-12 12:19 UTC (permalink / raw) Commit 19d8e2308bc5 changed the list of set-of-columns that can be returned by RelationGetIndexAttrBitmap, but didn't update its "documentation". That was pretty hard to read already, so rewrite to make it more comprehensible, adding the missing values while at it. Backpatch to 16, like that commit. --- src/backend/utils/cache/relcache.c | 12 +++++++++--- src/include/utils/relcache.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 8e28335915..8e08ca1c68 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -5150,9 +5150,15 @@ RelationGetIndexPredicate(Relation relation) * simple index keys, but attributes used in expressions and partial-index * predicates.) * - * Depending on attrKind, a bitmap covering the attnums for all index columns, - * for all potential foreign key columns, or for all columns in the configured - * replica identity index is returned. + * Depending on attrKind, a bitmap covering attnums for certain columns is + * returned: + * INDEX_ATTR_BITMAP_KEY Columns in non-partial unique indexes not + * in expressions (i.e., usable for FKs) + * INDEX_ATTR_BITMAP_PRIMARY_KEY Columns in the table's primary key + * INDEX_ATTR_BITMAP_IDENTITY_KEY Columns in the table's replica identity + * index (empty if FULL) + * INDEX_ATTR_BITMAP_HOT_BLOCKING Columns that block updates from being HOT + * INDEX_ATTR_BITMAP_SUMMARIZED Columns included in summarizing indexes * * Attribute numbers are offset by FirstLowInvalidHeapAttributeNumber so that * we can include system attributes (e.g., OID) in the bitmap representation. diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index beeb28b83c..38524641f4 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -54,6 +54,9 @@ extern List *RelationGetIndexPredicate(Relation relation); extern Datum *RelationGetIndexRawAttOptions(Relation indexrel); extern bytea **RelationGetIndexAttOptions(Relation relation, bool copy); +/* + * Which set of columns to return by RelationGetIndexAttrBitmap. + */ typedef enum IndexAttrBitmapKind { INDEX_ATTR_BITMAP_KEY, -- 2.39.2 --sr6mye444zs4xrf5-- ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH v14 2/8] Row pattern recognition patch (parse/analysis). @ 2024-02-28 13:59 Tatsuo Ishii <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Tatsuo Ishii @ 2024-02-28 13:59 UTC (permalink / raw) --- src/backend/parser/parse_agg.c | 7 + src/backend/parser/parse_clause.c | 296 +++++++++++++++++++++++++++++- src/backend/parser/parse_expr.c | 4 + src/backend/parser/parse_func.c | 3 + 4 files changed, 309 insertions(+), 1 deletion(-) diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c index 9d151a880b..a36218b103 100644 --- a/src/backend/parser/parse_agg.c +++ b/src/backend/parser/parse_agg.c @@ -576,6 +576,10 @@ check_agglevels_and_constraints(ParseState *pstate, Node *expr) errkind = true; break; + case EXPR_KIND_RPR_DEFINE: + errkind = true; + break; + /* * There is intentionally no default: case here, so that the * compiler will warn if we add a new ParseExprKind without @@ -965,6 +969,9 @@ transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc, case EXPR_KIND_CYCLE_MARK: errkind = true; break; + case EXPR_KIND_RPR_DEFINE: + errkind = true; + break; /* * There is intentionally no default: case here, so that the diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 4b50278fd0..8a4f8f24d2 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -100,7 +100,14 @@ static WindowClause *findWindowClause(List *wclist, const char *name); static Node *transformFrameOffset(ParseState *pstate, int frameOptions, Oid rangeopfamily, Oid rangeopcintype, Oid *inRangeFunc, Node *clause); - +static void transformRPR(ParseState *pstate, WindowClause *wc, WindowDef *windef, + List **targetlist); +static List *transformDefineClause(ParseState *pstate, WindowClause *wc, WindowDef *windef, + List **targetlist); +static void transformPatternClause(ParseState *pstate, WindowClause *wc, + WindowDef *windef); +static List *transformMeasureClause(ParseState *pstate, WindowClause *wc, + WindowDef *windef); /* * transformFromClause - @@ -2950,6 +2957,10 @@ transformWindowDefinitions(ParseState *pstate, rangeopfamily, rangeopcintype, &wc->endInRangeFunc, windef->endOffset); + + /* Process Row Pattern Recognition related clauses */ + transformRPR(pstate, wc, windef, targetlist); + wc->runCondition = NIL; wc->winref = winref; @@ -3815,3 +3826,286 @@ transformFrameOffset(ParseState *pstate, int frameOptions, return node; } + +/* + * transformRPR + * Process Row Pattern Recognition related clauses + */ +static void +transformRPR(ParseState *pstate, WindowClause *wc, WindowDef *windef, + List **targetlist) +{ + /* + * Window definition exists? + */ + if (windef == NULL) + return; + + /* + * Row Pattern Common Syntax clause exists? + */ + if (windef->rpCommonSyntax == NULL) + return; + + /* Check Frame option. Frame must start at current row */ + if ((wc->frameOptions & FRAMEOPTION_START_CURRENT_ROW) == 0) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("FRAME must start at current row when row patttern recognition is used"))); + + /* Transform AFTER MACH SKIP TO clause */ + wc->rpSkipTo = windef->rpCommonSyntax->rpSkipTo; + + /* Transform AFTER MACH SKIP TO variable */ + wc->rpSkipVariable = windef->rpCommonSyntax->rpSkipVariable; + + /* Transform SEEK or INITIAL clause */ + wc->initial = windef->rpCommonSyntax->initial; + + /* Transform DEFINE clause into list of TargetEntry's */ + wc->defineClause = transformDefineClause(pstate, wc, windef, targetlist); + + /* Check PATTERN clause and copy to patternClause */ + transformPatternClause(pstate, wc, windef); + + /* Transform MEASURE clause */ + transformMeasureClause(pstate, wc, windef); +} + +/* + * transformDefineClause Process DEFINE clause and transform ResTarget into + * list of TargetEntry. + * + * XXX we only support column reference in row pattern definition search + * condition, e.g. "price". <row pattern definition variable name>.<column + * reference> is not supported, e.g. "A.price". + */ +static List * +transformDefineClause(ParseState *pstate, WindowClause *wc, WindowDef *windef, + List **targetlist) +{ + /* DEFINE variable name initials */ + static char *defineVariableInitials = "abcdefghijklmnopqrstuvwxyz"; + + ListCell *lc, + *l; + ResTarget *restarget, + *r; + List *restargets; + List *defineClause; + char *name; + int initialLen; + int i; + + /* + * If Row Definition Common Syntax exists, DEFINE clause must exist. (the + * raw parser should have already checked it.) + */ + Assert(windef->rpCommonSyntax->rpDefs != NULL); + + /* + * Check and add "A AS A IS TRUE" if pattern variable is missing in DEFINE + * per the SQL standard. + */ + restargets = NIL; + foreach(lc, windef->rpCommonSyntax->rpPatterns) + { + A_Expr *a; + bool found = false; + + if (!IsA(lfirst(lc), A_Expr)) + ereport(ERROR, + errmsg("node type is not A_Expr")); + + a = (A_Expr *) lfirst(lc); + name = strVal(a->lexpr); + + foreach(l, windef->rpCommonSyntax->rpDefs) + { + restarget = (ResTarget *) lfirst(l); + + if (!strcmp(restarget->name, name)) + { + found = true; + break; + } + } + + if (!found) + { + /* + * "name" is missing. So create "name AS name IS TRUE" ResTarget + * node and add it to the temporary list. + */ + A_Const *n; + + restarget = makeNode(ResTarget); + n = makeNode(A_Const); + n->val.boolval.type = T_Boolean; + n->val.boolval.boolval = true; + n->location = -1; + restarget->name = pstrdup(name); + restarget->indirection = NIL; + restarget->val = (Node *) n; + restarget->location = -1; + restargets = lappend((List *) restargets, restarget); + } + } + + if (list_length(restargets) >= 1) + { + /* add missing DEFINEs */ + windef->rpCommonSyntax->rpDefs = + list_concat(windef->rpCommonSyntax->rpDefs, restargets); + list_free(restargets); + } + + /* + * Check for duplicate row pattern definition variables. The standard + * requires that no two row pattern definition variable names shall be + * equivalent. + */ + restargets = NIL; + foreach(lc, windef->rpCommonSyntax->rpDefs) + { + restarget = (ResTarget *) lfirst(lc); + name = restarget->name; + + /* + * Add DEFINE expression (Restarget->val) to the targetlist as a + * TargetEntry if it does not exist yet. Planner will add the column + * ref var node to the outer plan's target list later on. This makes + * DEFINE expression could access the outer tuple while evaluating + * PATTERN. + * + * XXX: adding whole expressions of DEFINE to the plan.targetlist is + * not so good, because it's not necessary to evalute the expression + * in the target list while running the plan. We should extract the + * var nodes only then add them to the plan.targetlist. + */ + findTargetlistEntrySQL99(pstate, (Node *) restarget->val, + targetlist, EXPR_KIND_RPR_DEFINE); + + /* + * Make sure that the row pattern definition search condition is a + * boolean expression. + */ + transformWhereClause(pstate, restarget->val, + EXPR_KIND_RPR_DEFINE, "DEFINE"); + + foreach(l, restargets) + { + char *n; + + r = (ResTarget *) lfirst(l); + n = r->name; + + if (!strcmp(n, name)) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("row pattern definition variable name \"%s\" appears more than once in DEFINE clause", + name), + parser_errposition(pstate, exprLocation((Node *) r)))); + } + restargets = lappend(restargets, restarget); + } + list_free(restargets); + + /* + * Create list of row pattern DEFINE variable name's initial. We assign + * [a-z] to them (up to 26 variable names are allowed). + */ + restargets = NIL; + i = 0; + initialLen = strlen(defineVariableInitials); + + foreach(lc, windef->rpCommonSyntax->rpDefs) + { + char initial[2]; + + restarget = (ResTarget *) lfirst(lc); + name = restarget->name; + + if (i >= initialLen) + { + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("number of row pattern definition variable names exceeds %d", + initialLen), + parser_errposition(pstate, + exprLocation((Node *) restarget)))); + } + initial[0] = defineVariableInitials[i++]; + initial[1] = '\0'; + wc->defineInitial = lappend(wc->defineInitial, + makeString(pstrdup(initial))); + } + + defineClause = transformTargetList(pstate, windef->rpCommonSyntax->rpDefs, + EXPR_KIND_RPR_DEFINE); + + /* mark column origins */ + markTargetListOrigins(pstate, defineClause); + + /* mark all nodes in the DEFINE clause tree with collation information */ + assign_expr_collations(pstate, (Node *) defineClause); + + return defineClause; +} + +/* + * transformPatternClause + * Process PATTERN clause and return PATTERN clause in the raw parse tree + */ +static void +transformPatternClause(ParseState *pstate, WindowClause *wc, + WindowDef *windef) +{ + ListCell *lc; + + /* + * Row Pattern Common Syntax clause exists? + */ + if (windef->rpCommonSyntax == NULL) + return; + + wc->patternVariable = NIL; + wc->patternRegexp = NIL; + foreach(lc, windef->rpCommonSyntax->rpPatterns) + { + A_Expr *a; + char *name; + char *regexp; + + if (!IsA(lfirst(lc), A_Expr)) + ereport(ERROR, + errmsg("node type is not A_Expr")); + + a = (A_Expr *) lfirst(lc); + name = strVal(a->lexpr); + + wc->patternVariable = lappend(wc->patternVariable, makeString(pstrdup(name))); + regexp = strVal(lfirst(list_head(a->name))); + + wc->patternRegexp = lappend(wc->patternRegexp, makeString(pstrdup(regexp))); + } +} + +/* + * transformMeasureClause + * Process MEASURE clause + * XXX MEASURE clause is not supported yet + */ +static List * +transformMeasureClause(ParseState *pstate, WindowClause *wc, + WindowDef *windef) +{ + if (windef->rowPatternMeasures == NIL) + return NIL; + + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("%s", "MEASURE clause is not supported yet"), + parser_errposition(pstate, exprLocation((Node *) windef->rowPatternMeasures)))); + return NIL; +} diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 9300c7b9ab..da4f42677b 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -557,6 +557,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref) case EXPR_KIND_COPY_WHERE: case EXPR_KIND_GENERATED_COLUMN: case EXPR_KIND_CYCLE_MARK: + case EXPR_KIND_RPR_DEFINE: /* okay */ break; @@ -1770,6 +1771,7 @@ transformSubLink(ParseState *pstate, SubLink *sublink) case EXPR_KIND_VALUES: case EXPR_KIND_VALUES_SINGLE: case EXPR_KIND_CYCLE_MARK: + case EXPR_KIND_RPR_DEFINE: /* okay */ break; case EXPR_KIND_CHECK_CONSTRAINT: @@ -3149,6 +3151,8 @@ ParseExprKindName(ParseExprKind exprKind) return "GENERATED AS"; case EXPR_KIND_CYCLE_MARK: return "CYCLE"; + case EXPR_KIND_RPR_DEFINE: + return "DEFINE"; /* * There is intentionally no default: case here, so that the diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index fdb3e6df33..bf07085a15 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -2656,6 +2656,9 @@ check_srf_call_placement(ParseState *pstate, Node *last_srf, int location) case EXPR_KIND_CYCLE_MARK: errkind = true; break; + case EXPR_KIND_RPR_DEFINE: + errkind = true; + break; /* * There is intentionally no default: case here, so that the -- 2.25.1 ----Next_Part(Thu_Feb_29_09_19_54_2024_640)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="v14-0003-Row-pattern-recognition-patch-rewriter.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH v9 04/10] lwlock: Invert meaning of LW_FLAG_RELEASE_OK @ 2026-01-06 01:40 Andres Freund <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Andres Freund @ 2026-01-06 01:40 UTC (permalink / raw) Instead of setting a flag whenever a lock release is supposed to wake up waiters - the majority of the time - set a flag whenever wakeups are inhibited. The motivation for this that in an upcoming commit, buffer content locks are implemented separately from lwlocks, and for buffer content locks it is useful to be able to reset all buffer flags when a buffer invalidated, alternatively we would have to set the release-ok flag when making a buffer valid. It seems good to keep the implementation of lwlocks and buffer content locks as similar as reasonably possible. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch: --- src/backend/storage/lmgr/lwlock.c | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 6a9f86d5025..148309cc186 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -92,7 +92,7 @@ #define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31) -#define LW_FLAG_RELEASE_OK ((uint32) 1 << 30) +#define LW_FLAG_WAKE_IN_PROGRESS ((uint32) 1 << 30) #define LW_FLAG_LOCKED ((uint32) 1 << 29) #define LW_FLAG_BITS 3 #define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS)) @@ -246,14 +246,14 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode) ereport(LOG, (errhidestmt(true), errhidecontext(true), - errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u rOK %d", + errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u waking %d", MyProcPid, where, T_NAME(lock), lock, (state & LW_VAL_EXCLUSIVE) != 0, state & LW_SHARED_MASK, (state & LW_FLAG_HAS_WAITERS) != 0, pg_atomic_read_u32(&lock->nwaiters), - (state & LW_FLAG_RELEASE_OK) != 0))); + (state & LW_FLAG_WAKE_IN_PROGRESS) != 0))); } } @@ -700,7 +700,7 @@ LWLockInitialize(LWLock *lock, int tranche_id) /* verify the tranche_id is valid */ (void) GetLWTrancheName(tranche_id); - pg_atomic_init_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_init_u32(&lock->state, 0); #ifdef LOCK_DEBUG pg_atomic_init_u32(&lock->nwaiters, 0); #endif @@ -929,15 +929,13 @@ LWLockWaitListUnlock(LWLock *lock) static void LWLockWakeup(LWLock *lock) { - bool new_release_ok; + bool new_release_in_progress = false; bool wokeup_somebody = false; proclist_head wakeup; proclist_mutable_iter iter; proclist_init(&wakeup); - new_release_ok = true; - /* lock wait list while collecting backends to wake up */ LWLockWaitListLock(lock); @@ -958,7 +956,7 @@ LWLockWakeup(LWLock *lock) * that are just waiting for the lock to become free don't retry * automatically. */ - new_release_ok = false; + new_release_in_progress = true; /* * Don't wakeup (further) exclusive locks. @@ -997,10 +995,10 @@ LWLockWakeup(LWLock *lock) /* compute desired flags */ - if (new_release_ok) - desired_state |= LW_FLAG_RELEASE_OK; + if (new_release_in_progress) + desired_state |= LW_FLAG_WAKE_IN_PROGRESS; else - desired_state &= ~LW_FLAG_RELEASE_OK; + desired_state &= ~LW_FLAG_WAKE_IN_PROGRESS; if (proclist_is_empty(&lock->waiters)) desired_state &= ~LW_FLAG_HAS_WAITERS; @@ -1131,10 +1129,10 @@ LWLockDequeueSelf(LWLock *lock) */ /* - * Reset RELEASE_OK flag if somebody woke us before we removed - * ourselves - they'll have set it to false. + * Clear LW_FLAG_WAKE_IN_PROGRESS if somebody woke us before we + * removed ourselves - they'll have set it. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * Now wait for the scheduled wakeup, otherwise our ->lwWaiting would @@ -1301,7 +1299,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode) } /* Retrying, allow LWLockRelease to release waiters again. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); #ifdef LOCK_DEBUG { @@ -1636,10 +1634,10 @@ LWLockWaitForVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, LWLockQueueSelf(lock, LW_WAIT_UNTIL_FREE); /* - * Set RELEASE_OK flag, to make sure we get woken up as soon as the - * lock is released. + * Clear LW_FLAG_WAKE_IN_PROGRESS flag, to make sure we get woken up + * as soon as the lock is released. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * We're now guaranteed to be woken up if necessary. Recheck the lock @@ -1852,11 +1850,11 @@ LWLockReleaseInternal(LWLock *lock, LWLockMode mode) TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock)); /* - * We're still waiting for backends to get scheduled, don't wake them up - * again. + * Check if we're still waiting for backends to get scheduled, if so, + * don't wake them up again. */ - if ((oldstate & (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK)) == - (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK) && + if ((oldstate & LW_FLAG_HAS_WAITERS) && + !(oldstate & LW_FLAG_WAKE_IN_PROGRESS) && (oldstate & LW_LOCK_MASK) == 0) check_waiters = true; else -- 2.48.1.76.g4e746b1a31.dirty --rkiyqpij3ajqn7ww Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0005-bufmgr-Make-definitions-related-to-buffer-descrip.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH v9 04/10] lwlock: Invert meaning of LW_FLAG_RELEASE_OK @ 2026-01-06 01:40 Andres Freund <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Andres Freund @ 2026-01-06 01:40 UTC (permalink / raw) Instead of setting a flag whenever a lock release is supposed to wake up waiters - the majority of the time - set a flag whenever wakeups are inhibited. The motivation for this that in an upcoming commit, buffer content locks are implemented separately from lwlocks, and for buffer content locks it is useful to be able to reset all buffer flags when a buffer invalidated, alternatively we would have to set the release-ok flag when making a buffer valid. It seems good to keep the implementation of lwlocks and buffer content locks as similar as reasonably possible. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch: --- src/backend/storage/lmgr/lwlock.c | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 6a9f86d5025..148309cc186 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -92,7 +92,7 @@ #define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31) -#define LW_FLAG_RELEASE_OK ((uint32) 1 << 30) +#define LW_FLAG_WAKE_IN_PROGRESS ((uint32) 1 << 30) #define LW_FLAG_LOCKED ((uint32) 1 << 29) #define LW_FLAG_BITS 3 #define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS)) @@ -246,14 +246,14 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode) ereport(LOG, (errhidestmt(true), errhidecontext(true), - errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u rOK %d", + errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u waking %d", MyProcPid, where, T_NAME(lock), lock, (state & LW_VAL_EXCLUSIVE) != 0, state & LW_SHARED_MASK, (state & LW_FLAG_HAS_WAITERS) != 0, pg_atomic_read_u32(&lock->nwaiters), - (state & LW_FLAG_RELEASE_OK) != 0))); + (state & LW_FLAG_WAKE_IN_PROGRESS) != 0))); } } @@ -700,7 +700,7 @@ LWLockInitialize(LWLock *lock, int tranche_id) /* verify the tranche_id is valid */ (void) GetLWTrancheName(tranche_id); - pg_atomic_init_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_init_u32(&lock->state, 0); #ifdef LOCK_DEBUG pg_atomic_init_u32(&lock->nwaiters, 0); #endif @@ -929,15 +929,13 @@ LWLockWaitListUnlock(LWLock *lock) static void LWLockWakeup(LWLock *lock) { - bool new_release_ok; + bool new_release_in_progress = false; bool wokeup_somebody = false; proclist_head wakeup; proclist_mutable_iter iter; proclist_init(&wakeup); - new_release_ok = true; - /* lock wait list while collecting backends to wake up */ LWLockWaitListLock(lock); @@ -958,7 +956,7 @@ LWLockWakeup(LWLock *lock) * that are just waiting for the lock to become free don't retry * automatically. */ - new_release_ok = false; + new_release_in_progress = true; /* * Don't wakeup (further) exclusive locks. @@ -997,10 +995,10 @@ LWLockWakeup(LWLock *lock) /* compute desired flags */ - if (new_release_ok) - desired_state |= LW_FLAG_RELEASE_OK; + if (new_release_in_progress) + desired_state |= LW_FLAG_WAKE_IN_PROGRESS; else - desired_state &= ~LW_FLAG_RELEASE_OK; + desired_state &= ~LW_FLAG_WAKE_IN_PROGRESS; if (proclist_is_empty(&lock->waiters)) desired_state &= ~LW_FLAG_HAS_WAITERS; @@ -1131,10 +1129,10 @@ LWLockDequeueSelf(LWLock *lock) */ /* - * Reset RELEASE_OK flag if somebody woke us before we removed - * ourselves - they'll have set it to false. + * Clear LW_FLAG_WAKE_IN_PROGRESS if somebody woke us before we + * removed ourselves - they'll have set it. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * Now wait for the scheduled wakeup, otherwise our ->lwWaiting would @@ -1301,7 +1299,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode) } /* Retrying, allow LWLockRelease to release waiters again. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); #ifdef LOCK_DEBUG { @@ -1636,10 +1634,10 @@ LWLockWaitForVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, LWLockQueueSelf(lock, LW_WAIT_UNTIL_FREE); /* - * Set RELEASE_OK flag, to make sure we get woken up as soon as the - * lock is released. + * Clear LW_FLAG_WAKE_IN_PROGRESS flag, to make sure we get woken up + * as soon as the lock is released. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * We're now guaranteed to be woken up if necessary. Recheck the lock @@ -1852,11 +1850,11 @@ LWLockReleaseInternal(LWLock *lock, LWLockMode mode) TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock)); /* - * We're still waiting for backends to get scheduled, don't wake them up - * again. + * Check if we're still waiting for backends to get scheduled, if so, + * don't wake them up again. */ - if ((oldstate & (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK)) == - (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK) && + if ((oldstate & LW_FLAG_HAS_WAITERS) && + !(oldstate & LW_FLAG_WAKE_IN_PROGRESS) && (oldstate & LW_LOCK_MASK) == 0) check_waiters = true; else -- 2.48.1.76.g4e746b1a31.dirty --rkiyqpij3ajqn7ww Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0005-bufmgr-Make-definitions-related-to-buffer-descrip.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH v10 1/8] lwlock: Invert meaning of LW_FLAG_RELEASE_OK @ 2026-01-06 01:40 Andres Freund <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Andres Freund @ 2026-01-06 01:40 UTC (permalink / raw) Previously, a flag was set to indicate that a lock release should wake up waiters. Since waking waiters is the default behavior in the majority of cases, this logic has been inverted. The new LW_FLAG_WAKE_IN_PROGRESS flag is now set iff wakeups are explicitly inhibited. The motivation for this change is that in an upcoming commit, content locks will be implemented independently of lwlocks, with the lock state stored as part of BufferDesc.state. As all of a buffer's flags are cleared when the buffer is invalidated, without this change we would have to re-add the RELEASE_OK flag after clearing the flags; otherwise, the next lock release would not wake waiters. It seems good to keep the implementation of lwlocks and buffer content locks as similar as reasonably possible. Discussion: https://postgr.es/m/4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf --- src/backend/storage/lmgr/lwlock.c | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 6a9f86d5025..148309cc186 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -92,7 +92,7 @@ #define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31) -#define LW_FLAG_RELEASE_OK ((uint32) 1 << 30) +#define LW_FLAG_WAKE_IN_PROGRESS ((uint32) 1 << 30) #define LW_FLAG_LOCKED ((uint32) 1 << 29) #define LW_FLAG_BITS 3 #define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS)) @@ -246,14 +246,14 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode) ereport(LOG, (errhidestmt(true), errhidecontext(true), - errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u rOK %d", + errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u waking %d", MyProcPid, where, T_NAME(lock), lock, (state & LW_VAL_EXCLUSIVE) != 0, state & LW_SHARED_MASK, (state & LW_FLAG_HAS_WAITERS) != 0, pg_atomic_read_u32(&lock->nwaiters), - (state & LW_FLAG_RELEASE_OK) != 0))); + (state & LW_FLAG_WAKE_IN_PROGRESS) != 0))); } } @@ -700,7 +700,7 @@ LWLockInitialize(LWLock *lock, int tranche_id) /* verify the tranche_id is valid */ (void) GetLWTrancheName(tranche_id); - pg_atomic_init_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_init_u32(&lock->state, 0); #ifdef LOCK_DEBUG pg_atomic_init_u32(&lock->nwaiters, 0); #endif @@ -929,15 +929,13 @@ LWLockWaitListUnlock(LWLock *lock) static void LWLockWakeup(LWLock *lock) { - bool new_release_ok; + bool new_release_in_progress = false; bool wokeup_somebody = false; proclist_head wakeup; proclist_mutable_iter iter; proclist_init(&wakeup); - new_release_ok = true; - /* lock wait list while collecting backends to wake up */ LWLockWaitListLock(lock); @@ -958,7 +956,7 @@ LWLockWakeup(LWLock *lock) * that are just waiting for the lock to become free don't retry * automatically. */ - new_release_ok = false; + new_release_in_progress = true; /* * Don't wakeup (further) exclusive locks. @@ -997,10 +995,10 @@ LWLockWakeup(LWLock *lock) /* compute desired flags */ - if (new_release_ok) - desired_state |= LW_FLAG_RELEASE_OK; + if (new_release_in_progress) + desired_state |= LW_FLAG_WAKE_IN_PROGRESS; else - desired_state &= ~LW_FLAG_RELEASE_OK; + desired_state &= ~LW_FLAG_WAKE_IN_PROGRESS; if (proclist_is_empty(&lock->waiters)) desired_state &= ~LW_FLAG_HAS_WAITERS; @@ -1131,10 +1129,10 @@ LWLockDequeueSelf(LWLock *lock) */ /* - * Reset RELEASE_OK flag if somebody woke us before we removed - * ourselves - they'll have set it to false. + * Clear LW_FLAG_WAKE_IN_PROGRESS if somebody woke us before we + * removed ourselves - they'll have set it. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * Now wait for the scheduled wakeup, otherwise our ->lwWaiting would @@ -1301,7 +1299,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode) } /* Retrying, allow LWLockRelease to release waiters again. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); #ifdef LOCK_DEBUG { @@ -1636,10 +1634,10 @@ LWLockWaitForVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, LWLockQueueSelf(lock, LW_WAIT_UNTIL_FREE); /* - * Set RELEASE_OK flag, to make sure we get woken up as soon as the - * lock is released. + * Clear LW_FLAG_WAKE_IN_PROGRESS flag, to make sure we get woken up + * as soon as the lock is released. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * We're now guaranteed to be woken up if necessary. Recheck the lock @@ -1852,11 +1850,11 @@ LWLockReleaseInternal(LWLock *lock, LWLockMode mode) TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock)); /* - * We're still waiting for backends to get scheduled, don't wake them up - * again. + * Check if we're still waiting for backends to get scheduled, if so, + * don't wake them up again. */ - if ((oldstate & (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK)) == - (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK) && + if ((oldstate & LW_FLAG_HAS_WAITERS) && + !(oldstate & LW_FLAG_WAKE_IN_PROGRESS) && (oldstate & LW_LOCK_MASK) == 0) check_waiters = true; else -- 2.48.1.76.g4e746b1a31.dirty --jmawlk4t5yqwiemy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v10-0002-bufmgr-Make-definitions-related-to-buffer-descri.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
* [PATCH v10 1/8] lwlock: Invert meaning of LW_FLAG_RELEASE_OK @ 2026-01-06 01:40 Andres Freund <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Andres Freund @ 2026-01-06 01:40 UTC (permalink / raw) Previously, a flag was set to indicate that a lock release should wake up waiters. Since waking waiters is the default behavior in the majority of cases, this logic has been inverted. The new LW_FLAG_WAKE_IN_PROGRESS flag is now set iff wakeups are explicitly inhibited. The motivation for this change is that in an upcoming commit, content locks will be implemented independently of lwlocks, with the lock state stored as part of BufferDesc.state. As all of a buffer's flags are cleared when the buffer is invalidated, without this change we would have to re-add the RELEASE_OK flag after clearing the flags; otherwise, the next lock release would not wake waiters. It seems good to keep the implementation of lwlocks and buffer content locks as similar as reasonably possible. Discussion: https://postgr.es/m/4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf --- src/backend/storage/lmgr/lwlock.c | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 6a9f86d5025..148309cc186 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -92,7 +92,7 @@ #define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31) -#define LW_FLAG_RELEASE_OK ((uint32) 1 << 30) +#define LW_FLAG_WAKE_IN_PROGRESS ((uint32) 1 << 30) #define LW_FLAG_LOCKED ((uint32) 1 << 29) #define LW_FLAG_BITS 3 #define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS)) @@ -246,14 +246,14 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode) ereport(LOG, (errhidestmt(true), errhidecontext(true), - errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u rOK %d", + errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u waking %d", MyProcPid, where, T_NAME(lock), lock, (state & LW_VAL_EXCLUSIVE) != 0, state & LW_SHARED_MASK, (state & LW_FLAG_HAS_WAITERS) != 0, pg_atomic_read_u32(&lock->nwaiters), - (state & LW_FLAG_RELEASE_OK) != 0))); + (state & LW_FLAG_WAKE_IN_PROGRESS) != 0))); } } @@ -700,7 +700,7 @@ LWLockInitialize(LWLock *lock, int tranche_id) /* verify the tranche_id is valid */ (void) GetLWTrancheName(tranche_id); - pg_atomic_init_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_init_u32(&lock->state, 0); #ifdef LOCK_DEBUG pg_atomic_init_u32(&lock->nwaiters, 0); #endif @@ -929,15 +929,13 @@ LWLockWaitListUnlock(LWLock *lock) static void LWLockWakeup(LWLock *lock) { - bool new_release_ok; + bool new_release_in_progress = false; bool wokeup_somebody = false; proclist_head wakeup; proclist_mutable_iter iter; proclist_init(&wakeup); - new_release_ok = true; - /* lock wait list while collecting backends to wake up */ LWLockWaitListLock(lock); @@ -958,7 +956,7 @@ LWLockWakeup(LWLock *lock) * that are just waiting for the lock to become free don't retry * automatically. */ - new_release_ok = false; + new_release_in_progress = true; /* * Don't wakeup (further) exclusive locks. @@ -997,10 +995,10 @@ LWLockWakeup(LWLock *lock) /* compute desired flags */ - if (new_release_ok) - desired_state |= LW_FLAG_RELEASE_OK; + if (new_release_in_progress) + desired_state |= LW_FLAG_WAKE_IN_PROGRESS; else - desired_state &= ~LW_FLAG_RELEASE_OK; + desired_state &= ~LW_FLAG_WAKE_IN_PROGRESS; if (proclist_is_empty(&lock->waiters)) desired_state &= ~LW_FLAG_HAS_WAITERS; @@ -1131,10 +1129,10 @@ LWLockDequeueSelf(LWLock *lock) */ /* - * Reset RELEASE_OK flag if somebody woke us before we removed - * ourselves - they'll have set it to false. + * Clear LW_FLAG_WAKE_IN_PROGRESS if somebody woke us before we + * removed ourselves - they'll have set it. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * Now wait for the scheduled wakeup, otherwise our ->lwWaiting would @@ -1301,7 +1299,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode) } /* Retrying, allow LWLockRelease to release waiters again. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); #ifdef LOCK_DEBUG { @@ -1636,10 +1634,10 @@ LWLockWaitForVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, LWLockQueueSelf(lock, LW_WAIT_UNTIL_FREE); /* - * Set RELEASE_OK flag, to make sure we get woken up as soon as the - * lock is released. + * Clear LW_FLAG_WAKE_IN_PROGRESS flag, to make sure we get woken up + * as soon as the lock is released. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * We're now guaranteed to be woken up if necessary. Recheck the lock @@ -1852,11 +1850,11 @@ LWLockReleaseInternal(LWLock *lock, LWLockMode mode) TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock)); /* - * We're still waiting for backends to get scheduled, don't wake them up - * again. + * Check if we're still waiting for backends to get scheduled, if so, + * don't wake them up again. */ - if ((oldstate & (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK)) == - (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK) && + if ((oldstate & LW_FLAG_HAS_WAITERS) && + !(oldstate & LW_FLAG_WAKE_IN_PROGRESS) && (oldstate & LW_LOCK_MASK) == 0) check_waiters = true; else -- 2.48.1.76.g4e746b1a31.dirty --jmawlk4t5yqwiemy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v10-0002-bufmgr-Make-definitions-related-to-buffer-descri.patch" ^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2026-01-06 01:40 UTC | newest] Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-05-20 17:57 [PATCH v3 06/12] consistent language: not implemented Justin Pryzby <[email protected]> 2019-05-20 17:57 [PATCH v5 06/12] consistent language: not implemented Justin Pryzby <[email protected]> 2023-07-12 12:19 [PATCH] Document RelationGetIndexAttrBitmap better Alvaro Herrera <[email protected]> 2023-07-12 12:19 [PATCH] Document RelationGetIndexAttrBitmap better Alvaro Herrera <[email protected]> 2023-07-12 12:19 [PATCH] Document RelationGetIndexAttrBitmap better Alvaro Herrera <[email protected]> 2024-02-28 13:59 [PATCH v14 2/8] Row pattern recognition patch (parse/analysis). Tatsuo Ishii <[email protected]> 2026-01-06 01:40 [PATCH v9 04/10] lwlock: Invert meaning of LW_FLAG_RELEASE_OK Andres Freund <[email protected]> 2026-01-06 01:40 [PATCH v9 04/10] lwlock: Invert meaning of LW_FLAG_RELEASE_OK Andres Freund <[email protected]> 2026-01-06 01:40 [PATCH v10 1/8] lwlock: Invert meaning of LW_FLAG_RELEASE_OK Andres Freund <[email protected]> 2026-01-06 01:40 [PATCH v10 1/8] lwlock: Invert meaning of LW_FLAG_RELEASE_OK Andres Freund <[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