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 1g6ygh-0000Kb-5H for pgsql-general@arkaria.postgresql.org; Mon, 01 Oct 2018 13:56:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g6yge-0008HE-0K for pgsql-general@arkaria.postgresql.org; Mon, 01 Oct 2018 13:56:36 +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.89) (envelope-from ) id 1g6ygd-0008H7-G0 for pgsql-general@lists.postgresql.org; Mon, 01 Oct 2018 13:56:35 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g6ygb-0004iF-2U for pgsql-general@lists.postgresql.org; Mon, 01 Oct 2018 13:56:34 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 7938221FA9; Mon, 1 Oct 2018 09:56:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 01 Oct 2018 09:56:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=/DoqdWmGqr0wYm/2vLt1dxr+S2wzQ HW+AEEyWrjbJTA=; b=VZQqRBzTPKIa9iOf9OSutK2ApRA3Lz3LxKbWq8CtHbqEC wMNKIDk1+D34FOjG6PI3nyKTUSn/7bncR/ycLms7QIlPXJWoF3jmsaaMeA0N9WhN vvRQSrUzrLHHgrpE5OtxWmoUw8ODrXtAz/GxP45YxpC85QKUE0awowWIU/xQgD58 egFWF5gZ/b7t9Rrzket080ak7jJL46blknXlsmE0LuXBltxT7RttGixCuyTAwsLe nzVP38dSFmqRZbG97UiXQ3QC22vHU9SgABXqQ1AjGPsjETaL+ltV19C17pt/3/tV EW6EvpFSOeDoQypc8YI13af4oeE2m+6sZfFGsFItg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=/DoqdW mGqr0wYm/2vLt1dxr+S2wzQHW+AEEyWrjbJTA=; b=c/dP72axD5gy5LmCb9xXkv yvBm+QO3lqd7Edeggal+K5i7I0Kn4gPzUquUPO9zWdL4Z63esHibU5lmnY1fRdKM nSkPdpvqYE+pTc4Wih8ysIaBJTXeTARl5old/SMtmrIXVsugAbWfstka8ZmQw19Q CFBsEQ3tvkpA744fesScyZ9/jIu83u+usYPZHp+NM86pNueJlryw9uVfQHtNjce8 q1LPvfAzxPs+lpBzFOGCcygh+dgOuilsO/RXwSi54M0oENkFxt0D7B2p2HmxAds1 i1P3K1ndG9sWF0DSr9n+PCylPWEI5lYbk0trYi7xvq8HoV79KmYuBB/jNSyeP7Mg == X-ME-Sender: X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id BE7BF102D3; Mon, 1 Oct 2018 09:56:30 -0400 (EDT) Subject: Re: Why my query not using index to sort? To: Arup Rakshit Cc: Andreas Kretschmer , pgsql-general@lists.postgresql.org References: <20311.1538141875@sss.pgh.pa.us> <97DDEE09-FE33-43DB-A451-665F3535B5BA@zeit.io> <40D9D4B8-7D62-4E6E-B6E9-3F83DACA2D45@zeit.io> <61708e66-dcc6-6490-b876-979eff8c3efd@a-kretschmer.de> <05A26EE2-964C-4F53-8DB5-CD86D3D46D86@zeit.io> <2c10559c-21fa-bb73-3814-cec5583ddb6c@aklaver.com> <327CBA05-3910-416D-B1E0-175C44A256AE@zeit.io> <2be603be-1506-5a3d-c086-1fdd11d83bd3@aklaver.com> <13BB58F6-A4D6-475A-A71A-F6B4CF780644@zeit.io> <761996F5-EF2E-48C9-A250-B41A63239E01@zeit.io> <658B2138-3146-4BE8-946F-827B1453A38E@zeit.io> <50c0d333-b979-c34b-46bd-a686b429868f@aklaver.com> <6F29D803-9EC7-4D80-BFDB-BDF740243A68@zeit.io> From: Adrian Klaver Message-ID: <381c04e8-583b-869d-82cf-7fe0beede79f@aklaver.com> Date: Mon, 1 Oct 2018 06:56:29 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <6F29D803-9EC7-4D80-BFDB-BDF740243A68@zeit.io> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/30/18 9:26 PM, Arup Rakshit wrote: > Hello Adrian, > > The one I said in gist is different query, and the previous mail I > posted another query because I was testing with different types of > queries. So 1.5, 1.7 is not for this current one. My main point now I am > trying to understand why it is not matching at all. The current query > timing in psql and production log is very close, but not the explain output. 1) If you want to track down what is happening you will need to provide a consistent test case. Jumping from query to query, dataset to dataset, condition to condition is not conducive to coming up with an answer. 2) What is the answer you are looking for? Or to put it another way what is the problem you are trying to solve? 3) Taking 1) & 2) into account you need to do something along lines of: a) Information about size of table. b) A set query against said table. c) Some indication of the problem the query is causing. > > Regarding the file written time, I think it is not the time to write > into the file. Because If I don’t write this to the file still it shows > 14ms + always. I used the file not the sql output so that I can paste > here clean stuffs I want to show. If you want, I can show the output > without writing it to the external file, and you will see the same time. > > Well you are looking at two different times. The EXPLAIN ANALYZE is showing the time to execute the query. The \timing is including the time to display the output which is why is comparable to what you see in the log. To illustrate: select count(*) from projection ; count ------- 28447 (1 row) \timing Timing is on. explain analyze select * from projection ; QUERY PLAN ---------------------------------------------------------------------------------------------------------------- Seq Scan on projection (cost=0.00..751.47 rows=28447 width=109) (actual time=0.012..3.853 rows=28447 loops=1) Planning time: 0.066 ms Execution time: 5.381 ms (3 rows) explain analyze select * from projection where p_item_no = 2; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Index Scan using pj_pno_idx on projection (cost=0.29..21.93 rows=5 width=109) (actual time=0.021..0.032 rows=10 loops=1) Index Cond: (p_item_no = 2) Planning time: 0.117 ms Execution time: 0.061 ms (4 rows) select * from projection ; --Returns 28447 rows Time: 56.186 ms select * from projection where p_item_no = 2; --Returns 10 rows Time: 0.372 ms Repeating it: explain analyze select * from projection ; QUERY PLAN ---------------------------------------------------------------------------------------------------------------- Seq Scan on projection (cost=0.00..751.47 rows=28447 width=109) (actual time=0.012..3.377 rows=28447 loops=1) Planning time: 0.056 ms Execution time: 4.759 ms (3 rows) explain analyze select * from projection where p_item_no = 2; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Index Scan using pj_pno_idx on projection (cost=0.29..21.93 rows=5 width=109) (actual time=0.021..0.031 rows=10 loops=1) Index Cond: (p_item_no = 2) Planning time: 0.112 ms Execution time: 0.059 ms (4 rows) select * from projection ; Time: 56.548 ms select * from projection where p_item_no = 2; Time: 0.463 ms -- Adrian Klaver adrian.klaver@aklaver.com