Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1muIPG-0003IL-Sk for pgsql-general@arkaria.postgresql.org; Mon, 06 Dec 2021 18:08:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1muIPF-0005BT-K5 for pgsql-general@arkaria.postgresql.org; Mon, 06 Dec 2021 18:08:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1muIPE-0005BJ-1f for pgsql-general@lists.postgresql.org; Mon, 06 Dec 2021 18:08:05 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1muIPB-0000vc-49 for pgsql-general@lists.postgresql.org; Mon, 06 Dec 2021 18:08:03 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 0F02E5C01B5; Mon, 6 Dec 2021 13:07:59 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 06 Dec 2021 13:07:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=k gPR29j8Micg/lJfMEdC0mFlHzpW0qdYwZF/Jp7z4Cg=; b=wwOEqy1LtWRUhSZP6 +cccynfEnvKzA+gDURpOiJ8C/99TCJgu9lM/gQFagBzgKObnR7hI9QzMGToR8I7m OR6RKHCBEl1gYQWii1G2LW+VJ45RjLUfNE3aevfEZgwC4F690NbGiFHBVsiO/MU5 UyAn9p3kjP/47orpJgD2d7PvLyUZaqpehDnMnACmxJNT7g1qcp+JYHHepftQTXNz 8ND4l2GcYE9+hPy2L+i9DBEJeRyT9sTIWj/7WTnFTeipeJYfWbEHQVZD6+xUPn23 oWpOoE4gzrcG+yrhj1na/BkFKGVKJR4Lp/5AgBxvQw1Lv0jb+pSnqUjTF971uHbO TJJFA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=kgPR29j8Micg/lJfMEdC0mFlHzpW0qdYwZF/Jp7z4 Cg=; b=j78KFTK6/buZLiHUB++BrD5O1u468RaO9jTT44Naep/UYcl0SSFTwWF4K gjmkYlxIIFPlfDI+Myt8b3nihq9S4F7v3PWvtntQbHPgG856n23QZNxZQPXtTBFR +kg/vnJaay8RtSHH+9+wEmqqtZ0A5tuDgcspdJXN2XHraAS/iUs6LfjcmuvkhYk1 ErzS/+P11lXrAxzkU7ViohgTk3coUtWfGpJ2WzioVJampR51PNB+Jw+cPRps7F90 VSg+HILsM/JltHpg0CCKk6bQs0us6G/u1P2cejcQ7JtxgdxE1MsBUJJC5wIXbz43 myUmW9yQ0BmM7J75+stTaARTu8z/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeefgddutdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpedugfeuleegveffhfegleejhefhtedtgeeileeggfeh fefffeevgeejtdeutefftdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Dec 2021 13:07:58 -0500 (EST) Message-ID: <6b84dfe8-d13b-45b0-53e7-e9aadf1a1c4c@aklaver.com> Date: Mon, 6 Dec 2021 10:07:57 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT Content-Language: en-US To: Alan Hodgson , pgsql-general@lists.postgresql.org References: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca> From: Adrian Klaver In-Reply-To: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/6/21 10:02, Alan Hodgson wrote: > On Mon, 2021-12-06 at 10:19 -0700, Rob Sargent wrote: >> To be clear, is it the devs or the ORM that's adding the ORDER  and the >> LIMIT?  I'm betting on devs.  Do they need the smallest id (first >> occurrance?) or do they need data common to all 5096 entries (Name?) and >> any record will do?.  For the former they might be better off asking for >> just the attributes they need and for the latter you need to provide an >> option which gets them that single record.  Of course, If they have the >> "smallest id" in hand they should request that. > > That assumes I could figure what bit of ORM code is generating this, > talk to them, and then get them to actually think about what data > they're looking for and it's impact on the database. :/ Given my 25 year > track record with devs, I'm thinking of that as plan B. Hopefully though > if they're looking for something common to all the records they would > look at the parent table instead. > > I do expect the dev actually specified the order/limit for some reason. Maybe I'm silly, but why is asking them a Plan B? > > Thank you for the suggestions. -- Adrian Klaver adrian.klaver@aklaver.com