Re: Extract numeric filed in JSONB more effectively

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Extract numeric filed in JSONB more effectively
Date: 2023-08-21 10:58:05
Message-ID: CAKU4AWphRdQUmdw0cnR8PixYsfoxmncQi9+=8gaEy23MTNmR5w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
>
> Interestingly, when I relabel both places, like this:
>
> Oid targetOid = fexpr->funcresulttype;
> Const *target = makeConst(
> OIDOID, -1, InvalidOid, sizeof(Oid),
> ObjectIdGetDatum(targetOid), false, true);
> RelabelType *rTarget = makeRelabelType((Expr *)target,
> INTERNALOID, -1, InvalidOid, COERCE_IMPLICIT_CAST);
> fexpr->funcid = new_func_id;
> fexpr->args = opexpr->args;
> fexpr->args = list_insert_nth(fexpr->args, 0, rTarget);
> expr = (Expr *)makeRelabelType((Expr *)fexpr,
> targetOid, -1, InvalidOid, COERCE_IMPLICIT_CAST);
> }
> PG_RETURN_POINTER(expr);
>
> EXPLAIN looks like this:
>
> Seq Scan on pg_temp.test_jsonb
> Output: jsonb_array_element_type(('23'::oid)::internal, test_json,
> 0), (test_json -> 0)
> Filter: (test_jsonb.json_type = 'scalarint'::text)
>
> With COERCE_IMPLICIT_CAST both places, the relabeling of the
> function result is invisible, but the relabeling of the argument
> is visible.
>
>
I think this is because get_rule_expr's showimplicit is always
true for args in this case, checking the implementation of
get_rule_expr, I found PG behavior like this in many places.

--
Best Regards
Andy Fan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2023-08-21 11:16:33 Re: postgres_fdw: wrong results with self join + enable_nestloop off
Previous Message Tomas Vondra 2023-08-21 10:56:18 Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500