Skip to content

[pull] master from postgres:master #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/isn/isn.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ string2ean(const char *str, struct Node *escontext, ean13 *result,
if (type != INVALID)
goto eaninvalid;
type = ISSN;
*aux1++ = pg_ascii_toupper((unsigned char) *aux2);
*aux1++ = toupper((unsigned char) *aux2);
length++;
}
else if (length == 9 && (digit || *aux2 == 'X' || *aux2 == 'x') && last)
Expand All @@ -736,7 +736,7 @@ string2ean(const char *str, struct Node *escontext, ean13 *result,
goto eaninvalid;
if (type == INVALID)
type = ISBN; /* ISMN must start with 'M' */
*aux1++ = pg_ascii_toupper((unsigned char) *aux2);
*aux1++ = toupper((unsigned char) *aux2);
length++;
}
else if (length == 11 && digit && last)
Expand Down
12 changes: 6 additions & 6 deletions contrib/pg_overexplain/expected/pg_overexplain.out
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EXPLAIN (DEBUG) SELECT 1;
Subplans Needing Rewind: none
Relation OIDs: none
Executor Parameter Types: none
Parse Location: 16 for 8 bytes
Parse Location: 0 to end
(11 rows)

EXPLAIN (RANGE_TABLE) SELECT 1;
Expand Down Expand Up @@ -119,7 +119,7 @@ $$);
Subplans Needing Rewind: none
Relation OIDs: NNN...
Executor Parameter Types: none
Parse Location: 41 to end
Parse Location: 0 to end
RTI 1 (relation, inherited, in-from-clause):
Eref: vegetables (id, name, genus)
Relation: vegetables
Expand Down Expand Up @@ -240,7 +240,7 @@ $$);
<Subplans-Needing-Rewind>none</Subplans-Needing-Rewind> +
<Relation-OIDs>NNN...</Relation-OIDs> +
<Executor-Parameter-Types>none</Executor-Parameter-Types> +
<Parse-Location>53 to end</Parse-Location> +
<Parse-Location>0 to end</Parse-Location> +
</PlannedStmt> +
<Range-Table> +
<Range-Table-Entry> +
Expand Down Expand Up @@ -344,7 +344,7 @@ $$);
Subplans Needing Rewind: none
Relation OIDs: NNN...
Executor Parameter Types: none
Parse Location: 28 to end
Parse Location: 0 to end
(37 rows)

SET debug_parallel_query = false;
Expand Down Expand Up @@ -372,7 +372,7 @@ $$);
Subplans Needing Rewind: none
Relation OIDs: NNN...
Executor Parameter Types: 0
Parse Location: 28 to end
Parse Location: 0 to end
(15 rows)

-- Create an index, and then attempt to force a nested loop with inner index
Expand Down Expand Up @@ -436,7 +436,7 @@ $$);
Subplans Needing Rewind: none
Relation OIDs: NNN...
Executor Parameter Types: 23
Parse Location: 75 for 62 bytes
Parse Location: 0 to end
(47 rows)

RESET enable_hashjoin;
Expand Down
182 changes: 93 additions & 89 deletions contrib/pg_stat_statements/expected/level_tracking.out

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions contrib/pg_stat_statements/expected/planning.out
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SELECT 42;
(1 row)

SELECT plans, calls, rows, query FROM pg_stat_statements
WHERE query NOT LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C";
WHERE query NOT LIKE 'PREPARE%' ORDER BY query COLLATE "C";
plans | calls | rows | query
-------+-------+------+----------------------------------------------------------
0 | 1 | 0 | ALTER TABLE stats_plan_test ADD COLUMN x int
Expand All @@ -72,10 +72,10 @@ SELECT plans, calls, rows, query FROM pg_stat_statements
-- for the prepared statement we expect at least one replan, but cache
-- invalidations could force more
SELECT plans >= 2 AND plans <= calls AS plans_ok, calls, rows, query FROM pg_stat_statements
WHERE query LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C";
plans_ok | calls | rows | query
----------+-------+------+--------------------------------------
t | 4 | 4 | SELECT COUNT(*) FROM stats_plan_test
WHERE query LIKE 'PREPARE%' ORDER BY query COLLATE "C";
plans_ok | calls | rows | query
----------+-------+------+-------------------------------------------------------
t | 4 | 4 | PREPARE prep1 AS SELECT COUNT(*) FROM stats_plan_test
(1 row)

