create view numeric_view as select
f1, f1::numeric(16,4) as f1164, f1::numericas f1n,
f2, f2::numeric(16,4) as f2164, f2::numericas f2n from numeric_tbl;
\d+ numeric_view
explain (verbose, costs off) select * from numeric_view;
-- bpchar, lacking planner support for its length coercion function, -- could behave differently
create view bpchar_view as select
f1, f1::character(14) as f114, f1::bpchar as f1n,
f2, f2::character(14) as f214, f2::bpchar as f2n from bpchar_tbl;
\d+ bpchar_view
explain (verbose, costs off) select * from bpchar_view where f1::bpchar = 'foo';
rollback;
-- -- Ordinarily, IN/NOT IN can be converted to a ScalarArrayOpExpr -- with a suitably-chosen array type. -- explain (verbose, costs off) select random() IN (1, 4, 8.0); explain (verbose, costs off) select random()::intIN (1, 4, 8.0); -- However, if there's not a common supertype for the IN elements, -- we should instead try to produce "x = v1 OR x = v2 OR ...". -- In most cases that'll fail for lack of all the requisite = operators, -- but it can succeed sometimes. So this should complain about lack of -- an = operator, not about cast failure. select'(0,0)'::point in ('(0,0,0,0)'::box, point(0,0));
-- -- Tests for ScalarArrayOpExpr with a hashfn --
-- create a stable function so that the tests below are not -- evaluated using the planner's constant folding.
begin;
create function return_int_input(int) returns intas $$
begin return $1;
end;
$$ language plpgsql stable;
create function return_text_input(text) returns text as $$
begin return $1;
end;
$$ language plpgsql stable;
-- Test with non-strict equality function. -- We need to create our own type for this.
begin;
create type myint; create function myintin(cstring) returns myint strict immutable language
internal as'int4in'; create function myintout(myint) returns cstring strict immutable language
internal as'int4out'; create function myinthash(myint) returns integer strict immutable language
internal as'hashint4';
create type myint (input = myintin, output = myintout, like = int4);
create cast (int4as myint) without function; create cast (myint asint4) without function;
create function myinteq(myint, myint) returns bool as $$
begin if $1isnulland $2isnullthen returntrue; else return $1::int = $2::int;
end if;
end;
$$ language plpgsql immutable;
create function myintne(myint, myint) returns bool as $$
begin returnnot myinteq($1, $2);
end;
$$ language plpgsql immutable;
create operator class myint_ops defaultfor type myint using hash as
operator 1 = (myint, myint),
function 1 myinthash(myint);
createtable inttest (a myint); insertinto inttest values (null), (0::myint), (1::myint);
-- Test EEOP_HASHED_SCALARARRAYOP against EEOP_SCALARARRAYOP. Ensure the -- result of non-hashed vs hashed is the same. select
a,
a in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as not_hashed,
a in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint) as hashed from inttest;
select
a,
a in (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed,
a in (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed from inttest;
select
a,
a notin (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as not_hashed,
a notin (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint) as hashed from inttest;
select
a,
a notin (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed,
a notin (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed from inttest;
-- Now make the equal function return false when given two NULLs createorreplace function myinteq(myint, myint) returns bool as $$
begin if $1isnulland $2isnullthen returnfalse; else return $1::int = $2::int;
end if;
end;
$$ language plpgsql immutable;
-- And try the same again to ensure EEOP_HASHED_SCALARARRAYOP does the same -- thing as EEOP_SCALARARRAYOP. select
a,
a in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as not_hashed,
a in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint) as hashed from inttest;
select
a,
a in (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed,
a in (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed from inttest;
select
a,
a notin (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as not_hashed,
a notin (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint) as hashed from inttest;
select
a,
a notin (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed,
a notin (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed from inttest;
-- Try again with an equality function that treats NULLs as equal to 0. createorreplace function myinteq(myint, myint) returns bool as $$
begin if $1isnulland $2isnullthen returnfalse; else return coalesce($1::int,0) = coalesce($2::int, 0);
end if;
end;
$$ language plpgsql immutable;
select
a,
a in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as not_hashed,
a in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint) as hashed,
a in (0::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed_zero,
a in (0::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed_zero from inttest;
select
a,
a in (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed,
a in (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed from inttest;
select
a,
a notin (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as not_hashed,
a notin (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint) as hashed,
a notin (0::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed_zero,
a notin (0::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed_zero from inttest;
select
a,
a notin (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint) as not_hashed,
a notin (null::myint,1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint) as hashed from inttest;
rollback;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.