pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Luís Roberto Weck <luisroberto@siscobra.com.br>
To: pgsql-general@postgresql.org
Subject: Parallel Append Query
Date: Fri, 21 Feb 2020 08:16:29 -0300
Message-ID: <5d461f71-85fd-c76c-323a-2f3604ff8fe3@siscobra.com.br> (raw)

Hi!

I'm seeing varying number of rows removed by filter on a parallel append 
query:

CREATE TABLE usuario (
   id bigint generated always as identity,
   nome text
);

INSERT INTO usuario (nome)
SELECT md5(seq)::text
     FROM generate_series(1,500000,1) tab(seq);

ANALYZE usuario;

EXPLAIN ANALYZE
(SELECT * FROM usuario WHERE nome = 'c4ca4238a0b923820dcc509a6f75849b')
UNION ALL
(SELECT * FROM usuario WHERE nome = 'c81e728d9d4c2f636f067f89cc14862c')

Gather  (cost=1000.00..15574.56 rows=2 width=41) (actual 
time=0.320..56.154 rows=2 loops=1)
   Workers Planned: 2
   Workers Launched: 2
   ->  Parallel Append  (cost=0.00..14574.36 rows=2 width=41) (actual 
time=13.449..47.899 rows=1 loops=3)
         ->  Parallel Seq Scan on usuario (cost=0.00..7287.17 rows=1 
width=41) (actual time=8.934..25.476 rows=0 *loops=3*)
               Filter: (nome = 'c81e728d9d4c2f636f067f89cc14862c'::text)
*Rows Removed by Filter: 166666*
         ->  Parallel Seq Scan on usuario usuario_1 (cost=0.00..7287.17 
rows=1 width=41) (actual time=13.470..33.630 rows=0 *loops=2*)
               Filter: (nome = 'c4ca4238a0b923820dcc509a6f75849b'::text)
*Rows Removed by Filter: 250000*
Planning Time: 0.106 ms
Execution Time: 56.184 ms

The execution plan varies just by running the query a few times, and it 
goes back and forth between these two:

Gather  (cost=1000.00..15574.56 rows=2 width=41) (actual 
time=0.341..55.499 rows=2 loops=1)
   Workers Planned: 2
   Workers Launched: 2
   ->  Parallel Append  (cost=0.00..14574.36 rows=2 width=41) (actual 
time=15.904..49.821 rows=1 loops=3)
         ->  Parallel Seq Scan on usuario (cost=0.00..7287.17 rows=1 
width=41) (actual time=0.013..48.591 rows=1 *loops=1*)
               Filter: (nome = 'c81e728d9d4c2f636f067f89cc14862c'::text)
*Rows Removed by Filter: 499999*
         ->  Parallel Seq Scan on usuario usuario_1 (cost=0.00..7287.17 
rows=1 width=41) (actual time=15.985..33.621 rows=0 *loops=3*)
               Filter: (nome = 'c4ca4238a0b923820dcc509a6f75849b'::text)
*Rows Removed by Filter: 166666*
Planning Time: 0.107 ms
Execution Time: 55.524 ms

But I can't understand why does it changes the number of loops from the 
queries

Message-ID: <5d461f71-85fd-c76c-323a-2f3604ff8fe3@siscobra.com.br>
Permalink:  ../5d461f71-85fd-c76c-323a-2f3604ff8fe3@siscobra.com.br/
Also on:    postgresql.org/message-id/5d461f71-85fd-c76c-323a-2f3604ff8fe3@siscobra.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: luisroberto@siscobra.com.br
  Subject: Re: Parallel Append Query
  In-Reply-To: <5d461f71-85fd-c76c-323a-2f3604ff8fe3@siscobra.com.br>
  References: <5d461f71-85fd-c76c-323a-2f3604ff8fe3@siscobra.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox