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 1gTr5T-0000RK-Ds for pgsql-general@arkaria.postgresql.org; Mon, 03 Dec 2018 16:28:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gTr5R-0000EN-Vx for pgsql-general@arkaria.postgresql.org; Mon, 03 Dec 2018 16:28:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTr5R-0000EG-EQ for pgsql-general@lists.postgresql.org; Mon, 03 Dec 2018 16:28:45 +0000 Received: from aart.rice.edu ([168.7.56.48]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gTr5J-0004OZ-CQ for pgsql-general@lists.postgresql.org; Mon, 03 Dec 2018 16:28:43 +0000 Received: by aart.rice.edu (Postfix, from userid 18612) id 9F05A427F281; Mon, 3 Dec 2018 10:28:36 -0600 (CST) Date: Mon, 3 Dec 2018 10:28:36 -0600 From: Kenneth Marshall To: pgsql-general@lists.postgresql.org Subject: Query never completes with an OR condition Message-ID: <20181203162836.GC16983@aart.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Mutt/1.5.21 (2010-09-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I was investigating a performance problem and found a query that never completes in a reasonable amount of time even though my expectation is that it should. I am running version 9.6.6. I do not see anything in the 9.6.* release notes that mention this problem. The individual queries run as expected, but when the OR condition is added, it never finishes. Here is the information about the tables and queries. Any ideas about what could be happening or how to debug it further would be appreciated. Regards, Ken ---------------------------------------------------------------- \d cachedgroupmembers Table "public.cachedgroupmembers" Column | Type | Modifiers = =20 -------------------+----------+--------------------------------------------= ----------------------------- id | integer | not null default nextval(('cachedgroupmembe= rs_id_seq'::text)::regclass) groupid | integer |=20 memberid | integer |=20 via | integer |=20 immediateparentid | integer |=20 disabled | smallint | not null default 0 Indexes: "cachedgroupmembers_pkey" PRIMARY KEY, btree (id) "cachedgroupmembers1" btree (memberid, immediateparentid) "cachedgroupmembers4" btree (memberid, groupid, disabled) "disgroumem" btree (groupid, memberid, disabled) "shredder_cgm2" btree (immediateparentid, memberid) "shredder_cgm3" btree (via, id) \d tickets Table "public.tickets" Column | Type | M= odifiers =20 -----------------+-----------------------------+---------------------------= ----------------------------------- id | integer | not null default nextval((= 'tickets_id_seq'::text)::regclass) effectiveid | integer | not null default 0 queue | integer | not null default 0 type | character varying(16) |=20 owner | integer | not null default 0 subject | character varying(200) | default '[no subject]'::ch= aracter varying initialpriority | integer | not null default 0 finalpriority | integer | not null default 0 priority | integer | not null default 0 timeestimated | integer | not null default 0 timeworked | integer | not null default 0 status | character varying(64) |=20 timeleft | integer | not null default 0 told | timestamp without time zone |=20 starts | timestamp without time zone |=20 started | timestamp without time zone |=20 due | timestamp without time zone |=20 resolved | timestamp without time zone |=20 lastupdatedby | integer | not null default 0 lastupdated | timestamp without time zone |=20 creator | integer | not null default 0 created | timestamp without time zone |=20 ismerged | smallint |=20 sla | character varying(64) |=20 Indexes: "tickets_pkey" PRIMARY KEY, btree (id) "tickets1" btree (queue, status) "tickets2" btree (owner) "tickets3" btree (effectiveid) "tickets4" btree (status) "tickets_merged_helper" btree ((effectiveid - id)) EXPLAIN (ANALYZE, BUFFERS) SELECT COUNT(DISTINCT main.id) FROM Tickets main= JOIN CachedGroupMembers CachedGroupMembers_1 ON ( CachedGroupMembers_1.Di= sabled =3D '0' ) AND ( CachedGroupMembers_1.MemberId =3D main.Owner ) JOIN = CachedGroupMembers CachedGroupMembers_2 ON ( CachedGroupMembers_2.Disabled= =3D '0' ) AND ( CachedGroupMembers_2.MemberId =3D main.Owner ) LEFT JOIN G= roups Groups_3 ON ( LOWER(Groups_3.Domain) =3D 'rt::ticket-role' ) AND ( G= roups_3.Instance =3D main.id ) LEFT JOIN CachedGroupMembers CachedGroupMemb= ers_4 ON ( CachedGroupMembers_4.Disabled =3D '0' ) AND ( CachedGroupMember= s_4.MemberId =3D '579312' ) AND ( CachedGroupMembers_4.GroupId =3D Groups_3= =2Eid ) WHERE ( ( main.Queue IN ('3', '3', '7', '7', '4', '4', '6', '6', '= 18', '18', '1', '1', '8', '8', '17', '17', '11', '11', '15', '15', '23', '2= 3', '20', '20', '22', '22', '21', '21', '12', '12', '14', '14', '19', '19',= '10', '10', '5', '5', '9', '9', '28', '28', '38', '38', '30', '30', '34', = '34', '37', '37', '31', '31', '32', '32', '36', '36', '33', '33', '35', '35= ', '41', '41', '40', '40', '42', '42', '43', '43', '39', '39', '51', '51', = '52', '52', '53', '53', '61', '63', '63', '64', '66', '68', '69', '69', '71= ', '71', '72', '72', '73', '73', '70', '70', '75', '75', '81', '81', '82', = '82', '83', '83', '84', '84', '86', '86', '87', '89', '89', '90', '90', '92= ', '92', '93', '93', '94', '94', '91', '24', '24', '95', '95', '97', '97', = '98', '98', '103', '103', '105', '106', '106', '107', '107', '112', '112', = '109', '109', '110', '110', '111', '111', '113', '113', '114', '114', '117'= , '117', '118', '118', '120', '120', '119', '119', '116', '116', '115', '11= 5', '121', '121', '122', '122', '124', '124', '123', '123', '125', '125', '= 126', '126', '127', '127', '137', '138', '138', '140', '140', '133', '134',= '133', '153', '153', '154', '154', '155', '155', '156', '156', '132', '157= ', '157', '158', '158', '160', '160', '162', '162', '165', '165', '167', '1= 68', '169', '169', '170', '170', '173', '179', '179', '181', '181', '184', = '184', '185', '185', '187', '187', '164', '164', '190', '190', '191', '228'= , '80', '80', '230', '230', '231', '231', '183', '183', '232', '232', '27',= '233', '13', '13', '241', '242', '243', '243', '245', '244', '251', '16', = '29', '253', '253', '256', '257', '257', '242', '258', '261') OR ( CachedG= roupMembers_4.MemberId IS NOT NULL AND LOWER(Groups_3.Name) =3D 'requestor'= ) OR ( main.Owner =3D '579312' ) OR ( CachedGroupMembers_4.MemberId IS= NOT NULL AND LOWER(Groups_3.Name) =3D 'admincc' ) ) ) AND (main.IsMerged = IS NULL) AND (main.Status !=3D 'deleted') AND (main.Type =3D 'ticket') AND = CachedGroupMembers_1.GroupId =3D '3424108'; = = =20 = = =20 = QUERY= PLAN =20 = = =20 = = =20 = =20 ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= --------------- Aggregate (cost=3D890494.02..890494.03 rows=3D1 width=3D8) (actual time= =3D81.250..81.250 rows=3D1 loops=3D1) Buffers: shared hit=3D9273 read=3D20 -> Nested Loop (cost=3D32766.63..91115.22 rows=3D319751521 width=3D4) = (actual time=3D31.596..73.081 rows=3D45688 loops=3D1) Join Filter: (cachedgroupmembers_1.memberid =3D cachedgroupmembers= _2.memberid) Buffers: shared hit=3D9273 read=3D20 -> Hash Right Join (cost=3D32766.20..32774.87 rows=3D51916 width= =3D12) (actual time=3D24.132..24.740 rows=3D192 loops=3D1) Hash Cond: (cachedgroupmembers_4.groupid =3D groups_3.id) Filter: ((main.queue =3D ANY ('{3,3,7,7,4,4,6,6,18,18,1,1,8,= 8,17,17,11,11,15,15,23,23,20,20,22,22,21,21,12,12,14,14,19,19,10,10,5,5,9,9= ,28,28,38,38,30,30,34,34,37,37,31,31,32,32,36,36,33,33,35,35,41 ,41,40,40,42,42,43,43,39,39,51,51,52,52,53,53,61,63,63,64,66,68,69,69,71,71= ,72,72,73,73,70,70,75,75,81,81,82,82,83,83,84,84,86,86,87,89,89,90,90,92,92= ,93,93,94,94,91,24,24,95,95,97,97,98,98,103,103,105,106,106,1 07,107,112,112,109,109,110,110,111,111,113,113,114,114,117,117,118,118,120,= 120,119,119,116,116,115,115,121,121,122,122,124,124,123,123,125,125,126,126= ,127,127,137,138,138,140,140,133,134,133,153,153,154,154,155, 155,156,156,132,157,157,158,158,160,160,162,162,165,165,167,168,169,169,170= ,170,173,179,179,181,181,184,184,185,185,187,187,164,164,190,190,191,228,80= ,80,230,230,231,231,183,183,232,232,27,233,13,13,241,242,243, 243,245,244,251,16,29,253,253,256,257,257,242,258,261}'::integer[])) OR ((c= achedgroupmembers_4.memberid IS NOT NULL) AND (lower((groups_3.name)::text)= =3D 'requestor'::text)) OR (main.owner =3D 579312) OR ((cachedgr oupmembers_4.memberid IS NOT NULL) AND (lower((groups_3.name)::text) =3D 'a= dmincc'::text))) Buffers: shared hit=3D331 read=3D9 -> Index Only Scan using cachedgroupmembers4 on cachedgroup= members cachedgroupmembers_4 (cost=3D0.43..8.71 rows=3D14 width=3D8) (actu= al time=3D11.197..11.229 rows=3D123 loops=3D1) Index Cond: ((memberid =3D 579312) AND (disabled =3D '= 0'::smallint)) Heap Fetches: 24 Buffers: shared hit=3D40 read=3D2 -> Hash (cost=3D32000.44..32000.44 rows=3D61226 width=3D26= ) (actual time=3D12.729..12.729 rows=3D192 loops=3D1) Buckets: 65536 Batches: 1 Memory Usage: 524kB Buffers: shared hit=3D291 read=3D7 -> Nested Loop Left Join (cost=3D61.17..32000.44 row= s=3D61226 width=3D26) (actual time=3D0.163..12.646 rows=3D192 loops=3D1) Buffers: shared hit=3D291 read=3D7 -> Nested Loop (cost=3D60.74..15885.97 rows=3D= 18304 width=3D16) (actual time=3D0.128..11.807 rows=3D48 loops=3D1) Buffers: shared hit=3D88 read=3D7 -> Index Only Scan using disgroumem on ca= chedgroupmembers cachedgroupmembers_1 (cost=3D0.43..8.49 rows=3D3 width=3D= 4) (actual time=3D0.018..0.029 rows=3D6 loops=3D1) Index Cond: ((groupid =3D 3424108) A= ND (disabled =3D '0'::smallint)) Heap Fetches: 3 Buffers: shared hit=3D7 -> Bitmap Heap Scan on tickets main (cos= t=3D60.31..5278.15 rows=3D1434 width=3D12) (actual time=3D1.925..1.958 rows= =3D8 loops=3D6) Recheck Cond: (owner =3D cachedgroup= members_1.memberid) Filter: ((ismerged IS NULL) AND ((st= atus)::text <> 'deleted'::text) AND ((type)::text =3D 'ticket'::text)) Rows Removed by Filter: 1 Heap Blocks: exact=3D70 Buffers: shared hit=3D81 read=3D7 -> Bitmap Index Scan on tickets2 (= cost=3D0.00..59.95 rows=3D1537 width=3D0) (actual time=3D1.914..1.914 rows= =3D14 loops=3D6) Index Cond: (owner =3D cachedg= roupmembers_1.memberid) Buffers: shared hit=3D11 read= =3D7 -> Index Scan using groups3 on groups groups_3 = (cost=3D0.43..0.84 rows=3D4 width=3D14) (actual time=3D0.012..0.016 rows= =3D4 loops=3D48) Index Cond: (instance =3D main.id) Filter: (lower((domain)::text) =3D 'rt::ti= cket-role'::text) Rows Removed by Filter: 0 Buffers: shared hit=3D203 -> Index Only Scan using cachedgroupmembers4 on cachedgroupmember= s cachedgroupmembers_2 (cost=3D0.43..0.90 rows=3D18 width=3D4) (actual tim= e=3D0.111..0.209 rows=3D238 loops=3D192) Index Cond: ((memberid =3D main.owner) AND (disabled =3D '0'= ::smallint)) Heap Fetches: 5028 Buffers: shared hit=3D8942 read=3D11 Planning time: 2.858 ms Execution time: 81.335 ms (44 rows) EXPLAIN (ANALYZE, BUFFERS) SELECT COUNT(DISTINCT main.id) FROM Tickets main= JOIN CachedGroupMembers CachedGroupMembers_1 ON ( CachedGroupMembers_1.Di= sabled =3D '0' ) AND ( CachedGroupMembers_1.MemberId =3D main.Owner ) JOIN = CachedGroupMembers CachedGroupMembers_2 ON ( CachedGroupMembers_2.Disabled= =3D '0' ) AND ( CachedGroupMembers_2.MemberId =3D main.Owner ) LEFT JOIN G= roups Groups_3 ON ( LOWER(Groups_3.Domain) =3D 'rt::ticket-role' ) AND ( G= roups_3.Instance =3D main.id ) LEFT JOIN CachedGroupMembers CachedGroupMemb= ers_4 ON ( CachedGroupMembers_4.Disabled =3D '0' ) AND ( CachedGroupMember= s_4.MemberId =3D '579312' ) AND ( CachedGroupMembers_4.GroupId =3D Groups_3= =2Eid ) WHERE ( ( main.Queue IN ('3', '3', '7', '7', '4', '4', '6', '6', '= 18', '18', '1', '1', '8', '8', '17', '17', '11', '11', '15', '15', '23', '2= 3', '20', '20', '22', '22', '21', '21', '12', '12', '14', '14', '19', '19',= '10', '10', '5', '5', '9', '9', '28', '28', '38', '38', '30', '30', '34', = '34', '37', '37', '31', '31', '32', '32', '36', '36', '33', '33', '35', '35= ', '41', '41', '40', '40', '42', '42', '43', '43', '39', '39', '51', '51', = '52', '52', '53', '53', '61', '63', '63', '64', '66', '68', '69', '69', '71= ', '71', '72', '72', '73', '73', '70', '70', '75', '75', '81', '81', '82', = '82', '83', '83', '84', '84', '86', '86', '87', '89', '89', '90', '90', '92= ', '92', '93', '93', '94', '94', '91', '24', '24', '95', '95', '97', '97', = '98', '98', '103', '103', '105', '106', '106', '107', '107', '112', '112', = '109', '109', '110', '110', '111', '111', '113', '113', '114', '114', '117'= , '117', '118', '118', '120', '120', '119', '119', '116', '116', '115', '11= 5', '121', '121', '122', '122', '124', '124', '123', '123', '125', '125', '= 126', '126', '127', '127', '137', '138', '138', '140', '140', '133', '134',= '133', '153', '153', '154', '154', '155', '155', '156', '156', '132', '157= ', '157', '158', '158', '160', '160', '162', '162', '165', '165', '167', '1= 68', '169', '169', '170', '170', '173', '179', '179', '181', '181', '184', = '184', '185', '185', '187', '187', '164', '164', '190', '190', '191', '228'= , '80', '80', '230', '230', '231', '231', '183', '183', '232', '232', '27',= '233', '13', '13', '241', '242', '243', '243', '245', '244', '251', '16', = '29', '253', '253', '256', '257', '257', '242', '258', '261') OR ( CachedG= roupMembers_4.MemberId IS NOT NULL AND LOWER(Groups_3.Name) =3D 'requestor'= ) OR ( main.Owner =3D '579312' ) OR ( CachedGroupMembers_4.MemberId IS= NOT NULL AND LOWER(Groups_3.Name) =3D 'admincc' ) ) ) AND (main.IsMerged = IS NULL) AND (main.Status !=3D 'deleted') AND (main.Type =3D 'ticket') AND = CachedGroupMembers_1.GroupId =3D '3424109'; = = =20 = = =20 = QUERY= PLAN =20 = = =20 = = =20 = =20 ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= --------------- Aggregate (cost=3D890494.02..890494.03 rows=3D1 width=3D8) (actual time= =3D21.748..21.748 rows=3D1 loops=3D1) Buffers: shared hit=3D7778 -> Nested Loop (cost=3D32766.63..91115.22 rows=3D319751521 width=3D4) = (actual time=3D0.755..16.059 rows=3D37104 loops=3D1) Join Filter: (cachedgroupmembers_1.memberid =3D cachedgroupmembers= _2.memberid) Buffers: shared hit=3D7778 -> Hash Right Join (cost=3D32766.20..32774.87 rows=3D51916 width= =3D12) (actual time=3D0.747..1.236 rows=3D148 loops=3D1) Hash Cond: (cachedgroupmembers_4.groupid =3D groups_3.id) Filter: ((main.queue =3D ANY ('{3,3,7,7,4,4,6,6,18,18,1,1,8,= 8,17,17,11,11,15,15,23,23,20,20,22,22,21,21,12,12,14,14,19,19,10,10,5,5,9,9= ,28,28,38,38,30,30,34,34,37,37,31,31,32,32,36,36,33,33,35,35,41 ,41,40,40,42,42,43,43,39,39,51,51,52,52,53,53,61,63,63,64,66,68,69,69,71,71= ,72,72,73,73,70,70,75,75,81,81,82,82,83,83,84,84,86,86,87,89,89,90,90,92,92= ,93,93,94,94,91,24,24,95,95,97,97,98,98,103,103,105,106,106,1 07,107,112,112,109,109,110,110,111,111,113,113,114,114,117,117,118,118,120,= 120,119,119,116,116,115,115,121,121,122,122,124,124,123,123,125,125,126,126= ,127,127,137,138,138,140,140,133,134,133,153,153,154,154,155, 155,156,156,132,157,157,158,158,160,160,162,162,165,165,167,168,169,169,170= ,170,173,179,179,181,181,184,184,185,185,187,187,164,164,190,190,191,228,80= ,80,230,230,231,231,183,183,232,232,27,233,13,13,241,242,243, 243,245,244,251,16,29,253,253,256,257,257,242,258,261}'::integer[])) OR ((c= achedgroupmembers_4.memberid IS NOT NULL) AND (lower((groups_3.name)::text)= =3D 'requestor'::text)) OR (main.owner =3D 579312) OR ((cachedgr oupmembers_4.memberid IS NOT NULL) AND (lower((groups_3.name)::text) =3D 'a= dmincc'::text))) Buffers: shared hit=3D265 -> Index Only Scan using cachedgroupmembers4 on cachedgroup= members cachedgroupmembers_4 (cost=3D0.43..8.71 rows=3D14 width=3D8) (actu= al time=3D0.010..0.047 rows=3D123 loops=3D1) Index Cond: ((memberid =3D 579312) AND (disabled =3D '= 0'::smallint)) Heap Fetches: 24 Buffers: shared hit=3D42 -> Hash (cost=3D32000.44..32000.44 rows=3D61226 width=3D26= ) (actual time=3D0.658..0.658 rows=3D148 loops=3D1) Buckets: 65536 Batches: 1 Memory Usage: 521kB Buffers: shared hit=3D223 -> Nested Loop Left Join (cost=3D61.17..32000.44 row= s=3D61226 width=3D26) (actual time=3D0.051..0.599 rows=3D148 loops=3D1) Buffers: shared hit=3D223 -> Nested Loop (cost=3D60.74..15885.97 rows=3D= 18304 width=3D16) (actual time=3D0.036..0.184 rows=3D37 loops=3D1) Buffers: shared hit=3D66 -> Index Only Scan using disgroumem on ca= chedgroupmembers cachedgroupmembers_1 (cost=3D0.43..8.49 rows=3D3 width=3D= 4) (actual time=3D0.009..0.020 rows=3D4 loops=3D1) Index Cond: ((groupid =3D 3424109) A= ND (disabled =3D '0'::smallint)) Heap Fetches: 1 Buffers: shared hit=3D5 -> Bitmap Heap Scan on tickets main (cos= t=3D60.31..5278.15 rows=3D1434 width=3D12) (actual time=3D0.012..0.036 rows= =3D9 loops=3D4) Recheck Cond: (owner =3D cachedgroup= members_1.memberid) Filter: ((ismerged IS NULL) AND ((st= atus)::text <> 'deleted'::text) AND ((type)::text =3D 'ticket'::text)) Rows Removed by Filter: 2 Heap Blocks: exact=3D49 Buffers: shared hit=3D61 -> Bitmap Index Scan on tickets2 (= cost=3D0.00..59.95 rows=3D1537 width=3D0) (actual time=3D0.007..0.007 rows= =3D14 loops=3D4) Index Cond: (owner =3D cachedg= roupmembers_1.memberid) Buffers: shared hit=3D12 -> Index Scan using groups3 on groups groups_3 = (cost=3D0.43..0.84 rows=3D4 width=3D14) (actual time=3D0.007..0.010 rows= =3D4 loops=3D37) Index Cond: (instance =3D main.id) Filter: (lower((domain)::text) =3D 'rt::ti= cket-role'::text) Rows Removed by Filter: 0 Buffers: shared hit=3D157 -> Index Only Scan using cachedgroupmembers4 on cachedgroupmember= s cachedgroupmembers_2 (cost=3D0.43..0.90 rows=3D18 width=3D4) (actual tim= e=3D0.004..0.055 rows=3D251 loops=3D148) Index Cond: ((memberid =3D main.owner) AND (disabled =3D '0'= ::smallint)) Heap Fetches: 4536 Buffers: shared hit=3D7513 Planning time: 2.869 ms Execution time: 21.823 ms (44 rows) EXPLAIN SELECT COUNT(DISTINCT main.id) FROM Tickets main JOIN CachedGroupMe= mbers CachedGroupMembers_1 ON ( CachedGroupMembers_1.Disabled =3D '0' ) AN= D ( CachedGroupMembers_1.MemberId =3D main.Owner ) JOIN CachedGroupMembers = CachedGroupMembers_2 ON ( CachedGroupMembers_2.Disabled =3D '0' ) AND ( Ca= chedGroupMembers_2.MemberId =3D main.Owner ) LEFT JOIN Groups Groups_3 ON = ( LOWER(Groups_3.Domain) =3D 'rt::ticket-role' ) AND ( Groups_3.Instance = =3D main.id ) LEFT JOIN CachedGroupMembers CachedGroupMembers_4 ON ( Cache= dGroupMembers_4.Disabled =3D '0' ) AND ( CachedGroupMembers_4.MemberId =3D = '579312' ) AND ( CachedGroupMembers_4.GroupId =3D Groups_3.id ) WHERE ( ( = main.Queue IN ('3', '3', '7', '7', '4', '4', '6', '6', '18', '18', '1', '1'= , '8', '8', '17', '17', '11', '11', '15', '15', '23', '23', '20', '20', '22= ', '22', '21', '21', '12', '12', '14', '14', '19', '19', '10', '10', '5', '= 5', '9', '9', '28', '28', '38', '38', '30', '30', '34', '34', '37', '37', '= 31', '31', '32', '32', '36', '36', '33', '33', '35', '35', '41', '41', '40'= , '40', '42', '42', '43', '43', '39', '39', '51', '51', '52', '52', '53', '= 53', '61', '63', '63', '64', '66', '68', '69', '69', '71', '71', '72', '72'= , '73', '73', '70', '70', '75', '75', '81', '81', '82', '82', '83', '83', '= 84', '84', '86', '86', '87', '89', '89', '90', '90', '92', '92', '93', '93'= , '94', '94', '91', '24', '24', '95', '95', '97', '97', '98', '98', '103', = '103', '105', '106', '106', '107', '107', '112', '112', '109', '109', '110'= , '110', '111', '111', '113', '113', '114', '114', '117', '117', '118', '11= 8', '120', '120', '119', '119', '116', '116', '115', '115', '121', '121', '= 122', '122', '124', '124', '123', '123', '125', '125', '126', '126', '127',= '127', '137', '138', '138', '140', '140', '133', '134', '133', '153', '153= ', '154', '154', '155', '155', '156', '156', '132', '157', '157', '158', '1= 58', '160', '160', '162', '162', '165', '165', '167', '168', '169', '169', = '170', '170', '173', '179', '179', '181', '181', '184', '184', '185', '185'= , '187', '187', '164', '164', '190', '190', '191', '228', '80', '80', '230'= , '230', '231', '231', '183', '183', '232', '232', '27', '233', '13', '13',= '241', '242', '243', '243', '245', '244', '251', '16', '29', '253', '253',= '256', '257', '257', '242', '258', '261') OR ( CachedGroupMembers_4.Membe= rId IS NOT NULL AND LOWER(Groups_3.Name) =3D 'requestor' ) OR ( main.Owne= r =3D '579312' ) OR ( CachedGroupMembers_4.MemberId IS NOT NULL AND LOWER= (Groups_3.Name) =3D 'admincc' ) ) ) AND (main.IsMerged IS NULL) AND (main.= Status !=3D 'deleted') AND (main.Type =3D 'ticket') AND (CachedGroupMembers= _1.GroupId =3D '3424108' OR CachedGroupMembers_2.GroupId =3D '3424109'); = = =20 = = =20 = QU= ERY PLAN =20 = = =20 = = =20 = =20 ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------- ---------------------------------------------------------------------------= --------------------- Aggregate (cost=3D15585087.22..15585087.23 rows=3D1 width=3D8) -> Merge Join (cost=3D2743321.81..13750588.06 rows=3D733799667 width= =3D4) Merge Cond: (cachedgroupmembers_1.memberid =3D main.owner) -> Sort (cost=3D2194090.30..2194196.31 rows=3D42404 width=3D8) Sort Key: cachedgroupmembers_1.memberid -> Gather (cost=3D1000.43..2190831.15 rows=3D42404 width= =3D8) Workers Planned: 2 -> Nested Loop (cost=3D0.43..2185590.75 rows=3D17668= width=3D8) -> Parallel Seq Scan on cachedgroupmembers cach= edgroupmembers_1 (cost=3D0.00..73131.51 rows=3D2323945 width=3D8) Filter: (disabled =3D '0'::smallint) -> Index Only Scan using cachedgroupmembers4 on= cachedgroupmembers cachedgroupmembers_2 (cost=3D0.43..0.90 rows=3D1 width= =3D8) Index Cond: ((memberid =3D cachedgroupmemb= ers_1.memberid) AND (disabled =3D '0'::smallint)) Filter: ((cachedgroupmembers_1.groupid =3D= 3424108) OR (groupid =3D 3424109)) -> Sort (cost=3D549231.51..555372.36 rows=3D2456341 width=3D8) Sort Key: main.owner -> Hash Left Join (cost=3D81156.63..288514.50 rows=3D24563= 41 width=3D8) Hash Cond: (groups_3.id =3D cachedgroupmembers_4.group= id) Filter: ((main.queue =3D ANY ('{3,3,7,7,4,4,6,6,18,18,= 1,1,8,8,17,17,11,11,15,15,23,23,20,20,22,22,21,21,12,12,14,14,19,19,10,10,5= ,5,9,9,28,28,38,38,30,30,34,34,37,37,31,31,32,32,36,36,33,33,35 ,35,41,41,40,40,42,42,43,43,39,39,51,51,52,52,53,53,61,63,63,64,66,68,69,69= ,71,71,72,72,73,73,70,70,75,75,81,81,82,82,83,83,84,84,86,86,87,89,89,90,90= ,92,92,93,93,94,94,91,24,24,95,95,97,97,98,98,103,103,105,106 ,106,107,107,112,112,109,109,110,110,111,111,113,113,114,114,117,117,118,11= 8,120,120,119,119,116,116,115,115,121,121,122,122,124,124,123,123,125,125,1= 26,126,127,127,137,138,138,140,140,133,134,133,153,153,154,15 4,155,155,156,156,132,157,157,158,158,160,160,162,162,165,165,167,168,169,1= 69,170,170,173,179,179,181,181,184,184,185,185,187,187,164,164,190,190,191,= 228,80,80,230,230,231,231,183,183,232,232,27,233,13,13,241,24 2,243,243,245,244,251,16,29,253,253,256,257,257,242,258,261}'::integer[])) = OR ((cachedgroupmembers_4.memberid IS NOT NULL) AND (lower((groups_3.name):= :text) =3D 'requestor'::text)) OR (main.owner =3D 579312) OR ((ca chedgroupmembers_4.memberid IS NOT NULL) AND (lower((groups_3.name)::text) = =3D 'admincc'::text))) -> Hash Right Join (cost=3D81147.75..230564.78 rows= =3D2896824 width=3D22) Hash Cond: (groups_3.instance =3D main.id) -> Seq Scan on groups groups_3 (cost=3D0.00..1= 08806.51 rows=3D3104608 width=3D14) Filter: (lower((domain)::text) =3D 'rt::ti= cket-role'::text) -> Hash (cost=3D70322.31..70322.31 rows=3D8660= 35 width=3D12) -> Seq Scan on tickets main (cost=3D0.00= =2E.70322.31 rows=3D866035 width=3D12) Filter: ((ismerged IS NULL) AND ((st= atus)::text <> 'deleted'::text) AND ((type)::text =3D 'ticket'::text)) -> Hash (cost=3D8.71..8.71 rows=3D14 width=3D8) -> Index Only Scan using cachedgroupmembers4 on= cachedgroupmembers cachedgroupmembers_4 (cost=3D0.43..8.71 rows=3D14 widt= h=3D8) Index Cond: ((memberid =3D 579312) AND (di= sabled =3D '0'::smallint)) (28 rows)