diff --git a/contrib/intarray/Makefile b/contrib/intarray/Makefile new file mode 100644 index 920c5b1..c37aeb9 *** a/contrib/intarray/Makefile --- b/contrib/intarray/Makefile *************** *** 2,8 **** MODULE_big = _int OBJS = _int_bool.o _int_gist.o _int_op.o _int_tool.o \ ! _intbig_gist.o _int_gin.o $(WIN32RES) EXTENSION = intarray DATA = intarray--1.0.sql intarray--unpackaged--1.0.sql --- 2,8 ---- MODULE_big = _int OBJS = _int_bool.o _int_gist.o _int_op.o _int_tool.o \ ! _intbig_gist.o _int_gin.o _int_selfuncs.o $(WIN32RES) EXTENSION = intarray DATA = intarray--1.0.sql intarray--unpackaged--1.0.sql diff --git a/contrib/intarray/_int_selfuncs.c b/contrib/intarray/_int_selfuncs.c new file mode 100644 index ...495aac8 *** a/contrib/intarray/_int_selfuncs.c --- b/contrib/intarray/_int_selfuncs.c *************** *** 0 **** --- 1,83 ---- + /*------------------------------------------------------------------------- + * + * _int_selfuncs.c + * Functions for selectivity estimation of intarray operators + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * contrib/intarray/_int_selfuncs.c + * + *------------------------------------------------------------------------- + */ + #include "postgres.h" + + #include "access/htup_details.h" + #include "catalog/pg_operator.h" + #include "utils/selfuncs.h" + #include "utils/syscache.h" + + PG_FUNCTION_INFO_V1(_int_contsel); + PG_FUNCTION_INFO_V1(_int_contjoinsel); + + Datum _int_contsel(PG_FUNCTION_ARGS); + Datum _int_contjoinsel(PG_FUNCTION_ARGS); + + static Oid transformOperator(Oid oprOid); + + static Oid + transformOperator(Oid oprOid) + { + HeapTuple tup; + Form_pg_operator op; + Oid result = InvalidOid; + + tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(oprOid)); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "Invalid operator: %u", oprOid); + + op = (Form_pg_operator) GETSTRUCT(tup); + + if (!strcmp(op->oprname.data, "&&")) + result = OID_ARRAY_OVERLAP_OP; + else if (!strcmp(op->oprname.data, "@>")) + result = OID_ARRAY_CONTAINS_OP; + else if (!strcmp(op->oprname.data, "<@")) + result = OID_ARRAY_CONTAINED_OP; + + ReleaseSysCache(tup); + + if (!OidIsValid(result)) + elog(ERROR, "Invalid operator: %u", oprOid); + + return result; + } + + /* + * _int_contsel -- restriction selectivity for array @>, &&, <@ operators + */ + Datum + _int_contsel(PG_FUNCTION_ARGS) + { + PG_RETURN_DATUM(DirectFunctionCall4(arraycontsel, + PG_GETARG_DATUM(0), + ObjectIdGetDatum(transformOperator(PG_GETARG_OID(1))), + PG_GETARG_DATUM(2), + PG_GETARG_DATUM(3))); + } + + /* + * _int_contjoinsel -- join selectivity for array @>, &&, <@ operators + */ + Datum + _int_contjoinsel(PG_FUNCTION_ARGS) + { + PG_RETURN_DATUM(DirectFunctionCall5(arraycontjoinsel, + PG_GETARG_DATUM(0), + ObjectIdGetDatum(transformOperator(PG_GETARG_OID(1))), + PG_GETARG_DATUM(2), + PG_GETARG_DATUM(3), + PG_GETARG_DATUM(4))); + } diff --git a/contrib/intarray/intarray--1.0.sql b/contrib/intarray/intarray--1.0.sql new file mode 100644 index 0b89e0f..72fb4c2 *** a/contrib/intarray/intarray--1.0.sql --- b/contrib/intarray/intarray--1.0.sql *************** RETURNS _int4 *** 117,122 **** --- 117,132 ---- AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; + CREATE FUNCTION _int_contsel(internal, oid, internal, integer) + RETURNS float8 + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT STABLE; + + CREATE FUNCTION _int_contjoinsel(internal, oid, internal, smallint, internal) + RETURNS float8 + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT STABLE; + -- -- OPERATORS -- *************** CREATE OPERATOR && ( *** 126,133 **** RIGHTARG = _int4, PROCEDURE = _int_overlap, COMMUTATOR = '&&', ! RESTRICT = contsel, ! JOIN = contjoinsel ); --CREATE OPERATOR = ( --- 136,143 ---- RIGHTARG = _int4, PROCEDURE = _int_overlap, COMMUTATOR = '&&', ! RESTRICT = _int_contsel, ! JOIN = _int_contjoinsel ); --CREATE OPERATOR = ( *************** CREATE OPERATOR @> ( *** 157,164 **** RIGHTARG = _int4, PROCEDURE = _int_contains, COMMUTATOR = '<@', ! RESTRICT = contsel, ! JOIN = contjoinsel ); CREATE OPERATOR <@ ( --- 167,174 ---- RIGHTARG = _int4, PROCEDURE = _int_contains, COMMUTATOR = '<@', ! RESTRICT = _int_contsel, ! JOIN = _int_contjoinsel ); CREATE OPERATOR <@ ( *************** CREATE OPERATOR <@ ( *** 166,173 **** RIGHTARG = _int4, PROCEDURE = _int_contained, COMMUTATOR = '@>', ! RESTRICT = contsel, ! JOIN = contjoinsel ); -- obsolete: --- 176,183 ---- RIGHTARG = _int4, PROCEDURE = _int_contained, COMMUTATOR = '@>', ! RESTRICT = _int_contsel, ! JOIN = _int_contjoinsel ); -- obsolete: