pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Mats Julian Olsen <mats@duneanalytics.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: postgres_fdw insert extremely slow
Date: Wed, 25 Nov 2020 08:57:49 -0800
Message-ID: <1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com> (raw)
In-Reply-To: <10df210c-a1bb-f909-9a48-61ac54880df0@duneanalytics.com>
References: <CAARtqpE-7mZY8WKKMq2fWeHBcrAJu41_GnKgKqdvkidk7g+M3A@mail.gmail.com>
	<3862aa4d-01c7-c76b-4497-ebce1af702cc@aklaver.com>
	<10df210c-a1bb-f909-9a48-61ac54880df0@duneanalytics.com>

On 11/25/20 8:48 AM, Mats Julian Olsen wrote:
> Apologies for the sloppiness!
>> Postgres version(s)?
> 
> x: Aurora PostgreSQL 11.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 
> 4.9.3, 64-bit (RDS)
> 
> y: PostgreSQL 12.2 (Ubuntu 12.2-2.pgdg19.10+1) on x86_64-pc-linux-gnu, 
> compiled by gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008, 64-bit (GCP)

So they are separated by what network distance?

> 
>>
>> Without the actual query and EXPLAIN ANALYZE on it this will be 
>> difficult to answer with any detail.
>>
>> Also would be nice to have the table schema.
>>
> 
> Here's the query, schema and the EXPLAIN ANALYZE

FYI, you will get more responses by including below information directly 
in the email. To that end:

On x

CREATE TABLE labels ( 

     id integer NOT NULL, 

     address_id bytea NOT NULL, 

     name text NOT NULL, 

     author character varying(50) NOT NULL, 

     type text NOT NULL, 

     source text, 

     updated_at timestamp with time zone DEFAULT now() NOT NULL, 

     CONSTRAINT lowercase_name CHECK ((name = lower(name))), 

     CONSTRAINT lowercase_type CHECK ((type = lower(type))), 

     CONSTRAINT whitespace_name CHECK ((regexp_replace(btrim(name, ' 
'::text), '(\s+)'::text, ' '::text, 'g'::text) = name)),
     CONSTRAINT whitespace_type CHECK ((regexp_replace(btrim(type, ' 
'::text), '(\s+)'::text, ' '::text, 'g'::text) = type))
); 

CREATE INDEX labels_label ON labels USING BTREE (name);
CREATE INDEX labels_label_type ON labels USING BTREE (type);
CREATE INDEX labels_address ON labels USING HASH (address_id);
CREATE INDEX labels_source ON labels USING BTREE (source);

On y

CREATE TABLE labels.labels (
     address     bytea PRIMARY KEY,
     labels      text[]
);

> 
> query: https://gist.github.com/mewwts/704663e19a21bc51864f3298f09a18c0

INSERT INTO foreign.labels (address, labels)
SELECT address_id, ARRAY_AGG(name) AS labels
FROM labels
GROUP BY 1
LIMIT 100;

> 
> plan: https://explain.depesz.com/s/RQFQ

Insert on labels  (cost=0.42..26.19 rows=100 width=53) (actual 
time=11541.205..11541.205 rows=0 loops=1)
    ->  Limit  (cost=0.42..25.19 rows=100 width=53) (actual 
time=0.068..3.549 rows=100 loops=1)
          ->  GroupAggregate  (cost=0.42..26502.02 rows=106996 width=53) 
(actual time=0.066..3.449 rows=100 loops=1)
                Group Key: labels_1.address_id
                ->  Index Only Scan using 
labels_address_id_type_name_key on labels labels_1  (cost=0.42..24068.85 
rows=219145 width=31) (actual time=0.054..0.414 rows=201 loops=1)
                      Heap Fetches: 0
  Planning Time: 0.102 ms
  Execution Time: 12797.143 ms


> 
> 
> Best,
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (17+ messages)  latest in thread

Message-ID: <1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com>
Permalink:  ../1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com/
Also on:    postgresql.org/message-id/1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com

 · 

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: adrian.klaver@aklaver.com, mats@duneanalytics.com
  Subject: Re: postgres_fdw insert extremely slow
  In-Reply-To: <1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com>
  References: <CAARtqpE-7mZY8WKKMq2fWeHBcrAJu41_GnKgKqdvkidk7g+M3A@mail.gmail.com> <3862aa4d-01c7-c76b-4497-ebce1af702cc@aklaver.com> <10df210c-a1bb-f909-9a48-61ac54880df0@duneanalytics.com> <1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com>

* 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