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 1pSVDH-0004pO-9b for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 03:45:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSVDE-0000bj-Gt for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 03:45:36 +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 1pSVDE-0000b1-3R for pgsql-general@lists.postgresql.org; Thu, 16 Feb 2023 03:45:36 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pSVCz-0001VN-TY for pgsql-general@lists.postgresql.org; Thu, 16 Feb 2023 03:45:34 +0000 Received: by mail-ed1-x52f.google.com with SMTP id fj20so1098833edb.1 for ; Wed, 15 Feb 2023 19:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=N/lrmNwaxnFHlPHyJ7GLLPvg/sP/7Byu2EofmFt1/uA=; b=fOXqvGV/WftqcfxIGQ1sVtKvOfhyNL3KqZXhQfi0gB8yuj/SrrsX3FXUvCoZ9dFHHi 0eMI6VVbM47uv7wWpe8tmysOTeB5ba/vpODNh8eJTWVNVjg2VYDqjUpgxL/GDVc3Lde7 wXj2bCWzGpWJZqlYtrxyZN3yiR6fKjyBVlh61FupCdRTKFtA6cdAiN/is9QPvDlhBZ5s pBehygmXLsKzzvhq4/1fS3QF+kohVTKeaQcxak+XhxaaGcrvN/8R6S+8KIrPQHrD1N+Z CYrCwdF8nirZYLf8FUYy9ZBfmH6qjo4xNgS8V3Gn0x07GLLX1e7lXMt3kq+giEIi8OPp SpiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=N/lrmNwaxnFHlPHyJ7GLLPvg/sP/7Byu2EofmFt1/uA=; b=fFlTeZdVrmwOl3R4L5SCstyZ3gc5VOXDm70UFYGFdYlsnNTkydFBXKvMBDpi97V3z6 Xkt8YLCKi1/MQuaBkIQ97YarWUO23438n5NhvunXIbGdyWAZ3jOF8rrxa19VxMNyhVqP KZL6F36B5ny0mHgINfDZ0f9xDi7qhwBet8Y34jXBetP382pozBSoL80kveeTstx9Trqy 078FIN4owvs004g1hYwXEDoAOoj7lbny2tBC5YDYLX5HO8738VgyueaWE0ChFGMPrGk8 fAuiMi8pf2s/iPqtglR4WvofbEX93fuwxpflnPO7Lspkg4Y5jBiD2h38mYREnHtd22cX anRQ== X-Gm-Message-State: AO0yUKXsCr6AFGsLXk9XfSybR1uSlkXGhQHvkPxo8rlN+0lrIEwYhTF5 ag0EoTyaXa0wNpl6smP970sITQ== X-Google-Smtp-Source: AK7set/tWuVI7YLSO9o0G7pFIFEj5e4O9TO7waYEH23bLiiBwKL0Tj25dI134eahtE324mjCmATqMg== X-Received: by 2002:aa7:c6d7:0:b0:4ac:bdf3:36ce with SMTP id b23-20020aa7c6d7000000b004acbdf336cemr3781870eds.13.1676519119305; Wed, 15 Feb 2023 19:45:19 -0800 (PST) Received: from localhost.localdomain (62-46-251-54.adsl.highway.telekom.at. [62.46.251.54]) by smtp.gmail.com with ESMTPSA id u28-20020a50a41c000000b004a0e2fe619esm218727edb.39.2023.02.15.19.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 19:45:18 -0800 (PST) Message-ID: <121cb8239ebfea29f059a263dc2a920f1f3f8604.camel@cybertec.at> Subject: Re: Multi-column index: Which column order From: Laurenz Albe To: Ron , pgsql-general@lists.postgresql.org Date: Thu, 16 Feb 2023 04:45:18 +0100 In-Reply-To: <3728c419-a158-4821-d736-dbd63a79c30d@gmail.com> References: <8780fa45a4041e4229f4a3fa88a61778d8534ab2.camel@cybertec.at> <3728c419-a158-4821-d736-dbd63a79c30d@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 (3.46.3-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2023-02-15 at 10:20 -0600, Ron wrote: > On 2/15/23 02:46, Laurenz Albe wrote: > > Which one is best? > > > CREATE UNIQUE INDEX ix1 ON art (code, etb) > > > or > > > CREATE UNIQUE INDEX ix1 ON art (etb, code) > > >=20 > > > (or its PRIMARY KEY equivalent) > > Both are the same. > >=20 > > There is an old myth that says that you should use the more selective c= olumn first > > (which would be "code"), but that is just a myth. >=20 > Only on Postgresql? No, on all relational databases that use B-tree indexes. Look at how many index entries have to be scanned in both cases, and you wi= ll see. Yours, Laurenz Albe