postgresql/contrib/citext/citext--1.4--1.5.sql

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

89 lines
2.2 KiB
MySQL
Raw Permalink Normal View History

Distinguish selectivity of < from <= and > from >=. Historically, the selectivity functions have simply not distinguished < from <=, or > from >=, arguing that the fraction of the population that satisfies the "=" aspect can be considered to be vanishingly small, if the comparison value isn't any of the most-common-values for the variable. (If it is, the code path that executes the operator against each MCV will take care of things properly.) But that isn't really true unless we're dealing with a continuum of variable values, and in practice we seldom are. If "x = const" would estimate a nonzero number of rows for a given const value, then it follows that we ought to estimate different numbers of rows for "x < const" and "x <= const", even if the const is not one of the MCVs. Handling this more honestly makes a significant difference in edge cases, such as the estimate for a tight range (x BETWEEN y AND z where y and z are close together). Hence, split scalarltsel into scalarltsel/scalarlesel, and similarly split scalargtsel into scalargtsel/scalargesel. Adjust <= and >= operator definitions to reference the new selectivity functions. Improve the core ineq_histogram_selectivity() function to make a correction for equality. (Along the way, I learned quite a bit about exactly why that function gives good answers, which I tried to memorialize in improved comments.) The corresponding join selectivity functions were, and remain, just stubs. But I chose to split them similarly, to avoid confusion and to prevent the need for doing this exercise again if someone ever makes them less stubby. In passing, change ineq_histogram_selectivity's clamp for extreme probability estimates so that it varies depending on the histogram size, instead of being hardwired at 0.0001. With the default histogram size of 100 entries, you still get the old clamp value, but bigger histograms should allow us to put more faith in edge values. Tom Lane, reviewed by Aleksander Alekseev and Kuntal Ghosh Discussion: https://postgr.es/m/12232.1499140410@sss.pgh.pa.us
2017-09-13 17:12:39 +02:00
/* contrib/citext/citext--1.4--1.5.sql */
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION citext UPDATE TO '1.5'" to load this file. \quit
ALTER OPERATOR <= (citext, citext) SET (
RESTRICT = scalarlesel,
JOIN = scalarlejoinsel
);
ALTER OPERATOR >= (citext, citext) SET (
RESTRICT = scalargesel,
JOIN = scalargejoinsel
);
CREATE FUNCTION citext_pattern_lt( citext, citext )
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION citext_pattern_le( citext, citext )
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION citext_pattern_gt( citext, citext )
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION citext_pattern_ge( citext, citext )
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE OPERATOR ~<~ (
LEFTARG = CITEXT,
RIGHTARG = CITEXT,
NEGATOR = ~>=~,
COMMUTATOR = ~>~,
PROCEDURE = citext_pattern_lt,
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel
);
CREATE OPERATOR ~<=~ (
LEFTARG = CITEXT,
RIGHTARG = CITEXT,
NEGATOR = ~>~,
COMMUTATOR = ~>=~,
PROCEDURE = citext_pattern_le,
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel
);
CREATE OPERATOR ~>=~ (
LEFTARG = CITEXT,
RIGHTARG = CITEXT,
NEGATOR = ~<~,
COMMUTATOR = ~<=~,
PROCEDURE = citext_pattern_ge,
RESTRICT = scalargtsel,
JOIN = scalargtjoinsel
);
CREATE OPERATOR ~>~ (
LEFTARG = CITEXT,
RIGHTARG = CITEXT,
NEGATOR = ~<=~,
COMMUTATOR = ~<~,
PROCEDURE = citext_pattern_gt,
RESTRICT = scalargtsel,
JOIN = scalargtjoinsel
);
CREATE FUNCTION citext_pattern_cmp(citext, citext)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
CREATE OPERATOR CLASS citext_pattern_ops
FOR TYPE CITEXT USING btree AS
OPERATOR 1 ~<~ (citext, citext),
OPERATOR 2 ~<=~ (citext, citext),
OPERATOR 3 = (citext, citext),
OPERATOR 4 ~>=~ (citext, citext),
OPERATOR 5 ~>~ (citext, citext),
FUNCTION 1 citext_pattern_cmp(citext, citext);