Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fTEof-00038s-ST for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jun 2018 23:04:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fTEoc-0005cl-2u for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jun 2018 23:04:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fTEob-0005cY-Pa; Wed, 13 Jun 2018 23:04:33 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fTEoZ-0003He-1U; Wed, 13 Jun 2018 23:04:33 +0000 Received: by mail-lf0-x243.google.com with SMTP id i15-v6so6454589lfc.2; Wed, 13 Jun 2018 16:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=kugd6InwXDfT9MjCm4K5dyWq2b+mCFKuS4JLdAo21TU=; b=OtFOEG0oyZb7Vetb7DftRYLMnK6DX+V8RMZyudKEn/it8TUtW9OJ9bncyL5EZagN9+ fEHtvMaGCaKqkZYjF8xippL6yKzs8dAccu/9HjdVVMo7I+1CGSmjmxpnzLjqSuJAWfCB wts2T+wpjANuABD83avr2Yrd0WNc6gRycP2v+xgWxdX0QDxAKiZmqC10c6Txk8E7jrKD 5gRCGag1+l6GPCA9mTaMja7xC7zzvV298iMc8r6ds9kHsDCD+JlA6FnmZxTBxWIRXlWS 4pRR6najGu05h+7MQfzf21pXUl0J4lVo2LIxN+VL6wtcrCjo7KFUsChZ6MGhHSPTdeBP s+iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=kugd6InwXDfT9MjCm4K5dyWq2b+mCFKuS4JLdAo21TU=; b=MsZytYRQ5dYuJn9IH7k6VnZBxqiiKAV/Om8aiKN34WBSDv73IgnyN8OjzCUheTW2/2 DUHUWj5A+TbXIaoyO+eRrY/SCldQqtAFit1T5Ahjc+CnBoVKThcoFgdXjja3yjwAg7yv XibKXPSNDNfyIogeJAVo7njD3vm/DHtnJRl+HOF+5Ewdl2AQKdgCmGXjGGDJGDUSVAP7 MgepC5+Vdl7zQ5a5pchuBI588+syLWRwQFhMSt4n6dVAUiggNC9BJt/p74vno9hu39vK cnQPHgVecM872Fh63ce95nbeQ9xcUlPsYYAb3W7Ldsv0oiEKVAwYoMUwFcrQIM5KnTnS T08w== X-Gm-Message-State: APt69E1aFydQZxO22pZLG0nyCC/7/PZilpPSryyTdYDkRzm/Iv0XUVrR yeHhsHEss1tlO1wrL8dPJ2DUm/ou7Lk= X-Google-Smtp-Source: ADUXVKIRhX1rJMeaHkvBtBEZlFYEfH59vjOiRbecc7JAs8vi9a22odbpvp7bFjNTanL7J8+NkEMrdA== X-Received: by 2002:a19:9601:: with SMTP id y1-v6mr4197538lfd.130.1528931068510; Wed, 13 Jun 2018 16:04:28 -0700 (PDT) Received: from MacBook-Pro-Milutin.local ([188.123.231.40]) by smtp.gmail.com with ESMTPSA id q5-v6sm706162ljj.68.2018.06.13.16.04.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 16:04:27 -0700 (PDT) Subject: Re: Slow planning time for simple query From: Maksim Milyutin To: Tom Lane Cc: pgsql-general@lists.postgresql.org, pgsql-hackers@lists.postgresql.org References: <36adf760-680b-7a4a-e019-64f4eaaf6ff7@gmail.com> <9661.1528573749@sss.pgh.pa.us> <7a5653e4-5a94-18d3-17e4-7e11ed2c9919@gmail.com> Message-ID: <4d61f569-c781-9066-c6b8-471e963d7759@gmail.com> Date: Thu, 14 Jun 2018 02:04:26 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <7a5653e4-5a94-18d3-17e4-7e11ed2c9919@gmail.com> Content-Type: multipart/alternative; boundary="------------D66A4A23E10E9176AF85250E" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------D66A4A23E10E9176AF85250E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 13.06.2018 12:40, Maksim Milyutin wrote: > On 09.06.2018 22:49, Tom Lane wrote: > >> Maksim Milyutin writes: >>> On hot standby I faced with the similar problem. >>> ... >>> is planned 4.940 ms on master and *254.741* ms on standby. >> (I wonder though why, if you executed the same query on the master, >> its setting of the index-entry-is-dead bits didn't propagate to the >> standby.) > > I have verified the number dead item pointers (through pageinspect > extension) in the first leaf page of index participating in query > ('main.message_instance_pkey') on master and slave nodes and have > noticed a big difference. > > SELECT * FROM monitoring.bt_page_stats('main.message_instance_pkey', > 3705); > > On master: > >  blkno | type | live_items | dead_items | avg_item_size | page_size | > free_size | btpo_prev | btpo_next | btpo | btpo_flags > -------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------ >   3705 | l    |          1 |         58 |            24 |      8192 > |      6496 |         0 |      3719 |    0 | 65 > > On standby: > >  blkno | type | live_items | dead_items | avg_item_size | page_size | > free_size | btpo_prev | btpo_next | btpo | btpo_flags > -------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------ >   3705 | l    |         59 |          0 |            24 |      8192 > |      6496 |         0 |      3719 |    0 |          1 > > In this point I want to highlight the issue that the changes in *lp_flags* bits (namely, set items as dead) for index item pointers doesn't propagate from master to replica in my case. As a consequence, on standby I have live index items most of which on master are marked as dead. And my queries on planning stage are forced to descent to heap pages under *get_actual_variable_range* execution that considerately slows down planning. Is it bug or restriction of implementation or misconfiguration of WAL/replication? -- Regards, Maksim Milyutin --------------D66A4A23E10E9176AF85250E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

13.06.2018 12:40, Maksim Milyutin wrote:

On 09.06.2018 22:49, Tom Lane wrote:

Maksim Milyutin <milyutinma@gmail.com> writes:
On hot standby I faced with the similar problem.
...
is planned 4.940 ms on master and *254.741* ms on standby.
(I wonder though why, if you executed the same query on the master,
its setting of the index-entry-is-dead bits didn't propagate to the
standby.)

I have verified the number dead item pointers (through pageinspect extension) in the first leaf page of index participating in query ('main.message_instance_pkey') on master and slave nodes and have noticed a big difference.

SELECT * FROM monitoring.bt_page_stats('main.message_instance_pkey', 3705);

On master:

 blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags
-------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------
  3705 | l    |          1 |         58 |            24 |      8192 |      6496 |         0 |      3719 |    0 |         65

On standby:

 blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags
-------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------
  3705 | l    |         59 |          0 |            24 |      8192 |      6496 |         0 |      3719 |    0 |          1



In this point I want to highlight the issue that the changes in lp_flags bits (namely, set items as dead) for index item pointers doesn't propagate from master to replica in my case. As a consequence, on standby I have live index items most of which on master are marked as dead. And my queries on planning stage are forced to descent to heap pages under get_actual_variable_range execution that considerately slows down planning.

Is it bug or restriction of implementation or misconfiguration of WAL/replication?

-- 
Regards,
Maksim Milyutin
--------------D66A4A23E10E9176AF85250E--