Bug 1330306 - two queries are performed when searching for erratum that does not exist
Summary: two queries are performed when searching for erratum that does not exist
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Performance
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: Unspecified
Assignee: Adam Price
QA Contact:
URL: http://projects.theforeman.org/issues...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-04-25 20:38 UTC by Adam Price
Modified: 2019-09-26 18:41 UTC (History)
4 users (show)

Fixed In Version: rubygem-katello-3.0.0.34-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-07-27 11:31:37 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 14268 0 None None None 2016-04-25 21:03:04 UTC

Internal Links: 1273256

Description Adam Price 2016-04-25 20:38:35 UTC
If you search for something that does not exist (for example, searching for erratum 'asdfasdf' without field specified), two search queries are performed. The first query is to get a count for pagination, but even if the count is zero, the second query is still performed. In some cases, these queries can take 3+ seconds, so running it once instead of twice can make the page much snappier.

To repro, sync some RH repos and then do the following:

<pre>
time curl -sk 'https://admin:changeme@localhost/katello/api/v2/errata?organization_id=3&search=sadfasdf' > /dev/null
</pre>

If you enable slow query logging in postgres (log_min_duration_statement = 500 will do it), you'll see two queries:

<pre>
LOG:  duration: 3125.694 ms  execute <unnamed>: SELECT COUNT(DISTINCT "katello_errata"."id") FROM "katello_errata" LEFT OUTER JOIN "katello_erratum_cves" ON "katello_erratum_cves"."erratum_id" = "katello_errata"."id" LEFT OUTER JOIN "katello_erratum_bugzillas" ON "katello_erratum_bugzillas"."erratum_id" = "katello_errata"."id" LEFT OUTER JOIN "katello_erratum_packages" ON "katello_erratum_packages"."erratum_id" = "katello_errata"."id" WHERE (("katello_errata"."errata_id" ILIKE '%sadfasdf%' OR "katello_errata"."severity" ILIKE '%sadfasdf%' OR "katello_errata"."errata_type" ILIKE '%sadfasdf%' OR "katello_erratum_cves"."cve_id" ILIKE '%sadfasdf%' OR "katello_erratum_bugzillas"."bug_id" ILIKE '%sadfasdf%' OR "katello_erratum_packages"."nvrea" ILIKE '%sadfasdf%' OR "katello_erratum_packages"."name" ILIKE '%sadfasdf%')) AND "katello_errata"."id" IN (SELECT DISTINCT "katello_errata"."id" FROM "katello_errata" INNER JOIN "katello_repository_errata" ON "katello_repository_errata"."erratum_id" = "katello_errata"."id" WHERE "katello_repository_errata"."repository_id" IN (SELECT "katello_repositories"."id" FROM "katello_repositories"  WHERE (katello_repositories.id ....

LOG:  duration: 3129.778 ms  execute <unnamed>: SELECT  DISTINCT "katello_errata"."id", katello_errata.updated AS alias_0, katello_errata.id AS alias_1 FROM "katello_errata" LEFT OUTER JOIN "katello_erratum_cves" ON "katello_erratum_cves"."erratum_id" = "katello_errata"."id" LEFT OUTER JOIN "katello_erratum_bugzillas" ON "katello_erratum_bugzillas"."erratum_id" = "katello_errata"."id" LEFT OUTER JOIN "katello_erratum_packages" ON "katello_erratum_packages"."erratum_id" = "katello_errata"."id" WHERE (("katello_errata"."errata_id" ILIKE '%sadfasdf%' OR "katello_errata"."severity" ILIKE '%sadfasdf%' OR "katello_errata"."errata_type" ILIKE '%sadfasdf%' OR "katello_erratum_cves"."cve_id" ILIKE '%sadfasdf%' OR "katello_erratum_bugzillas"."bug_id" ILIKE '%sadfasdf%' OR "katello_erratum_packages"."nvrea" ILIKE '%sadfasdf%' OR "katello_erratum_packages"."name" ILIKE '%sadfasdf%')) AND "katello_errata"."id" IN (SELECT DISTINCT "katello_errata"."id" FROM "katello_errata" INNER JOIN "katello_repository_errata" ON "katello_repository_errata"."erratum_id" = "katello_errata"."id" WHERE "katello_repository_errata"."repository_id" IN (SELECT "katello_repositories"."id" FROM "katello_repositories"  WHERE (katello_repositories.id in  ...
</pre>

Comment 1 Adam Price 2016-04-25 20:38:36 UTC
Created from redmine issue http://projects.theforeman.org/issues/14268

Comment 2 Adam Price 2016-04-25 20:38:38 UTC
Upstream bug assigned to adprice

Comment 4 Bryan Kearney 2016-05-16 20:21:37 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/14268 has been closed

Comment 5 Ondřej Pražák 2016-05-27 13:43:23 UTC
When searching for non-existing errata, only the SELECT COUNT... query is performed. Verified with snap 13.1

Comment 6 Bryan Kearney 2016-07-27 11:31:37 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2016:1501


Note You need to log in before you can comment on or make changes to this bug.