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 1o48bL-0003kI-9q for pgsql-general@arkaria.postgresql.org; Wed, 22 Jun 2022 22:13:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o48bI-00087r-Bf for pgsql-general@arkaria.postgresql.org; Wed, 22 Jun 2022 22:13:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o48bI-00086U-1H for pgsql-general@lists.postgresql.org; Wed, 22 Jun 2022 22:13:28 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o48bD-0001x3-KF for pgsql-general@lists.postgresql.org; Wed, 22 Jun 2022 22:13:27 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id BC25F729E; Thu, 23 Jun 2022 00:13:21 +0200 (CEST) Date: Thu, 23 Jun 2022 00:13:21 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Tuning a query with ORDER BY and LIMIT Message-ID: <20220622221321.vjrapfkid3rprun5@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="u6wc6cib2bckecyx" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --u6wc6cib2bckecyx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2022-06-22 19:39:33 +0000, Dirschel, Steve wrote: > create index workflow_execution_initial_ui_tabs > on workflow_execution (workflow_id asc, status asc, result asc, > completed_datetime desc); [...] > explain (analyze, verbose, costs, buffers, timing, summary, hashes) > select * from workflow_execution > where workflow_id =3D 14560 and > status =3D 'COMPLETED' and > result =3D 'SUCCEEDED' > order by completed_datetime desc limit 50; This query should actually be able to use the index, since the first columns in the index are all compared to single values. So the you can just jump to the first matching index and then get the next 50 entries. > Is Postgres unable to optimize the query similar to Oracle? Is it possib= le > this is possible but we are running on too old of a version? PostgreSQL 10 is quite old, so that's a possibility. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --u6wc6cib2bckecyx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmKzk/wACgkQ8g5IURL+ KF2Wag//W065ISeEKiyy8Z2YlX6uSHyNhAW4zD1hNZ+odMP7aT8/4SQybyWwtGH9 KKGgGqnTAzMXqqMdhuto4p6r72QiYqXl8r59mblq8hNujSApHdJZYj4hsEzPQ2CY dXTdnX0Frwth9C1WbDlLSIrv6XAflLO39ttePPUn8Am/xYierBSshXBPi/InuIqO y/KHdpQNoDoj3FUYAsmqpYFpIWuia7i4HVaTUPXRgImIRH2NL1Z5usPbPM/ILB5Q PbC+kRapaE03s/eg/uVm+aKa889ebO2okcTOrp4fqJWyp8D3uklgXcgZZneEkjVN wxitlV9FBdlZOJVPCeKuHcEZdUyBwzl+OvBNbRkNbNlUsmm1G41xvGOWzWeKo0gT D+deOuLWBtsl50W2HY1N4amyVlaqWB88KOAu27zIK69OOpT++Wg8ByHvj/GT9c/o REVspVJWVO7svJ8cDmrFzBEq1jzsxf6S90XNbA1llj2gSAKWKgOMAtfMSzCsSxGy NceAZdK5ASuH5JESiMee3IgTP0qLnEOHGB93PZsamLKQumllQDOCxWkNsefviOGB 6muaJjs93Nazj5h70OwD/uMQs3GEsAr78dZlajLyo2pnOobKaeopxe82h4ai7z7E rlhVIw2k/nDFfidbfAu4xperfsXzbxnwlXjvE6Ol/NXl8ESUhD8= =z4Kq -----END PGP SIGNATURE----- --u6wc6cib2bckecyx--