postgresql/contrib/ltree/ltree--1.1--1.2.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
5.1 KiB
MySQL
Raw Permalink Normal View History

Implement operator class parameters PostgreSQL provides set of template index access methods, where opclasses have much freedom in the semantics of indexing. These index AMs are GiST, GIN, SP-GiST and BRIN. There opclasses define representation of keys, operations on them and supported search strategies. So, it's natural that opclasses may be faced some tradeoffs, which require user-side decision. This commit implements opclass parameters allowing users to set some values, which tell opclass how to index the particular dataset. This commit doesn't introduce new storage in system catalog. Instead it uses pg_attribute.attoptions, which is used for table column storage options but unused for index attributes. In order to evade changing signature of each opclass support function, we implement unified way to pass options to opclass support functions. Options are set to fn_expr as the constant bytea expression. It's possible due to the fact that opclass support functions are executed outside of expressions, so fn_expr is unused for them. This commit comes with some examples of opclass options usage. We parametrize signature length in GiST. That applies to multiple opclasses: tsvector_ops, gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and gist_hstore_ops. Also we parametrize maximum number of integer ranges for gist__int_ops. However, the main future usage of this feature is expected to be json, where users would be able to specify which way to index particular json parts. Catversion is bumped. Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru Author: Nikita Glukhov, revised by me Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-30 18:17:11 +02:00
/* contrib/ltree/ltree--1.1--1.2.sql */
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ltree UPDATE TO '1.2'" to load this file. \quit
CREATE FUNCTION ltree_recv(internal)
RETURNS ltree
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
CREATE FUNCTION ltree_send(ltree)
RETURNS bytea
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
ALTER TYPE ltree SET ( RECEIVE = ltree_recv, SEND = ltree_send );
CREATE FUNCTION lquery_recv(internal)
RETURNS lquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
CREATE FUNCTION lquery_send(lquery)
RETURNS bytea
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
ALTER TYPE lquery SET ( RECEIVE = lquery_recv, SEND = lquery_send );
CREATE FUNCTION ltxtq_recv(internal)
RETURNS ltxtquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
CREATE FUNCTION ltxtq_send(ltxtquery)
RETURNS bytea
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
ALTER TYPE ltxtquery SET ( RECEIVE = ltxtq_recv, SEND = ltxtq_send );
Implement operator class parameters PostgreSQL provides set of template index access methods, where opclasses have much freedom in the semantics of indexing. These index AMs are GiST, GIN, SP-GiST and BRIN. There opclasses define representation of keys, operations on them and supported search strategies. So, it's natural that opclasses may be faced some tradeoffs, which require user-side decision. This commit implements opclass parameters allowing users to set some values, which tell opclass how to index the particular dataset. This commit doesn't introduce new storage in system catalog. Instead it uses pg_attribute.attoptions, which is used for table column storage options but unused for index attributes. In order to evade changing signature of each opclass support function, we implement unified way to pass options to opclass support functions. Options are set to fn_expr as the constant bytea expression. It's possible due to the fact that opclass support functions are executed outside of expressions, so fn_expr is unused for them. This commit comes with some examples of opclass options usage. We parametrize signature length in GiST. That applies to multiple opclasses: tsvector_ops, gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and gist_hstore_ops. Also we parametrize maximum number of integer ranges for gist__int_ops. However, the main future usage of this feature is expected to be json, where users would be able to specify which way to index particular json parts. Catversion is bumped. Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru Author: Nikita Glukhov, revised by me Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-30 18:17:11 +02:00
CREATE FUNCTION ltree_gist_options(internal)
RETURNS void
AS 'MODULE_PATHNAME', 'ltree_gist_options'
LANGUAGE C IMMUTABLE PARALLEL SAFE;
CREATE FUNCTION _ltree_gist_options(internal)
RETURNS void
AS 'MODULE_PATHNAME', '_ltree_gist_options'
LANGUAGE C IMMUTABLE PARALLEL SAFE;
ALTER OPERATOR FAMILY gist_ltree_ops USING gist
ADD FUNCTION 10 (ltree) ltree_gist_options (internal);
ALTER OPERATOR FAMILY gist__ltree_ops USING gist
ADD FUNCTION 10 (_ltree) _ltree_gist_options (internal);
Improve selectivity estimation for assorted match-style operators. Quite a few matching operators such as JSONB's @> used "contsel" and "contjoinsel" as their selectivity estimators. That was a bad idea, because (a) contsel is only a stub, yielding a fixed default estimate, and (b) that default is 0.001, meaning we estimate these operators as five times more selective than equality, which is surely pretty silly. There's a good model for improving this in ltree's ltreeparentsel(): for any "var OP constant" query, we can try applying the operator to all of the column's MCV and histogram values, taking the latter as being a random sample of the non-MCV values. That code is actually 100% generic, except for the question of exactly what default selectivity ought to be plugged in when we don't have stats. Hence, migrate the guts of ltreeparentsel() into the core code, provide wrappers "matchingsel" and "matchingjoinsel" with a more-appropriate default estimate, and use those for the non-geometric operators that formerly used contsel (mostly JSONB containment operators and tsquery matching). Also apply this code to some match-like operators in hstore, ltree, and pg_trgm, including the former users of ltreeparentsel as well as ones that improperly used contsel. Since commit 911e70207 just created new versions of those extensions that we haven't released yet, we can sneak this change into those new versions instead of having to create an additional generation of update scripts. Patch by me, reviewed by Alexey Bashtanov Discussion: https://postgr.es/m/12237.1582833074@sss.pgh.pa.us
2020-04-01 16:32:33 +02:00
ALTER OPERATOR < (ltree, ltree)
SET (RESTRICT = scalarltsel, JOIN = scalarltjoinsel);
ALTER OPERATOR <= (ltree, ltree)
SET (RESTRICT = scalarlesel, JOIN = scalarlejoinsel);
ALTER OPERATOR >= (ltree, ltree)
SET (RESTRICT = scalargesel, JOIN = scalargejoinsel);
ALTER OPERATOR > (ltree, ltree)
SET (RESTRICT = scalargtsel, JOIN = scalargtjoinsel);
ALTER OPERATOR @> (ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@> (ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR <@ (ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^<@ (ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ~ (ltree, lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ~ (lquery, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^~ (ltree, lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^~ (lquery, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ? (ltree, _lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ? (_lquery, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^? (ltree, _lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^? (_lquery, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR @ (ltree, ltxtquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR @ (ltxtquery, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@ (ltree, ltxtquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@ (ltxtquery, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR @> (_ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR <@ (ltree, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR <@ (_ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR @> (ltree, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ~ (_ltree, lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ~ (lquery, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ? (_ltree, _lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ? (_lquery, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR @ (_ltree, ltxtquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR @ (ltxtquery, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@> (_ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^<@ (ltree, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^<@ (_ltree, ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@> (ltree, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^~ (_ltree, lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^~ (lquery, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^? (_ltree, _lquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^? (_lquery, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@ (_ltree, ltxtquery)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);
ALTER OPERATOR ^@ (ltxtquery, _ltree)
SET (RESTRICT = matchingsel, JOIN = matchingjoinsel);