Re: [PATCH] Add support function for containment operators

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Kim Johan Andersson <kimjand@kimmet.dk>, pgsql-hackers@lists.postgresql.org
Date: 2023-10-20T08:24:24Z
Lists: pgsql-hackers

Attachments

On Fri, Oct 20, 2023 at 12:01 AM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> On Fri, 2023-10-13 at 14:26 +0800, jian he wrote:
> > Collation problem seems solved.
>
> I didn't review your patch in detail, there is still a problem
> with my example:
>
>   CREATE TYPE textrange AS RANGE (
>      SUBTYPE = text,
>      SUBTYPE_OPCLASS = text_pattern_ops
>   );
>
>   CREATE TABLE tx (t text COLLATE "cs-CZ-x-icu");
>
>   INSERT INTO tx VALUES ('a'), ('c'), ('d'), ('ch');
>
>   SELECT * FROM tx WHERE t <@ textrange('a', 'd');
>
>    t
>   ════
>    a
>    c
>    ch
>   (3 rows)
>
> That was correct.
>
>   EXPLAIN SELECT * FROM tx WHERE t <@ textrange('a', 'd');
>
>                        QUERY PLAN
>   ════════════════════════════════════════════════════
>    Seq Scan on tx  (cost=0.00..30.40 rows=7 width=32)
>      Filter: ((t >= 'a'::text) AND (t < 'd'::text))
>   (2 rows)
>
> But that was weird.  The operators seem wrong.  Look at that

Thanks for pointing this out!

The problem is that TypeCacheEntry->rngelemtype typcaheentry don't
have the range's SUBTYPE_OPCLASS info.
So in find_simplified_clause, we need to get the range's
SUBTYPE_OPCLASS from the pg_catalog table.
Also in pg_range, column rngsubopc  is not null. so this should be fine.

Commits

  1. Add planner support functions for range operators <@ and @>.