Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0CPu-00E5ME-5p for pgsql-general@arkaria.postgresql.org; Thu, 03 Apr 2025 04:43:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u0COu-002njg-1B for pgsql-general@arkaria.postgresql.org; Thu, 03 Apr 2025 04:42:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0COt-002njX-Kd for pgsql-general@lists.postgresql.org; Thu, 03 Apr 2025 04:41:59 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u0COq-0035of-3B for pgsql-general@lists.postgresql.org; Thu, 03 Apr 2025 04:41:59 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-30bf3f3539dso4954091fa.1 for ; Wed, 02 Apr 2025 21:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743655316; x=1744260116; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SwIpjbs664EHZEWMVs6DFrjaigUJcMJg3hIvdxBRQ5s=; b=Mht20qtLMEC2bQ2Siqu6ACdTDrUO8bA14FZzqF/li7wKmC273wbB+wDW4rwF64l1yk krQ/zCP5kfB8QcIzsSoLfspWq34T/KN+55Kk1FVuMJzpIwWJqNnGDlPcHbRalVHaVCOu Ui6EYStTq6BfeECjgRiSncmv25BabO6YyeyC3PnI51qcZtx53l78WMB6/W4IeS1soYET XIPGXBAOXlcLUbzKRqXJCaLXI0x8Hts1UGJ3gwQXFpN4ObGRDPaYW34yBTK0E3M9x/7Y ZtaXP44ohdUgKrYwRvS0xRUn3MSCYvo7omuRWjPftZMZhAev10y4Oqka2tQAEI8/XOA/ yDfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743655316; x=1744260116; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SwIpjbs664EHZEWMVs6DFrjaigUJcMJg3hIvdxBRQ5s=; b=HzCZ6WgUi0sbMJFdIoAdAHOadMrzgl9126uMJba6xHAPfmh6X4NkKtNcw/098uoCCR EVMFBj6hXWAn5eby2AQ5DxwCBiS30/vJQ/iuneIOLY79OtVvvuzbDRHWpZOx+Ob7GH+k ufRRWURwN4KMKaRANSIqd7jla5XCsTw5lNLkBYWETYmbIbnZ7FcCr8Xj19n1wHKC0Cnu CoL93RbXYqYnGsXGFpizUnaH+ms4eIO3bYelGpt2V3WvF5iLVrCMy1g3gckMlSNiyfUR tmahJRrukkoyjOkyEKdlCyRWc3Pn8chughNYSNDa27ZggBUextUAK0yaXBYuYNmUzUPG bLZA== X-Forwarded-Encrypted: i=1; AJvYcCXj1qbnLwFuyXxLxCiTf7H+9I6mI/6lo5wuASyoxSUVL22NvO2ZKLplZ4LyS53uSrD+KrZlWsLoP3JOwcg0@lists.postgresql.org X-Gm-Message-State: AOJu0YwYu+GIG5UFLFB0uTzyNQZXikT4rmTcc4IWpiM+3q7L4ElzQf6f 9ORSI38VeeXpaTB+kb31P35R4N75K8cCL8evA72lz574PjpPhUKz1rBHndRPeOf8y+3NJHrQL9V nMEvPhkXCctlNEFWlzbnZ0erZUpo= X-Gm-Gg: ASbGnctgmty3jDi8tLqzQXk7eM2T3cYy8E7T7WCvK21rVWWqU1JvFgzTgFMEishh6nX lOO8NZu+ikhMdpGxpg4q2lo7eFvoEPlnoizi4rzjesQmY7FPWXnSJ3kOappThmbBLaH3aJNnNXA zoY/QNJgZqLcT2O/ty8Gk7vJv8T7yjigJ6nozYSqKts/UCIkI5Nbolv2pRXOhb X-Google-Smtp-Source: AGHT+IGsucu/tmpKGiaP2FYKj/+wKhFMEfiVO4l6EiXa1r6bab08lqQ1neLe6/LvDBQTPToUacHZwrvXG1i80C4+Z04= X-Received: by 2002:a2e:b04a:0:b0:30b:9af5:9549 with SMTP id 38308e7fff4ca-30f00628d73mr6617381fa.2.1743655315376; Wed, 02 Apr 2025 21:41:55 -0700 (PDT) MIME-Version: 1.0 References: <1203098.1743640224@sss.pgh.pa.us> <2BC8AB39-16D7-4423-BE0A-F0F4EA432E2E@gmail.com> In-Reply-To: <2BC8AB39-16D7-4423-BE0A-F0F4EA432E2E@gmail.com> From: David Rowley Date: Thu, 3 Apr 2025 17:41:43 +1300 X-Gm-Features: AQ5f1JqSkFBM6AnNZq73nkVo2yfPiVjgq3aAMf-1QlYrDaFoPoFW8XmyUwlCliU Message-ID: Subject: Re: Postgres Query Plan using wrong index To: Manikandan Swaminathan Cc: Tom Lane , pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 3 Apr 2025 at 16:24, Manikandan Swaminathan wrote: > Since you mentioned the planner not knowing about the correlation between= the columns, I=E2=80=99m curious, why doesn=E2=80=99t making a multivariat= e statistic make a difference? > > > CREATE STATISTICS col_a_col_b_stats (dependencies) ON col_a, col_b FROM t= est_table; > ANALYZE test_table; Extended statistics won't help you here. "dependencies" just estimates functional dependencies between the columns mentioned in the ON clause. What we'd need to store to do better in your example query is positional information of where certain values are within indexes according to an ordered scan of the index. I don't quite know how we'd represent that exactly, but if we knew that a row matching col_a > 4996 wasn't until somewhere near the end of idx_col_a_btree index, then we'd likely not want to use that index for this query. David