Re: How to improve the performance of my SQL query?

Поиск
Список
Период
Сортировка
От Peter J. Holzer
Тема Re: How to improve the performance of my SQL query?
Дата
Msg-id 20230720094451.m4hdv4hdhmjbjw53@hjp.at
обсуждение исходный текст
Ответ на How to improve the performance of my SQL query?  (gzh <gzhcoder@126.com>)
Список pgsql-general
On 2023-07-20 15:09:22 +0800, gzh wrote:
> Hi everyone,
>
>
> I'm running into some performance issues with my SQL query.
>
> The following SQL query is taking a long time to execute.
>
>
> explain analyze
> select COUNT(ET_CD)
> from TBL_SHA
> WHERE TBL_SHA.MS_CD = '009'
> and TBL_SHA.ETRYS in
>    (select TBL_INF.RY_CD
>     from TBL_INF
>     WHERE TBL_INF.MS_CD = '009'
>    AND TBL_INF.RY_CD = '000001'
>    )
>
> ----- Execution Plan -----
[...]
>               ->  Seq Scan on TBL_SHA  (cost=0.00..2698666.58 rows=3202774 width=18)
>                                        (actual time=97264.138..123554.792 rows=3200000 loops=1)
>                     Filter: ((MS_CD = '009'::bpchar) AND (ETRYS = '000001'::bpchar))
>                     Rows Removed by Filter: 32000325
[...]
> --------------------------------------------------------------------------------
>
>
> The index is defined as follows.
>
>
> CREATE INDEX index_search_01 ON mdb.TBL_SHA USING btree (MS_CD, ETRYS);
>
>
>
> When I take the following sql statement, the index works fine and the query is
> fast.
>
>
> select COUNT(ET_CD)
> from TBL_SHA
> WHERE MS_CD = '009'
> AND ETRYS = '000001'

What's the plan for that query?

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Erik Wienhold
Дата:
Сообщение: Re: How to improve the performance of my SQL query?
Следующее
От: gzh
Дата:
Сообщение: Re:Re: How to improve the performance of my SQL query?