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

From: gzh <gzhcoder(at)126(dot)com>
To: "Laurenz Albe" <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: How to improve the performance of my SQL query?
Date: 2023-07-25 03:11:13
Message-ID: 6cd42bea.2647.1898b07865a.Coremail.gzhcoder@126.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>I asked for EXPLAIN (ANALYZE, BUFFERS, SETTINGS) ...

>Or do you have a version that is too old for SETTINGS?

Sorry. Please refer to the following execution plan.

EXPLAIN (ANALYZE, BUFFERS, SETTINGS)

select COUNT(ET_CD)

from TBL_SHA

WHERE TBL_SHA.MS_CD = 'MLD009'

and TBL_SHA.ETRYS in

(select TBL_INF.RY_CD

from TBL_INF

WHERE TBL_INF.MS_CD = 'MLD009'

AND TBL_INF.RY_CD = '00000001'

)

----- Execution Plan -----

Buffers: shared hit=13 read=2171693

I/O Timings: read=365863.877

-> Aggregate (cost=2728633.22..2728633.23 rows=1 width=8) (actual time=131595.624..131599.529 rows=1 loops=1)

Buffers: shared hit=13 read=2171693

I/O Timings: read=365863.877

-> Nested Loop (cost=1000.29..2722556.76 rows=2430587 width=9) (actual time=2.341..131256.445 rows=2513500 loops=1)

Buffers: shared hit=13 read=2171693

I/O Timings: read=365863.877

-> Index Only Scan using tbl_inf_pkc on tbl_inf (cost=0.29..8.31 rows=1 width=9) (actual time=1.471..1.476 rows=1 loops=1)

Index Cond: ((ms_cd = 'MLD009'::bpchar) AND (ry_cd = '00000001'::bpchar))

Heap Fetches: 1

Buffers: shared hit=2 read=2

I/O Timings: read=1.412

-> Gather (cost=1000.00..2698242.58 rows=2430587 width=18) (actual time=0.866..130696.440 rows=2513500 loops=1)

Workers Planned: 2

Workers Launched: 2

Buffers: shared hit=11 read=2171691

I/O Timings: read=365862.464

-> Parallel Seq Scan on tbl_sha (cost=0.00..2454183.88 rows=1012745 width=18) (actual time=0.215..130476.981 rows=837833 loops=3)

Filter: ((ms_cd = 'MLD009'::bpchar) AND (etrys = '00000001'::bpchar))

Rows Removed by Filter: 13728945

Buffers: shared hit=11 read=2171691

I/O Timings: read=365862.464

Settings: effective_cache_size = '1886088kB', jit = 'off', search_path = '"$user", mdb'

Planning:

Buffers: shared hit=167 read=7

I/O Timings: read=2.735

Planning Time: 3.733 ms

Execution Time: 131599.594 ms

At 2023-07-24 23:58:50, "Laurenz Albe" <laurenz(dot)albe(at)cybertec(dot)at> wrote:
>On Mon, 2023-07-24 at 17:54 +0800, gzh wrote:
>> EXPLAIN (ANALYZE ON, VERBOSE ON, COSTS ON, BUFFERS ON)
>
>I asked for EXPLAIN (ANALYZE, BUFFERS, SETTINGS) ...
>Or do you have a version that is too old for SETTINGS?
>
>One other idea: check if the index is INVALID (this will
>be visible if you run "\d tablenane" in "psql").
>Invalid indexes won't be used.
>
>Yours,
>Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message gzh 2023-07-25 03:58:42 Re: How to improve the performance of my SQL query?
Previous Message Badri Subramaniam 2023-07-25 01:54:55 Setting Auto Commit off in C API