Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsxbc-0001QM-FE for pgsql-performance@arkaria.postgresql.org; Fri, 15 Sep 2017 20:52:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dsxbb-00080E-SG for pgsql-performance@arkaria.postgresql.org; Fri, 15 Sep 2017 20:52:55 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dsxZp-0004oz-VI for pgsql-performance@postgresql.org; Fri, 15 Sep 2017 20:51:06 +0000 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dsxZn-0006rC-1c for pgsql-performance@postgresql.org; Fri, 15 Sep 2017 20:51:05 +0000 Received: by mail-wr0-x22d.google.com with SMTP id 108so2664798wra.5 for ; Fri, 15 Sep 2017 13:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=yBBnAuvqh61QM07UorFObEEYCUEuHCElAOmc+4/6AGk=; b=I3NbdQRcspJW8R1yn+kwPR/Mt/vkfJsJ4DP9fIpr7DYFyQIm4HlqIXI6VpAv1/GzOf XVWo4wWCNA1PSdA8wzMxStQzIKLBbB3S+ziasxc3+rpVUWptYhzZnGI7yU2w01pbspsb NIJvG1GUfIhjxmYr0wo0WKWtg9uzo+jN7hZByRf51Y/DDW73cvz4sI2VlX8cMf4Jd0kL GbBrw4N0G6CzTiQrdm34W+HZZlBivkWC2KPqmApj17MtXhhY2SXyjNyJxwjqWJCOyFwd 3W6pFvzCivXrJO2tCf35CzL9qbv8mV1vmoeqm3XdU8Pm8n9PZGGwrozqDIPic6IhJZ49 5pdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=yBBnAuvqh61QM07UorFObEEYCUEuHCElAOmc+4/6AGk=; b=n2/Vy0rNtlgGsNYLGK/gyxeOfB9KqHRZPUqnRypZYfgDtZHRy5Dq9WVTo10ZVNLjZ1 X4YN9DN/QQ1hJi/PpkQe1YefgbZEeyQeE+Vcfx7VoSDRPg2WmXG5Zded8zz6Q/gPZQit cdAKCA/BF/XUDvExMJGgbQ43h3o2A702WjYzJZfGQhSDFbQCvSUYuO1zgWCQ9HLRdqei 8qD2papRa8cF2/VIJM8VY2E8u5f+7DT4fOg8kdMwDG/mMhUbdSOiN8AgVYDvkmKHVvlj cIl5avjUSUBLGalOSqNv3t2EJNNqMYqCxlz1mm3c+FqhWmy11kVqbhUEpfzkhTTCj08A I7lg== X-Gm-Message-State: AHPjjUgv1s2lVms+AinLIU11REUP4PJRTdv2u0iM9sMxUbBfqlkY7pMP 9sEAJEfpdH3ti3o+ddWNnY1F2+53fwzvKyjXHPffjA== X-Google-Smtp-Source: ADKCNb6ev3NVjwjbBIUu4I5vx7od17Uxmg3tYZ/S3WO3CTqw2U4ViWPBGMO1OduRbUVqWghNEJZReXlGvcX4+esYN+o= X-Received: by 10.223.187.129 with SMTP id q1mr22615391wrg.239.1505508661531; Fri, 15 Sep 2017 13:51:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.199.193 with HTTP; Fri, 15 Sep 2017 13:51:01 -0700 (PDT) From: Jeremy Finzel Date: Fri, 15 Sep 2017 15:51:01 -0500 Message-ID: Subject: Indexing an array of two separate columns To: postgres performance list Content-Type: multipart/alternative; boundary="089e08215428fa19c20559408c7c" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org --089e08215428fa19c20559408c7c Content-Type: text/plain; charset="UTF-8" I have a user who is trying to match overlapping duplicate phone info but for different customer_ids. The intended conditional could be expressed: IF the intersection of the sets {c.main_phone, c.secondary_phone} and {c1.main_phone, c1.secondary_phone} is not empty THEN join EXCEPT where the intersection of the sets = {'0000000000'} He wants a join like this: FROM customers c INNER JOIN customers c1 on (array[c.main_phone, c.secondary_phone] && array[nullif(c1.main_phone, '0000000000') , nullif(c1.secondary_phone, '0000000000')]) (array[c.main_phone, c.secondary_phone] && array[nullif(c1.main_phone, '0000000000') , nullif(c1.secondary_phone, '0000000000')]) WHERE c.customer_id = 1; I want to index this part: array[nullif(c1.main_phone, '0000000000') , nullif(c1.secondary_phone, '0000000000')] First of all I see I can't create a btree index on an array. And with btree_gin, this index is not being used: CREATE INDEX ON customers USING gin ((NULLIF(main_phone, '0000000000'::text)), (NULLIF(secondary_phone, '0000000000'::text))); What am I missing here? Is there a way to support a condition like this? Thank you! --089e08215428fa19c20559408c7c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I have a user who is trying to match overlapping duplicate= phone info but for different customer_ids. =C2=A0

= The intended conditional could be expressed:=C2=A0
IF the interse= ction of the sets
{c.main_phone, c.secondary_phone}
and=
{c1.main_phone, c1.secondary_phone}
is not empty=C2=A0=
THEN join=C2=A0
EXCEPT where the intersection of the s= ets =3D
{'0000000000'}

He = wants a join like this:

FROM customers c
INNER= JOIN customers c1 on (array[c.main_phone, c.secondary_phone] && = =C2=A0array[nullif(c1.main_phone, '0000000000') , nullif(c1.seconda= ry_phone, '0000000000')])
(array[c.main_phone, c.seco= ndary_phone] && array[nullif(c1.main_phone, '0000000000') ,= nullif(c1.secondary_phone, '0000000000')])
WHERE c.c= ustomer_id =3D 1;

I want to index this part:
=
array[nullif(c1.main_phone, '0000000000') , nullif(c1.secondar= y_phone, '0000000000')]

First of all I= see I can't create a btree index on an array.=C2=A0 And with btree_gin= , this index is not being used:

CREATE INDEX ON cu= stomers USING gin ((NULLIF(main_phone, '0000000000'::text)), (NULLI= F(secondary_phone, '0000000000'::text)));

<= div>What am I missing here?=C2=A0 Is there a way to support a condition lik= e this?

Thank you!
--089e08215428fa19c20559408c7c--