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 1qRRrN-001lom-8Q for pgsql-admin@arkaria.postgresql.org; Thu, 03 Aug 2023 06:30:57 +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 1qRRrL-00AWaE-AD for pgsql-admin@arkaria.postgresql.org; Thu, 03 Aug 2023 06:30:55 +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 1qRRrK-00AWa6-SD for pgsql-admin@lists.postgresql.org; Thu, 03 Aug 2023 06:30:55 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qRRrE-000HT3-CG for pgsql-admin@lists.postgresql.org; Thu, 03 Aug 2023 06:30:54 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbea14700bso6018045e9.3 for ; Wed, 02 Aug 2023 23:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20221208.gappssmtp.com; s=20221208; t=1691044246; x=1691649046; 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=0USzoRSYL3OBuyCjCrAoEG7Bg7EBne3sJp0QEhMx5+M=; b=sOZLK9ZZwCTug80L2WXW9DmQO3yI2bVyteNOTO8+mdxHjxBJsf0quQNn9Dl++DpY9i Ef9vGpPRN7JEs3RbSqs4LuMv2KHK1+kpy2PeFEWajzzmSnI62KguDYf8DcpKJsTh4J8t aZZbEcsrhLQJnZ1/WfIL95WqhgE7wHYB6NoiB4oMpJVS0yMb8l0OHuTzjL+dtmBPUo3Z rEjZw3ERjWr5JKaTOaArLyJUC1edTrBB4OHGUR3boVa4aVROCfjYHN5X9aqjYwFNmdzv FUkeeAra8sjUBuRhGaDpl8Rp9iF9/RFwtj3jKJ+6aQbnerMN8ipD3/TDRe99e9NS/UeX 2ZAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691044246; x=1691649046; 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=0USzoRSYL3OBuyCjCrAoEG7Bg7EBne3sJp0QEhMx5+M=; b=TsjDUOjrnTeSS9mcOx53pyyU+SWUW2eeX9eDrMMdePbEXizWxarEaSnU7WoG6oWv3n QkgL0r2cRNkhEvU3Ptqq2ILomg0xT9/xoyZGUfThU0Fs2ma2bvAVleoIMturvyl6HtCX M4EXtig+9zL5FcUzOX6pfUsjSFm1+aqKa/2P6ZBbJzviH0OKhCPqbL1/WFj7eBZCfCIT ri1HztEWp/nCs68TGTra87tgrj/k0XVZJgqA9A3QSoFSIlqiMkMbNkvT+QmHAU9Fqh6j EdPNrduCdSCXOe76PIMGT0AOK/acdEDWf0DtZ2D1NQKmD9M1SBvJb52jH5DhZAgKYJu0 PHlw== X-Gm-Message-State: ABy/qLYTVvsYspCaF+93cF6wX2mEnbviumqx7AxG7mNJs9Fugkzgfmys b7yBnCt4HeT9plH5EB7/WH+eqkOD/Ungqtr6n+0= X-Google-Smtp-Source: APBJJlFy6eq6C5QuGqNeO0f1YTnyGAWHSsrySJj+GNcXXA675R6aDxKzcPPRbJSbVuzfe52NuKIV6Q== X-Received: by 2002:a05:600c:260c:b0:3fe:15e7:c8a1 with SMTP id h12-20020a05600c260c00b003fe15e7c8a1mr5853197wma.16.1691044245824; Wed, 02 Aug 2023 23:30:45 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:6acd:7737:df67:614a:2637]) by smtp.gmail.com with ESMTPSA id p26-20020a05600c205a00b003fe15c466f3sm5966187wmg.0.2023.08.02.23.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 23:30:45 -0700 (PDT) Message-ID: Subject: Re: Anyway to index array with other columns From: Laurenz Albe To: Chris Hoover , pgsql-admin@lists.postgresql.org Date: Thu, 03 Aug 2023 08:30:44 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2023-08-02 at 16:17 -0400, Chris Hoover wrote: > Given table below, is there any way to index =C2=A0field_a, field_b, arra= y_a? >=20 > Create table table1 ( > field_a integer not null primary key, > field_b integer not null, > ... > array_a text[] > ) >=20 > My app is running queries similar to this: > Select * from table1 where field_a =3D 123 and field_b =3D 456 and array_= a=C2=A0@> ARRAY[=E2=80=99tag_xyz=E2=80=99]; >=20 > The array_a can have unto 1000 elements. =C2=A0Currently these queries ge= t very expensive if the array has any length to it. That seems unlikely, since you have the primary key in the WHERE condition. Can you provide the output of EXPLAIN (ANALYZE, BUFFERS, VERBOSE) for the query? Yours, Laurenz Albe