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 1hH7O4-0000zJ-2g for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 13:47:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hH7O2-0003zI-RK for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 13:47:34 +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 1hH7O2-0003zB-Hf for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 13:47:34 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hH7O0-00035k-9P for pgsql-general@postgresql.org; Thu, 18 Apr 2019 13:47:34 +0000 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hH7Nz-000AYl-MG for pgsql-general@postgresql.org; Thu, 18 Apr 2019 15:47:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Harald Fuchs Subject: Re: Multicolumn index for single-column queries? Date: Thu, 18 Apr 2019 15:47:25 +0200 Message-ID: <87muknwhle.fsf@protecting.net> References: <95ade9a3-6846-3f55-f936-85b8bb4b46a8@mail.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Archive: encrypt X-PGP-Fingerprint: 09 4E C4 A2 B2 C5 33 1A 79 80 5D 39 BD 9B 89 39 X-Face: (1awP+uzUZkz*UdAvr%F%K`x9g3n,CWkrK[r6TS,kY~DP)$C&=IJQ;H0uPn0B$Rb>\w"Tk~9w';1@dNIad{z!y(R99X7d-uc~Vf%,i.:=~=V>.b_)hr36Jt.tF0OBe]&PB6F.(k[i^^v^8DBny^)@17gud{[!1jfZ8+ Cancel-Lock: sha1:V2xXKRazur97pJETxNVVhPhLpqM= X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andreas Kretschmer writes: > Am 18.04.19 um 08:52 schrieb rihad: >> Hi. Say there are 2 indexes: >> >>     "foo_index" btree (foo_id) >> >>     "multi_index" btree (foo_id, approved, expires_at) >> >> >> foo_id is an integer. Some queries involve all three columns in >> their WHERE clauses, some involve only foo_id. >> Would it be ok from general performance standpoint to remove >> foo_index and rely only on multi_index? I know that >> PG would have to do less work updating just one index compared to >> updating them both, but wouldn't searches >> on foo_id alone become slower? > > it depends . > > it depends on the queries you are using, on your workload. a > multi-column-index will be large than an index over just one column, > therefore you will have more disk-io when you read from such an index. I think it also depends on the average number of rows having the same foo_id.