Improving row estimates for query with jsonb_object_keys() I have a query that looks something like this:
SELECT jsonb_object_keys(json) AS key,
       json
FROM (
       SELECT json_object -&gt; 'some_key' AS json
       FROM my_json_table
     ) j;

The planner currently estimates 100 rows to be returned by the jsonb_object_keys call for each from the inner query. In my case, it's 2. Since this underlies some larger queries in my database, it's critical that I get a better row estimate.
I would like to avoid creating a materialized view. Is there another approach to improve the query plan?
A super-user can do:
alter function jsonb_object_keys ( jsonb) rows 2;

But this will change the estimate for all uses of jsonb_object_keys in that database, not just that one use of it.
If you don't like that, you could duplicate the function and change the duplicate:
CREATE OR REPLACE FUNCTION jsonb_object_keys2(jsonb)
 RETURNS SETOF text
 LANGUAGE internal
 IMMUTABLE PARALLEL SAFE STRICT ROWS 2
AS $function$jsonb_object_keys$function$;