Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bBNQn-0005Xq-L3 for pgsql-performance@arkaria.postgresql.org; Fri, 10 Jun 2016 14:29:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bBNQn-00064j-2V for pgsql-performance@arkaria.postgresql.org; Fri, 10 Jun 2016 14:29:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bBNP8-0004FH-Bc for pgsql-performance@postgresql.org; Fri, 10 Jun 2016 14:27:22 +0000 Received: from smtp-out-no.shaw.ca ([64.59.134.13]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bBNP4-0004u3-QG for pgsql-performance@postgresql.org; Fri, 10 Jun 2016 14:27:20 +0000 Received: from home.zioup.com ([96.51.153.133]) by shaw.ca with SMTP id BNP0bgWtBBXanBNP1bPKhe; Fri, 10 Jun 2016 08:27:16 -0600 X-Authority-Analysis: v=2.2 cv=AdXzJDfG c=1 sm=1 tr=0 a=pcwx/iW1S4GNAxS9KzaPFA==:117 a=pcwx/iW1S4GNAxS9KzaPFA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=pD_ry4oyNxEA:10 a=pGLkceISAAAA:8 a=CSwD4DPDAAAA:8 a=N8iSzGwtAAAA:8 a=HXBxyC-n5k87qbps3-MA:9 a=6kGIvZw6iX1k4Y-7sg4_:22 a=jFnZSrNcIxrrcW8ogBOp:22 a=YHuoxGDvEISy2GqV2ok9:22 Received: from [192.168.246.243] (epicurus.zioup.net [192.168.246.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by home.zioup.com (Postfix) with ESMTPSA id 42271A0E56 for ; Fri, 10 Jun 2016 08:27:13 -0600 (MDT) Subject: Re: Many-to-many performance problem To: pgsql-performance@postgresql.org References: <22656.1465568025@sss.pgh.pa.us> From: Yves Dorfsman X-Enigmail-Draft-Status: N1110 Message-ID: <575ACE40.8070703@zioup.com> Date: Fri, 10 Jun 2016 08:27:12 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <22656.1465568025@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfE2NE45oNt87okqlhLORUklsgmmaBlLAs+djdtDmPe/+MfDo5l3GwA0aMqTj0w5FRa0LlcM0AwtpHfL7kDhzkCywiD9Feklxqm4q70lvKx2S8KzOxP6J x6hVceX6Tc/4Su2mTBsWlWqGr8dMNBtd8BwF3wdhVwUG3Gw0wmAk85s60WTC8BisnquCgdAxTZ206Q== X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org I thought this was a really interesting case, and would love to learn from it, please bare with me if my questions are naive. On 2016-06-10 08:13, Tom Lane wrote: > Rowan Seymour writes: >> Most of time, this query performs like https://explain.depesz.com/s/ksOC >> (~15ms). It's no longer using the using the msgs_inbox index, but it's >> plenty fast. However, sometimes it performs like >> https://explain.depesz.com/s/81c (67000ms) >> And if you run it again, it'll be fast again. > > It looks like everything is fine as long as all the data the query needs > is already in PG's shared buffers. As soon as it has to go to disk, > you're hurting, because disk reads seem to be taking ~10ms on average. -> Index Scan using msgs_message_pkey on msgs_message (cost=0.43..8.04 rows=1 width=47) (actual time=18.550..18.559 rows=0 loops=3556) Index Cond: (id = msgs_message_labels.message_id) Filter: (is_active AND is_handled AND has_labels AND (NOT is_archived) AND (created_on < '2016-06-10 07:11:06.381+00'::timestamp with time zone) AND (org_id = 7)) Rows Removed by Filter: 1 Buffers: shared hit=11032 read=3235 dirtied=5 Do you mean that it reads the index from disk? Or that it looks things up in the index, and fetch data on disk (based on that lookup)? Is the 18ms from the Buffers: read=3235? That's 3235 rows read from disk? -- http://yves.zioup.com gpg: 4096R/32B0F416 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance