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 1szF4o-0050o7-Fr for pgsql-general@arkaria.postgresql.org; Fri, 11 Oct 2024 12:49: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 1szF4m-003c7X-Bw for pgsql-general@arkaria.postgresql.org; Fri, 11 Oct 2024 12:49:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1szF4m-003c7N-1S for pgsql-general@lists.postgresql.org; Fri, 11 Oct 2024 12:49:00 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1szF4j-000Mln-Us for pgsql-general@lists.postgresql.org; Fri, 11 Oct 2024 12:48:59 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-539e1543ab8so824254e87.2 for ; Fri, 11 Oct 2024 05:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728650936; x=1729255736; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8S4rs6LdEh4HVCYlw0qYPfCS4gjggEJQ2Fq9XIReU6w=; b=O7xrzwUkyN7F8UjSQIW40ICeISKbGa54cfHIGFu+G3WXzWBOdNLm8kRiLd2lwrhh9k SvduIp5esrIGK7FptaLAEOmy1/pNUGX+3kMpo5WMPrmO9N+eMQsrU3nmDisKXQEjkpm1 dlX1fiQJidsSEonFe2p+1WG07GN7PmKwt/p/JTsPZ1XB3WNUrywW4/Ccvnibc/n7r0fq kGReMIYBDm5AY7uGDtCnUv7ynR5zdDC7xr/t/McjJ4RX/QGF7xNdgJ2uCIhN2/DuUGYZ LK7ebdUJ04g1k9cwEVWwuJdapOf++jkf8rb6UhNxkMFFta8OncOadV6HLEBJRKYbWiqg f9pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728650936; x=1729255736; h=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=8S4rs6LdEh4HVCYlw0qYPfCS4gjggEJQ2Fq9XIReU6w=; b=h3IfM9Ef1vxVWjIi0Qs5E+7vtrbTbKyDF3VQ7d5QzhTZ/i0otZIrVHRiVCZb/3mKyh pfVv8DsDZvPvLjfjmpWKIFZsVJTjfOZ1ac3KndNDKyFlBwEYf0fxgTuG4I1+GrdIcuJs K6TVvLpg5mNWpp+j65BpSU4sTaMxtbBSJjqv38xSSYgmoqhc1YnsUosNBFixltOAtAoO z1TF2E9+KkYeRa5EmpovwXBI+9wnDudDYkFPT834SUuXf9B8yWtjInWvGTeyEh6IcuBU 3tuzxEz8k4fxd5cbv7ioF9De/jPA8aneuB3w+alalLN6m0Q+Fry2MmWTN0Y883ZR7mZq 36fQ== X-Forwarded-Encrypted: i=1; AJvYcCUt0iU4m9UQm5LuuO/VTHOgaecwu/ok2NIxTFJFnCIGfHA8ZsBd9EhWBXiMKMUxOUf35xH70w5MemfIkxe0@lists.postgresql.org X-Gm-Message-State: AOJu0Yx4XkQ7tKNu/j+szgYN6ya8eW3oTepSJen0w/1qkyW8StzHKjbD eO2/Lsws5juu482Qm8VTZD9JQugrqQ90i7PbRm3X+pDJXSRiNiZaHQA8aOGk1+BNC/n+xQf6I+O PxTVYy1hGp3BM9xY2yVqp1QVSWKiWGp1C X-Google-Smtp-Source: AGHT+IE5SW8JUb97On+s0Sr4azQ1Nf0U6UiRJSJ5XIstjXVSzx1F36NDzOLnNDLa+DeFsXcEh9jEIy9y8tOo7Z4Mqlo= X-Received: by 2002:a05:6512:b17:b0:539:8fbd:5218 with SMTP id 2adb3069b0e04-539da5938a6mr2175808e87.56.1728650935856; Fri, 11 Oct 2024 05:48:55 -0700 (PDT) MIME-Version: 1.0 References: <88e5c335-c70e-4973-9b71-6c12e251e5b7@ewie.name> In-Reply-To: From: Greg Sabino Mullane Date: Fri, 11 Oct 2024 08:48:19 -0400 Message-ID: Subject: Re: Question on indexes To: Durgamahesh Manne Cc: sud , Erik Wienhold , xof@thebuild.com, pgsql-general Content-Type: multipart/alternative; boundary="000000000000f8f997062432e874" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f8f997062432e874 Content-Type: text/plain; charset="UTF-8" (please start a new thread in the future rather than replying to an existing one) You cannot query on b and use an index on (a,b) as you observed. However, you can have two indexes: index1(a) index2(b) Postgres will be able to combine those when needed in the case where your WHERE clause needs to filter by both columns. So then you no longer need the two-column index. Cheers, Greg --000000000000f8f997062432e874 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
(please start a new thread in the future rather than reply= ing to an existing one)

You cannot query on b and use an= index on (a,b) as you observed. However, you can have two indexes:

index1(a)
index2(b)

Po= stgres will be able to combine those when needed in the case where your WHE= RE clause needs to filter by both columns. So then you no longer need the t= wo-column index.

Cheers,
Greg
=

--000000000000f8f997062432e874--