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 1muIKF-00036r-O6 for pgsql-general@arkaria.postgresql.org; Mon, 06 Dec 2021 18:02:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1muIKE-0000tn-60 for pgsql-general@arkaria.postgresql.org; Mon, 06 Dec 2021 18:02:54 +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 1muIKD-0000te-RC for pgsql-general@lists.postgresql.org; Mon, 06 Dec 2021 18:02:53 +0000 Received: from outbound2m.ore.mailhop.org ([54.149.155.156]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1muIKB-0000tJ-Hq for pgsql-general@lists.postgresql.org; Mon, 06 Dec 2021 18:02:52 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1638813771; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=dePmxyvdwl7I/MOuYiSagrAhHOzvPr2aRO4DDTf+feN42iW7LlTHnmbha0i152RUQATlPY898YJn9 XRaLTkGhghz2Jw55iy5ENwt5ynpfootkZb6J1Ask6edfHSoZLJvEdQfYOzPjniIH5VT/5VERorscC/ +4mwyNlo4mT7JeJpWtrRVwS0nmTyw5OpTYIue1ZCpckD5fd0GVOE8zR+evJOfRSr9ZrTTXrSIIwEit UGVc+LiyanjHqGSGjSH2f1mwvTgkAGM+YOP2Z7t64sjp+25QS4XACrRVF+1pMdFRVYseH0hoB2zmd3 ALmDbNfotPj76e253V1ub8+QKPW9JTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=mime-version:content-type:references:in-reply-to:date:to:from:subject: message-id:dkim-signature:dkim-signature:dkim-signature:from; bh=0uYI+nLA61GFJDsenEheo9ApLkHQ0ZllZQ3N31OdYpg=; b=iqG3INkM6c/J0WZPjPaZx9DHqTlEJrQHPlIUR+9D0xxHHAbI1uOCgGrxiQQvL4zeNGoD+1hueTv0M oQhJdgOIb/cokgn4zcxAN1dTENIvGYXrQgCYAWGsThh4Gs7iwdcP2PzwTbdFrjKeFtVU3J1L8cMEDd 3c5xIdQyBLMvAPTAsCnfeRsFcvJ0xOCJFSWWKaDsxUmVfgqc/vr0GMn1Coliru41/05NYbbLzI5zhz XO6+nm5F+MLUQAmVBBsVrrQd2zM3+kQvimoja6AtbOnlPgnEiCmK+HBTeqqIbQOpW21BXh0FjVzU/I vvCDJu6KMGBs8rRq70MmjvzPqJL/6EQ== ARC-Authentication-Results: i=1; outbound4.ore.mailhop.org; spf=pass smtp.mailfrom=lists.simkin.ca smtp.remote-ip=172.105.109.24; dkim=pass header.d=lists.simkin.ca header.s=athena header.a=rsa-sha256 header.b=TbwhPiSN; dmarc=pass header.from=lists.simkin.ca; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.simkin.ca; s=duo-1610662143981-d3c4c825; h=mime-version:content-type:references:in-reply-to:date:to:from:subject: message-id:from; bh=0uYI+nLA61GFJDsenEheo9ApLkHQ0ZllZQ3N31OdYpg=; b=iRanIRMmOQrF5vpvRcUoqsgOluMx1x7NYSoTIiw345hdvwFbs2Kb4wAUJli4l4yS+Aj5IY3JWfVEt ZF3sLwDjVsQ89F78uCdcS0TfxKhcbfnj9R0aZZ3V1mUmyqysDMitxzysB6JJo8GW2DvcV6ssmSN6kA 51EvQeFJHgNcwSAk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=mime-version:content-type:references:in-reply-to:date:to:from:subject: message-id:from; bh=0uYI+nLA61GFJDsenEheo9ApLkHQ0ZllZQ3N31OdYpg=; b=bKC3nUpjnf7eeN/TOgIS/TbIR/d25c0kF2Z55ZcWRO7eIWxlxdbxRrAf4KNzmH8LFm1013f9hg0aQ 9fk5bsZnwIV14xNVAgad0Poa2bd03UPeq6XkZ21Xi0MsJswCXuaVEmgLCk4qujMBX2QaorwoaRakrF EUO9SN/mqNshY7Kgyr0zRwaouC65QbcfqVSYWEzLh4WyA5mj/kv0sUzyapHqmo0NV9++899JMyo1nA U07F/cjEzyusa6glab3YSdPyW/4DdjUlaCqCjO1xyV2CKiBvsYGIWPG6b1v/hCHhe3CPQwk1QrNuBj /vev1MyEiz3hSEktD4mk8bW0x2Q2OXQ== X-Originating-IP: 172.105.109.24 X-MHO-RoutePath: c2lta2lu X-MHO-User: b88433ea-56be-11ec-a681-89389772cfc7 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Mail-Handler: DuoCircle Outbound SMTP Received: from athena.simkin.ca (athena.simkin.ca [172.105.109.24]) by outbound4.ore.mailhop.org (Halon) with ESMTPSA id b88433ea-56be-11ec-a681-89389772cfc7; Mon, 06 Dec 2021 18:02:49 +0000 (UTC) Received: from skynet.simkin.ca (node-1w7jr9sr73xr4ze19xwgjcteu.ipv6.telus.net [IPv6:2001:569:bce0:6400:fa75:a4ff:fe2f:92e6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by athena.simkin.ca (Postfix) with ESMTPSA id E69A9C6A13DB for ; Mon, 6 Dec 2021 10:02:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.simkin.ca; s=athena; t=1638813767; bh=cZT9sohv+lbqV52xzRmLVbK7IyPWh8t93RQ4JK/zCUQ=; h=Subject:From:To:Date:From:To:Subject:Date:Reply-To; b=TbwhPiSNESoP8FatW84zVqj2Sn1ryPh7Cqff/KH/So9x2vGP6X7vsZl0OhP5pPkAF lNkw3X9rUOI4oVojEzQjaQ/PkKbMI2MjhJYlXWOPuVLlbA1BaqiLN34oAbVZKfH0gx xq9DPo6lcgbPCg3LHHdsoyGvWEKUiJBSBkPcyDolwnavqib3a987YF3bJAXrieZwTm Ljm3JdbdeHJCeAxLkEoEI4pqebhGAHb1SsPGCF+fwpTdby1s9W336widl0AIPWTOjM Vh9KplCATYLEAN5XqmaeQkOPZTd63xho10vLy1q12FfvbgomzqlZwxmWlYJkbGMkwZ BzW1liB92BZsQ== Received: from skynet.simkin.ca (skynet.simkin.ca [IPv6:::1]) by skynet.simkin.ca (Postfix) with ESMTP id 2EE00105B1B00 for ; Mon, 6 Dec 2021 10:02:44 -0800 (PST) Message-ID: <222a1e5472e33656a1167facfccd722ddecfbc66.camel@lists.simkin.ca> Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT From: Alan Hodgson To: pgsql-general@lists.postgresql.org Date: Mon, 06 Dec 2021 10:02:44 -0800 In-Reply-To: References: Content-Type: multipart/alternative; boundary="=-FdXno2ckF6ufPhCLa8C7" X-PGP-Key: fp="EF82 6F8D A3BA A096 FFA3 05F2 A7A0 40A5 34E5 AA0B"; id="0x34E5AA0B"; get= User-Agent: Evolution 3.40.4 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-FdXno2ckF6ufPhCLa8C7 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: 8bit 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. Thank you for the suggestions. --=-FdXno2ckF6ufPhCLa8C7 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
On Mon, 2021-12-06 at 10:19 -0700, Rob Sargen= t wrote:
To be clear, is it the devs o= r 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?) a= nd
any record will do?.  For the former they might be b= etter off asking for
just the attributes they need and for t= he 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, t= alk to them, and then get them to actually think about what data they're lo= oking 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 loo= king for something common to all the records they would look at the parent = table instead.

I do expect the dev actually specif= ied the order/limit for some reason.

Thank you for= the suggestions.
--=-FdXno2ckF6ufPhCLa8C7--