postgresql,我的查询太慢了。什么';问题出在哪里?(需要1分钟以上)

postgresql,我的查询太慢了。什么';问题出在哪里?(需要1分钟以上),postgresql,Postgresql,下面是我使用的查询。 我想在2到3秒钟内看到结果,但这需要一分钟以上的时间 with meta as ( select item_name , item_sp , grade from meta_info where item_sp = 'Bc_1' and grade_no = ( select max(grade_n

下面是我使用的查询。 我想在2到3秒钟内看到结果,但这需要一分钟以上的时间

with meta as (
    select
        item_name
        , item_sp 
        , grade
    from
        meta_info
    where
        item_sp = 'Bc_1'
        and grade_no = (
            select
                max(grade_no)
            from
                meta_info
            where 
                item_sp = 'Bc_1'
        )
) select 
    *
from (
    select
        m.grade
        , i.item_sp
        , i.regist_date
        , i.serial_key
        , row_number() over(partition by i.serial_key order by m.grade) as serial_key_number
    from 
        item_info i, meta m
    where 
        i.item_sp = 'Bc_1'
        and i.regist_date = '20210314' 
        and i.regist = true
        and i.item_name = m.item_name
        and i.item_sp = m.item_sp
    ) i
where 
    not exists (select 
                    serial_key 
                from 
                    item_info ii
                where 
                    ii.item_sp = 'Bc_1'
                    and ii.regist_date < '20210314'  
                    and i.serial_key = ii.serial_key)
    and i.serial_key_number = 1;


几乎所有的时间都将用于计划中的最后一次索引扫描。您应该能够通过在item\u info(序列号、item\u sp、注册日期)上添加一个索引
来大大改进它。

这花费了13秒,相当不到一分钟。请以文字而不是图像的形式显示计划。谢谢。这是我第一次处理大数据,所以我不知道很多事情。谢谢你的回答。
1. meta_info
item_sp    grade    item_name    grade_no  
 ac_1        A         BOOK         2
 ac_1        B         FOOD         2
 bc_1        A         WATER        2
 cc_1        C         MOUSE        2
  .          .           .          .
  .          .           .          .
  .          .           .          .
2. item_info
item_no(key)    item_sp    item_name    serial_key      regist_date    regist 
   1              ac_1       BOOK       fgd5756ffdsf     20210314       true
   2              ac_1       FOOD        bnffdhtj        20210314       true     
   3              bc_1       WATER      fdfh4fsdfsf      20210314       true    
   4              cc_1       MOUSE      htt55434         20210314       true
   .               .           .           .                .            .
   .               .           .           .                .            .
   .               .           .           .                .            .
   .               .           .           .                .            .