Thread: ERREUR: cache lookup failed for function 0 with PostgreSQL 15 beta 2, no error with PostgreSQL 14.4

Hi,

A DSS developer from my company, Julien Roze, reported me an error I cannot explained. Is it a new behavior or a bug ?

Original query is much more complicated but here is a simplified test case with postgresql 14 and 15 beta 2 on Debian
11,packages from pgdg : 

Ver Cluster Port Status Owner    Data directory              Log file
14  main    5432 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
15  main    5433 online postgres /var/lib/postgresql/15/main /var/log/postgresql/postgresql-15-main.log

psql -p 5432

select version();
                                                           version
     

-----------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.4 (Debian 14.4-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110,
64-bit
(1 ligne)


with fakedata as (
               select 'hello' word
               union all
               select 'world' word
)
select *
from (
               select word, count(*) over (partition by word) nb from fakedata
) t where nb = 1;

  word  | nb
-------+----
 hello |  1
 world |  1
(2 lignes)


with fakedata as (
               select 'hello' word
               union all
               select 'world' word
)
select *
from (
               select word, count(*) nb from fakedata group by word
) t where nb = 1;

  word  | nb
-------+----
 hello |  1
 world |  1
(2 lignes)

psql -p 5433

 select version();
                                                              version
            

------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 15beta2 (Debian 15~beta2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1
20210110,64-bit 
(1 ligne)

with fakedata as (
               select 'hello' word
               union all
               select 'world' word
)
select *
from (
               select word, count(*) over (partition by word) nb from fakedata
) t where nb = 1;
ERREUR:  cache lookup failed for function 0

with fakedata as (
               select 'hello' word
               union all
               select 'world' word
)
select *
from (
               select word, count(*) nb from fakedata group by word
) t where nb = 1;

 word  | nb
-------+----
 hello |  1
 world |  1
(2 lignes)


Best regards,
Phil


On Thu, Aug 04, 2022 at 01:19:59PM +0000, Phil Florent wrote:
> A DSS developer from my company, Julien Roze, reported me an error I cannot explained. Is it a new behavior or a bug
?
> 
> Original query is much more complicated but here is a simplified test case with postgresql 14 and 15 beta 2 on Debian
11,packages from pgdg :
 

Thanks for simplifying and reporting it.

It looks like an issue with window run conditions (commit 9d9c02ccd).

+David

(gdb) b pg_re_throw
(gdb) bt
#0  pg_re_throw () at elog.c:1795
#1  0x0000557c85645e69 in errfinish (filename=<optimized out>, filename@entry=0x557c858db7da "fmgr.c",
lineno=lineno@entry=183,funcname=funcname@entry=0x557c858dc410 <__func__.24841> "fmgr_info_cxt_security") at
elog.c:588
#2  0x0000557c85650e21 in fmgr_info_cxt_security (functionId=functionId@entry=0, finfo=finfo@entry=0x557c86a05ad0,
mcxt=<optimizedout>, ignore_security=ignore_security@entry=false) at fmgr.c:183
 
#3  0x0000557c85651284 in fmgr_info (functionId=functionId@entry=0, finfo=finfo@entry=0x557c86a05ad0) at fmgr.c:128
#4  0x0000557c84b32c73 in ExecInitFunc (scratch=scratch@entry=0x7ffc369a9cf0, node=node@entry=0x557c869f59b8,
args=0x557c869f5a68,funcid=funcid@entry=0, inputcollid=inputcollid@entry=0, state=state@entry=0x557c86a05620)
 
    at execExpr.c:2748
#5  0x0000557c84b27904 in ExecInitExprRec (node=node@entry=0x557c869f59b8, state=state@entry=0x557c86a05620,
resv=resv@entry=0x557c86a05628,resnull=resnull@entry=0x557c86a05625) at execExpr.c:1147
 
#6  0x0000557c84b33a1d in ExecInitQual (qual=0x557c869f5b18, parent=parent@entry=0x557c86a05080) at execExpr.c:253
#7  0x0000557c84c8eadb in ExecInitWindowAgg (node=node@entry=0x557c869f4d20, estate=estate@entry=0x557c86a04e10,
eflags=eflags@entry=16)at nodeWindowAgg.c:2420
 
#8  0x0000557c84b8edda in ExecInitNode (node=node@entry=0x557c869f4d20, estate=estate@entry=0x557c86a04e10,
eflags=eflags@entry=16)at execProcnode.c:345
 
#9  0x0000557c84b70ea2 in InitPlan (queryDesc=queryDesc@entry=0x557c8695af50, eflags=eflags@entry=16) at
execMain.c:938
#10 0x0000557c84b71658 in standard_ExecutorStart (queryDesc=queryDesc@entry=0x557c8695af50, eflags=16, eflags@entry=0)
atexecMain.c:265
 
#11 0x0000557c84b71ca4 in ExecutorStart (queryDesc=queryDesc@entry=0x557c8695af50, eflags=0) at execMain.c:144
#12 0x0000557c8525292b in PortalStart (portal=portal@entry=0x557c869a45e0, params=params@entry=0x0,
eflags=eflags@entry=0,snapshot=snapshot@entry=0x0) at pquery.c:517
 
#13 0x0000557c8524b2a4 in exec_simple_query (
    query_string=query_string@entry=0x557c86938af0 "with fakedata as (\n", ' ' <repetidos 15 veces>, "select 'hello'
word\n",' ' <repetidos 15 veces>, "union all\n", ' ' <repetidos 15 veces>, "select 'world' word\n)\nselect *\nfrom
(\n",' ' <repetidos 15 veces>, "select word, count(*) over (partition by word) nb fro"...) at postgres.c:1204
 
#14 0x0000557c8524e8bd in PostgresMain (dbname=<optimized out>, username=username@entry=0x557c86964298 "pryzbyj") at
postgres.c:4505
#15 0x0000557c85042db6 in BackendRun (port=port@entry=0x557c8695a910) at postmaster.c:4490
#16 0x0000557c8504a79a in BackendStartup (port=port@entry=0x557c8695a910) at postmaster.c:4218
#17 0x0000557c8504ae12 in ServerLoop () at postmaster.c:1808
#18 0x0000557c8504c926 in PostmasterMain (argc=3, argv=<optimized out>) at postmaster.c:1480
#19 0x0000557c84ce4209 in main (argc=3, argv=0x557c86933000) at main.c:197

(gdb) fr 7             
#7  0x0000557c84c8eadb in ExecInitWindowAgg (node=node@entry=0x557c869f4d20, estate=estate@entry=0x557c86a04e10,
eflags=eflags@entry=16)at nodeWindowAgg.c:2420
 
2420            winstate->runcondition = ExecInitQual(node->runCondition,

-- 
Justin



On Fri, 5 Aug 2022 at 01:20, Phil Florent <philflorent@hotmail.com> wrote:
> with fakedata as (
>                select 'hello' word
>                union all
>                select 'world' word
> )
> select *
> from (
>                select word, count(*) over (partition by word) nb from fakedata
> ) t where nb = 1;
> ERREUR:  cache lookup failed for function 0

> A DSS developer from my company, Julien Roze, reported me an error I cannot explained. Is it a new behavior or a bug
?

Thank you for the report and the minimal self-contained test case.
That's highly useful for us.

I've now committed a fix for this ([1]).  It will appear in the next
beta release for PG15.

David

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=270eb4b5d4986534f2d522ebb19f67396d13cf44