[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OSSTEST PATCH 05/14] sg-report-flight: Use WITH to use best index use for $flightsq


  • To: Ian Jackson <Ian.Jackson@xxxxxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Wed, 22 Jul 2020 12:47:47 +0000
  • Accept-language: en-GB, en-US
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 22 Jul 2020 12:48:15 +0000
  • Ironport-sdr: QuNFg5IDhwSM4Fm4v5++nQSUz5awR7wWVkEXIacXNyJgGN/aImaFdFG0c4s9UrWDnB0ffmtg8z dQ9NDbVLVu2C8yFHbUhTBQ6TLWDxdfU2G4PL1aGPhpYGa+7mlwEIqixPrbmDJ3KPljMaHN/XTB ScROH88yerC5Z4wGMT2zLIxS+dJQ52JlIFzlfcxDWoqK3qwFjQPmQEx6UGGWx6fRa6gFBoncAV VPp0vALMVog9QrrHUgK1bnWqy/CVv9YOaPq5uV8Lp/j/zRKw6C5YBcoQywp2yeBwRpcE2y4lEM 8wI=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHWX46t5LGxeS+LX0KNSBltVaDWxqkTa/WA
  • Thread-topic: [OSSTEST PATCH 05/14] sg-report-flight: Use WITH to use best index use for $flightsq


> On Jul 21, 2020, at 7:41 PM, Ian Jackson <ian.jackson@xxxxxxxxxxxxx> wrote:
> 
> While we're here, convert this EXISTS subquery to a JOIN.
> 
> Perf: runtime of my test case now ~200-300s.
> 
> Example query before (from the Perl DBI trace):
> 
>      SELECT * FROM (
>        SELECT DISTINCT flight, blessing
>             FROM flights
>             JOIN runvars r1 USING (flight)
> 
>            WHERE (branch='xen-unstable')
>              AND ( (TRUE AND flight <= 151903) AND (blessing='real') )
>                  AND EXISTS (SELECT 1
>                            FROM jobs
>                           WHERE jobs.flight = flights.flight
>                             AND jobs.job = ?)
> 
>              AND r1.name LIKE 'built_revision_%'
>              AND r1.name = ?
>              AND r1.val= ?
> 
>            ORDER BY flight DESC
>            LIMIT 1000
>      ) AS sub
>      ORDER BY blessing ASC, flight DESC
> 
> With bind variables:
> 
>     "test-armhf-armhf-libvirt"
>     'built_revision_xen'
>     '165f3afbfc3db70fcfdccad07085cde0a03c858b'
> 
> After:
> 
>      WITH sub AS (
>        SELECT DISTINCT flight, blessing
>             FROM flights
>             JOIN runvars r1 USING (flight)
> 
>            WHERE (branch='xen-unstable')
>              AND ( (TRUE AND flight <= 151903) AND (blessing='real') )
>              AND r1.name LIKE 'built_revision_%'
>              AND r1.name = ?
>              AND r1.val= ?
> 
>            ORDER BY flight DESC
>            LIMIT 1000
>      )
>      SELECT *
>        FROM sub
>        JOIN jobs USING (flight)
> 
>       WHERE (1=1)
>                  AND jobs.job = ?
> 
>      ORDER BY blessing ASC, flight DESC

I was wondering if it would be useful converting this to a join would be 
useful. :-)

Again, not sure what the “(1=1) AND” bit is for; something to poke the query 
planner somehow?

The main thing I see here is that there’s nothing *in the query* that 
guarantees you won’t get multiple flights if there are multiple jobs for that 
flight whose ‘job’ value; but given the naming scheme so far, I’m guessing job 
is unique…?  As long as there’s something else preventing duplication I think 
it’s fine.

 -George


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.