Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBiX1-0006Rc-2x for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 16:14:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBiW1-0005YL-4L for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 16:13:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBiW0-0005Y8-Ov for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 16:13:28 +0000 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBiVy-0004qh-I5 for pgsql-general@postgresql.org; Wed, 03 Apr 2019 16:13:28 +0000 Received: by mail-qt1-x829.google.com with SMTP id w5so19938568qtb.11 for ; Wed, 03 Apr 2019 09:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=WRBpgc4lCBaqzlCWvlcHn5RDa8yOqSMa2ujvHQ+r+xk=; b=pZTqhPwuRpSGKaYReSXbUkKZw7WQJ0TBd//wrkbeGjSo6GZUXgPIdgEakui0QxnVyy u7kMrrhE9DDkvkJeyIMYLok5jask1Hp6GTmbGrlxme2S9A5jA7mgNqsfvF4SRqah0024 LhJRPfKzZIICw9F5O+typ7WvrR707SrlPbR+SUkOpS2cRy2iuc/m7sd+30grrPi97o/L IBxHlXtLU7F5q4ncz32v0V0TBTPovRojWCcoZ31jysiEmm4Euol38Eulsn7AT+WsGg9a yEIovVFUrTFm/A1zQ6+7hDksSSWgQX3xZn98i2vFIBoqvUxAH3Il47pYJBUPrKY2nwnP nzcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=WRBpgc4lCBaqzlCWvlcHn5RDa8yOqSMa2ujvHQ+r+xk=; b=tWnZWDG4+CM9RCba4HjnHEWL7Swt8mpYCJkGke0rohVDnwN/YzGvtbLCymdYSgGt5V BVIMLi3oiBEa/pMzQ/UiXtV3Whlk+4QK0lNUUG1FI0F6q4DhPBL1L8q6cPFpEnXhvWZv ZV/9oBI/WBg4F7ieqqEHmuV7r2PvUQu8lfpcyVDVXcyhS4qWDUPRSuLtPf+ZLK5vunDc w0Bj+zBCzvH4neDYyRV12eNM8jEkfhbNF1Bm7+leDqGBEQ1+Hoi/BqMpOvUulcztPXmt /dtx6edYuVQdC9X17X2ndCBzFWmq6qf9FnikpQjK1T/9XUXa5f024fc8eloLXohk3eC7 Gjxg== X-Gm-Message-State: APjAAAXv6OuwV2f6gCdEBgzZ5Z4W01j6O50OdHcl/7nu4Cedyuw7BUvx wOvHgbMX9sg/O4nCok9gMEfTiyww X-Google-Smtp-Source: APXvYqwZSBULWw7pBI3AlTH0G4aNEKtIpp+iTVnjwS/iRWDaWYIiXvLEmKmopPsMlTY67JXKm9GzuA== X-Received: by 2002:ac8:3032:: with SMTP id f47mr703330qte.105.1554308004075; Wed, 03 Apr 2019 09:13:24 -0700 (PDT) Received: from [192.168.212.192] ([38.142.23.50]) by smtp.gmail.com with ESMTPSA id a20sm9104309qth.88.2019.04.03.09.13.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 09:13:22 -0700 (PDT) From: Jonathan Marks Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Forcing index usage Message-Id: <679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com> Date: Wed, 3 Apr 2019 12:13:22 -0400 To: pgsql-general@postgresql.org X-Mailer: Apple Mail (2.3445.102.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi folks =E2=80=94 We=E2=80=99ve got several tables that are relatively large (~250-500GB = in total size) that use very large (tens to hundreds of GB) GIN indexes = for full-text search. We=E2=80=99ve set the column statistics for our = tsvector columns as high as they go (10,000). We almost always order our = search results by a separate date column (which has an index) and we = almost always use a limit. Whenever the query planner chooses to use the indexes, queries on these = tables are somewhat fast, maxing out at a few hundred milliseconds per = query (which is terrible, but acceptable to end users). When the query planner chooses not to use the indexes, queries can take = many tens of seconds if they ever finish at all. When this happens, the = query planner usually chooses to use the date index instead of the GIN = index, and that is almost always a bad idea. We have sometimes been able = to trick it into a better query plan by also adding the tsvector column = in the ORDER BY clause, but that has bad performance implications if the = result set is large. Is there a way to tell Postgres =E2=80=9Cplease don=E2=80=99t use index = X when queries that could use index Y instead occur?=E2=80=9D Thank you!=