mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Improve the implementation of information_schema._pg_expandarray().
This function was originally coded with a handmade expansion of the array subscripts. We can do it a little faster and far more legibly today, by using unnest() WITH ORDINALITY. While at it, let's apply the rowcount estimation support that exists for the underlying unnest() function: reduce the default ROWS estimate to 100 and attach array_unnest_support. I'm not sure that array_unnest_support can do anything useful today with the call sites that exist in information_schema, but it can't hurt, and the existing default rowcount of 1000 is surely much too high for any of these cases. The psql.sql regression script is using _pg_expandarray() as a test case for \sf+. While we could keep doing so, the new one-line function body makes a poor test case for \sf+ row-numbering, so switch it to print another information_schema function. Discussion: https://postgr.es/m/1424303.1703355485@sss.pgh.pa.us
This commit is contained in:
parent
6c361d323b
commit
58054de2d0
@ -43,11 +43,8 @@ SET search_path TO information_schema;
|
|||||||
CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int)
|
CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int)
|
||||||
RETURNS SETOF RECORD
|
RETURNS SETOF RECORD
|
||||||
LANGUAGE sql STRICT IMMUTABLE PARALLEL SAFE
|
LANGUAGE sql STRICT IMMUTABLE PARALLEL SAFE
|
||||||
AS 'select $1[s],
|
ROWS 100 SUPPORT pg_catalog.array_unnest_support
|
||||||
s operator(pg_catalog.-) pg_catalog.array_lower($1,1) operator(pg_catalog.+) 1
|
AS 'SELECT * FROM pg_catalog.unnest($1) WITH ORDINALITY';
|
||||||
from pg_catalog.generate_series(pg_catalog.array_lower($1,1),
|
|
||||||
pg_catalog.array_upper($1,1),
|
|
||||||
1) as g(s)';
|
|
||||||
|
|
||||||
/* Given an index's OID and an underlying-table column number, return the
|
/* Given an index's OID and an underlying-table column number, return the
|
||||||
* column's position in the index (NULL if not there) */
|
* column's position in the index (NULL if not there) */
|
||||||
|
@ -6317,6 +6317,9 @@ array_unnest(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Planner support function for array_unnest(anyarray)
|
* Planner support function for array_unnest(anyarray)
|
||||||
|
*
|
||||||
|
* Note: this is now also used for information_schema._pg_expandarray(),
|
||||||
|
* which is simply a wrapper around array_unnest().
|
||||||
*/
|
*/
|
||||||
Datum
|
Datum
|
||||||
array_unnest_support(PG_FUNCTION_ARGS)
|
array_unnest_support(PG_FUNCTION_ARGS)
|
||||||
|
@ -57,6 +57,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 202312251
|
#define CATALOG_VERSION_NO 202312271
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5293,26 +5293,30 @@ comment on function psql_df_plpgsql () is 'some comment';
|
|||||||
rollback;
|
rollback;
|
||||||
drop role regress_psql_user;
|
drop role regress_psql_user;
|
||||||
-- check \sf
|
-- check \sf
|
||||||
\sf information_schema._pg_expandarray
|
\sf information_schema._pg_index_position
|
||||||
CREATE OR REPLACE FUNCTION information_schema._pg_expandarray(anyarray, OUT x anyelement, OUT n integer)
|
CREATE OR REPLACE FUNCTION information_schema._pg_index_position(oid, smallint)
|
||||||
RETURNS SETOF record
|
RETURNS integer
|
||||||
LANGUAGE sql
|
LANGUAGE sql
|
||||||
IMMUTABLE PARALLEL SAFE STRICT
|
STABLE STRICT
|
||||||
AS $function$select $1[s],
|
BEGIN ATOMIC
|
||||||
s operator(pg_catalog.-) pg_catalog.array_lower($1,1) operator(pg_catalog.+) 1
|
SELECT (ss.a).n AS n
|
||||||
from pg_catalog.generate_series(pg_catalog.array_lower($1,1),
|
FROM ( SELECT information_schema._pg_expandarray(pg_index.indkey) AS a
|
||||||
pg_catalog.array_upper($1,1),
|
FROM pg_index
|
||||||
1) as g(s)$function$
|
WHERE (pg_index.indexrelid = $1)) ss
|
||||||
\sf+ information_schema._pg_expandarray
|
WHERE ((ss.a).x = $2);
|
||||||
CREATE OR REPLACE FUNCTION information_schema._pg_expandarray(anyarray, OUT x anyelement, OUT n integer)
|
END
|
||||||
RETURNS SETOF record
|
\sf+ information_schema._pg_index_position
|
||||||
|
CREATE OR REPLACE FUNCTION information_schema._pg_index_position(oid, smallint)
|
||||||
|
RETURNS integer
|
||||||
LANGUAGE sql
|
LANGUAGE sql
|
||||||
IMMUTABLE PARALLEL SAFE STRICT
|
STABLE STRICT
|
||||||
1 AS $function$select $1[s],
|
1 BEGIN ATOMIC
|
||||||
2 s operator(pg_catalog.-) pg_catalog.array_lower($1,1) operator(pg_catalog.+) 1
|
2 SELECT (ss.a).n AS n
|
||||||
3 from pg_catalog.generate_series(pg_catalog.array_lower($1,1),
|
3 FROM ( SELECT information_schema._pg_expandarray(pg_index.indkey) AS a
|
||||||
4 pg_catalog.array_upper($1,1),
|
4 FROM pg_index
|
||||||
5 1) as g(s)$function$
|
5 WHERE (pg_index.indexrelid = $1)) ss
|
||||||
|
6 WHERE ((ss.a).x = $2);
|
||||||
|
7 END
|
||||||
\sf+ interval_pl_time
|
\sf+ interval_pl_time
|
||||||
CREATE OR REPLACE FUNCTION pg_catalog.interval_pl_time(interval, time without time zone)
|
CREATE OR REPLACE FUNCTION pg_catalog.interval_pl_time(interval, time without time zone)
|
||||||
RETURNS time without time zone
|
RETURNS time without time zone
|
||||||
|
@ -1312,8 +1312,8 @@ rollback;
|
|||||||
drop role regress_psql_user;
|
drop role regress_psql_user;
|
||||||
|
|
||||||
-- check \sf
|
-- check \sf
|
||||||
\sf information_schema._pg_expandarray
|
\sf information_schema._pg_index_position
|
||||||
\sf+ information_schema._pg_expandarray
|
\sf+ information_schema._pg_index_position
|
||||||
\sf+ interval_pl_time
|
\sf+ interval_pl_time
|
||||||
\sf ts_debug(text)
|
\sf ts_debug(text)
|
||||||
\sf+ ts_debug(text)
|
\sf+ ts_debug(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user