-- Cleanup
Expand Down
2 changes: 1 addition & 1 deletion contrib/pg_stat_statements/expected/select.out
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ DEALLOCATE pgss_test;
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
calls | rows | query
-------+------+------------------------------------------------------------------------------
1 | 1 | PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3
4 | 4 | SELECT $1 +
| | -- but this one will appear +
| | AS "text"
Expand All @@ -221,7 +222,6 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
2 | 2 | SELECT $1 AS "int" ORDER BY 1
1 | 2 | SELECT $1 AS i UNION SELECT $2 ORDER BY i
1 | 1 | SELECT $1 || $2
1 | 1 | SELECT $1, $2 LIMIT $3
2 | 2 | SELECT DISTINCT $1 AS "int"
0 | 0 | SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C"
1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
Expand Down
2 changes: 1 addition & 1 deletion contrib/pg_stat_statements/expected/utility.out
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
-------+------+----------------------------------------------------
2 | 0 | DEALLOCATE $1
2 | 0 | DEALLOCATE ALL
2 | 2 | SELECT $1 AS a
2 | 2 | PREPARE stat_select AS SELECT $1 AS a
1 | 1 | SELECT $1 as a
1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
(5 rows)
Expand Down
4 changes: 2 additions & 2 deletions contrib/pg_stat_statements/sql/planning.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ SELECT 42;
SELECT 42;
SELECT 42;
SELECT plans, calls, rows, query FROM pg_stat_statements
WHERE query NOT LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C";
WHERE query NOT LIKE 'PREPARE%' ORDER BY query COLLATE "C";
-- for the prepared statement we expect at least one replan, but cache
-- invalidations could force more
SELECT plans >= 2 AND plans <= calls AS plans_ok, calls, rows, query FROM pg_stat_statements
WHERE query LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C";
WHERE query LIKE 'PREPARE%' ORDER BY query COLLATE "C";

