#2074 Limit final query by prechecking buildroot ids
Merged 3 months ago by tkopecek. Opened 3 months ago by tkopecek.
tkopecek/koji issue1562  into  master

file modified
+32 -1

@@ -5323,15 +5323,46 @@ 

              clauses.append('standard_buildroot.state IN %(state)s')

          else:

              clauses.append('standard_buildroot.state = %(state)i')

+ 

+     # following filters can dramatically limit overall query size

+     # run separate queries for picking smallest candidate set

+     candidate_buildroot_ids = set()

      if rpmID is not None:

          joins.insert(0, 'buildroot_listing ON buildroot.id = buildroot_listing.buildroot_id')

          fields.append(('buildroot_listing.is_update', 'is_update'))

          clauses.append('buildroot_listing.rpm_id = %(rpmID)i')

+         query = QueryProcessor(columns=['buildroot_id'], tables=['buildroot_listing'],

+                                clauses=['rpm_id = %(rpmID)i'], opts={'asList': True},

+                                values=locals())

+         result = set(query.execute())

+         candidate_buildroot_ids = result

+ 

      if archiveID is not None:

-         joins.append('buildroot_archives ON buildroot.id = buildroot_archives.buildroot_id')

+         joins.insert(0, 'buildroot_archives ON buildroot.id = buildroot_archives.buildroot_id')

          clauses.append('buildroot_archives.archive_id = %(archiveID)i')

+         query = QueryProcessor(columns=['buildroot_id'], tables=['buildroot_archives'],

+                                clauses=['archive_id = %(archiveID)i'], opts={'asList': True},

+                                values=locals())

+         result = set(query.execute())

+         if candidate_buildroot_ids:

+             candidate_buildroot_ids &= result

+         else:

+             candidate_buildroot_ids = result

+ 

      if taskID is not None:

          clauses.append('standard_buildroot.task_id = %(taskID)i')

+         query = QueryProcessor(columns=['buildroot_id'], tables=['standard_buildroot'],

+                                clauses=['task_id = %(taskID)i'], opts={'asList': True},

+                                values=locals())

+         result = set(query.execute())

+         if candidate_buildroot_ids:

+             candidate_buildroot_ids &= result

+         else:

+             candidate_buildroot_ids = result

+ 

+     if candidate_buildroot_ids:

+         candidate_buildroot_ids = list(candidate_buildroot_ids)

+         clauses.append('buildroot.id IN %(candidate_buildroot_ids)s')

  

      query = QueryProcessor(columns=[f[0] for f in fields], aliases=[f[1] for f in fields],

                             tables=tables, joins=joins, clauses=clauses, values=locals(),

1 new commit added

  • move inner join before outer joins
3 months ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

3 months ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

3 months ago

this might never happen

:thumbsup: for the logic
maybe

candidate_buildroot_ids = candidate_buildroot_ids.intersection(set(result))

can be

candidate_buildroot_ids &= set(result)

to always use operators of set?

rebased onto d79d45d

3 months ago

updated - there was more garbage :-)

Commit fe8f19e fixes this pull-request

Pull-Request has been merged by tkopecek

3 months ago