Task search for a tag and ordered by id causes lp-oops
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Launchpad itself |
Triaged
|
High
|
Unassigned |
Bug Description
OOPS: https:/
When we do a task search via launchpadlib which looks for a certain tag and asks for ordering by id, we now reliably get an oops (caused by running too long). From memory this did not happen before. We can work around this by changing the query to not request any ordering, which actually is the better approach in our case as the code does not require results in any order (the constraint was added for debugging and then forgotten).
Testcase (example):
valid_states = [
'In Progress',
'Fix Committed',
'Fix Released',
]
search_tag = 'kernel-
tasks = launchpadservic
From internal discussions:
What seems to be going on is that the planner doesn't quite realise how selective the tag is: without the order_by="id", it correctly does an index-only scan on bugtag_
There are possible restructurings of the query that work (e.g. replacing the tag search clause with BugTaskFlat.bug IN (SELECT BugTag.bug FROM BugTag WHERE BugTag.tag IN (E'kernel-
Query plan with order_by="id":
launchpad_staging=> EXPLAIN (ANALYZE, BUFFERS) SELECT BugTaskFlat.bugtask
17,
20,
21,
22,
25,
30,
13,
14) duplicateof IS NULL product IS NULL release- tracking- bug-live' )) information_ type IN (1,
2) (BugTaskFlat. access_ grants) &&
(SELECT ARRAY_AGG( TeamParticipati on.team)
FROM TeamParticipation
WHERE TeamParticipati on.person = 1733822), FALSE) (BugTaskFlat. access_ policies) &&
(SELECT ARRAY_AGG( AccessPolicyGra nt.policy)
FROM AccessPolicyGrant
JOIN TeamParticipation ON TeamParticipati on.team = AccessPolicyGra nt.grantee
WHERE TeamParticipati on.person = 1733822), FALSE))
BugTaskFlat. bugtask DESC LIMIT 76
QUERY PLAN ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- -- 41..11674. 81 rows=76 width=8) (actual time=7901. 839..8206. 012 rows=76 loops=1) on_person_ idx on teamparticipation (cost=0.43..25.40 rows=126 width=4) (actual time=0.031..0.419 rows=117 loops=1)
Index Cond: (person = 1733822)
Buffers: shared hit=97 31..908. 32 rows=1 width=32) (actual time=3.503..3.503 rows=1 loops=1)
Buffers: shared hit=1866 read=18 on_person_ idx on teamparticipation teamparticipation_1 (cost=0.43..25.40 rows=126 width=4) (actual time=0.013..0.087 rows=117 loops=1)
Index Cond: (person = 1733822)
Buffers: shared hit=97 nt__g.. .
FROM BugTaskFlat
LEFT JOIN Product ON BugTaskFlat.product = Product.id
AND Product.active
WHERE BugTaskFlat.status IN (10,
AND BugTaskFlat.
AND (BugTaskFlat.
OR Product.active = TRUE)
AND EXISTS
(SELECT 1
FROM BugTag
WHERE BugTag.bug = BugTaskFlat.bug
AND BugTag.tag IN (E'kernel-
AND (BugTaskFlat.
OR COALESCE(
OR COALESCE(
ORDER BY BugTaskFlat.bug,
OFFSET 0;
-------
Limit (cost=939.
Buffers: shared hit=2079749 read=295069
InitPlan 1 (returns $0)
-> Aggregate (cost=25.71..25.72 rows=1 width=32) (actual time=0.453..0.454 rows=1 loops=1)
Buffers: shared hit=97
-> Index Scan using teamparticipati
InitPlan 2 (returns $2)
-> Aggregate (cost=908.
Buffers: shared hit=1866 read=18
-> Nested Loop (cost=0.85..908.19 rows=44 width=4) (actual time=0.046..3.128 rows=2133 loops=1)
-> Index Scan using teamparticipati
-> Index Only Scan using accesspolicygra