-- Cleanup
DROP TABLE stats_plan_test;
Expand Down
2 changes: 1 addition & 1 deletion contrib/spi/refint.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
if (nrefs < 1)
/* internal error */
elog(ERROR, "check_foreign_key: %d (< 1) number of references specified", nrefs);
action = pg_ascii_tolower((unsigned char) *(args[1]));
action = tolower((unsigned char) *(args[1]));
if (action != 'r' && action != 'c' && action != 's')
/* internal error */
elog(ERROR, "check_foreign_key: invalid action %s", args[1]);
Expand Down
25 changes: 16 additions & 9 deletions src/backend/access/nbtree/nbtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static bool _bt_check_compare(IndexScanDesc scan, ScanDirection dir,
bool *continuescan, int *ikey);
static bool _bt_check_rowcompare(ScanKey skey,
IndexTuple tuple, int tupnatts, TupleDesc tupdesc,
ScanDirection dir, bool *continuescan);
ScanDirection dir, bool forcenonrequired, bool *continuescan);
static void _bt_checkkeys_look_ahead(IndexScanDesc scan, BTReadPageState *pstate,
int tupnatts, TupleDesc tupdesc);
static int _bt_keep_natts(Relation rel, IndexTuple lastleft,
Expand Down Expand Up @@ -2902,10 +2902,8 @@ _bt_check_compare(IndexScanDesc scan, ScanDirection dir,
/* row-comparison keys need special processing */
if (key->sk_flags & SK_ROW_HEADER)
{
Assert(!forcenonrequired); /* forbidden by _bt_set_startikey */

if (_bt_check_rowcompare(key, tuple, tupnatts, tupdesc, dir,
continuescan))
forcenonrequired, continuescan))
continue;
return false;
}
Expand Down Expand Up @@ -3062,7 +3060,8 @@ _bt_check_compare(IndexScanDesc scan, ScanDirection dir,
*/
static bool
_bt_check_rowcompare(ScanKey skey, IndexTuple tuple, int tupnatts,
TupleDesc tupdesc, ScanDirection dir, bool *continuescan)
TupleDesc tupdesc, ScanDirection dir,
bool forcenonrequired, bool *continuescan)
{
ScanKey subkey = (ScanKey) DatumGetPointer(skey->sk_argument);
int32 cmpresult = 0;
Expand Down Expand Up @@ -3102,7 +3101,11 @@ _bt_check_rowcompare(ScanKey skey, IndexTuple tuple, int tupnatts,

if (isNull)
{
if (subkey->sk_flags & SK_BT_NULLS_FIRST)
if (forcenonrequired)
{
/* treating scan's keys as non-required */
}
else if (subkey->sk_flags & SK_BT_NULLS_FIRST)
{
/*
* Since NULLs are sorted before non-NULLs, we know we have
Expand Down Expand Up @@ -3156,8 +3159,12 @@ _bt_check_rowcompare(ScanKey skey, IndexTuple tuple, int tupnatts,
*/
Assert(subkey != (ScanKey) DatumGetPointer(skey->sk_argument));
subkey--;
if ((subkey->sk_flags & SK_BT_REQFWD) &&
ScanDirectionIsForward(dir))
if (forcenonrequired)
{
/* treating scan's keys as non-required */
}
else if ((subkey->sk_flags & SK_BT_REQFWD) &&
ScanDirectionIsForward(dir))
*continuescan = false;
else if ((subkey->sk_flags & SK_BT_REQBKWD) &&
ScanDirectionIsBackward(dir))
Expand Down Expand Up @@ -3209,7 +3216,7 @@ _bt_check_rowcompare(ScanKey skey, IndexTuple tuple, int tupnatts,
break;
}

if (!result)
if (!result && !forcenonrequired)
{
/*
* Tuple fails this qual. If it's a required qual for the current
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/copyfromparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ GetDecimalFromHex(char hex)
if (isdigit((unsigned char) hex))
return hex - '0';
else
return pg_ascii_tolower((unsigned char) hex) - 'a' + 10;
return tolower((unsigned char) hex) - 'a' + 10;
}

/*
Expand Down
90 changes: 5 additions & 85 deletions src/backend/parser/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,103 +238,24 @@ parse_sub_analyze(Node *parseTree, ParseState *parentParseState,
return query;
}

/*
* setQueryLocationAndLength
* Set query's location and length from statement and ParseState
*
* Some statements, like PreparableStmt, can be located within parentheses.
* For example "(SELECT 1)" or "COPY (UPDATE ...) to x;". For those, we
* cannot use the whole string from the statement's location or the SQL
* string would yield incorrectly. The parser will set stmt_len, reflecting
* the size of the statement within the parentheses. Thus, when stmt_len is
* available, we need to use it for the Query's stmt_len.
*
* For other cases, the parser can't provide the length of individual
* statements. However, we have the statement's location plus the length
* (p_stmt_len) and location (p_stmt_location) of the top level RawStmt,
* stored in pstate. Thus, the statement's length is the RawStmt's length
* minus how much we've advanced in the RawStmt's string. If p_stmt_len
* is 0, the SQL string is used up to its end.
*/
static void
setQueryLocationAndLength(ParseState *pstate, Query *qry, Node *parseTree)
{
ParseLoc stmt_len = 0;

switch (nodeTag(parseTree))
{
case T_InsertStmt:
qry->stmt_location = ((InsertStmt *) parseTree)->stmt_location;
stmt_len = ((InsertStmt *) parseTree)->stmt_len;
break;

case T_DeleteStmt:
qry->stmt_location = ((DeleteStmt *) parseTree)->stmt_location;
stmt_len = ((DeleteStmt *) parseTree)->stmt_len;
break;

case T_UpdateStmt:
qry->stmt_location = ((UpdateStmt *) parseTree)->stmt_location;
stmt_len = ((UpdateStmt *) parseTree)->stmt_len;
break;

case T_MergeStmt:
qry->stmt_location = ((MergeStmt *) parseTree)->stmt_location;
stmt_len = ((MergeStmt *) parseTree)->stmt_len;
break;

case T_SelectStmt:
qry->stmt_location = ((SelectStmt *) parseTree)->stmt_location;
stmt_len = ((SelectStmt *) parseTree)->stmt_len;
break;

case T_PLAssignStmt:
qry->stmt_location = ((PLAssignStmt *) parseTree)->location;
break;

default:
qry->stmt_location = pstate->p_stmt_location;
break;
}

if (stmt_len > 0)
{
/* Statement's length is known, use it */
qry->stmt_len = stmt_len;
}
else if (pstate->p_stmt_len > 0)
{
/*
* The top RawStmt's length is known, so calculate the statement's
* length from the statement's location and the RawStmt's length and
* location.
*/
qry->stmt_len = pstate->p_stmt_len - (qry->stmt_location - pstate->p_stmt_location);
}

/* The calculated statement length should be calculated as positive. */
Assert(qry->stmt_len >= 0);
}

/*
* transformTopLevelStmt -
* transform a Parse tree into a Query tree.
*
* This function is just responsible for storing location data
* from the RawStmt into the ParseState.
* This function is just responsible for transferring statement location data
* from the RawStmt into the finished Query.
*/
Query *
transformTopLevelStmt(ParseState *pstate, RawStmt *parseTree)
{
Query *result;

/* Store RawStmt's length and location in pstate */
pstate->p_stmt_len = parseTree->stmt_len;
pstate->p_stmt_location = parseTree->stmt_location;

/* We're at top level, so allow SELECT INTO */
result = transformOptionalSelectInto(pstate, parseTree->stmt);

result->stmt_location = parseTree->stmt_location;
result->stmt_len = parseTree->stmt_len;

return result;
}

Expand Down Expand Up @@ -503,7 +424,6 @@ transformStmt(ParseState *pstate, Node *parseTree)
/* Mark as original query until we learn differently */
result->querySource = QSRC_ORIGINAL;
result->canSetTag = true;
setQueryLocationAndLength(pstate, result, parseTree);

return result;
}
Expand Down
Loading