Bug 1330756

Summary: scoped search queries use 'ilike' instead of 'like'
Product: Red Hat Satellite Reporter: Chris Duryee <cduryee>
Component: PerformanceAssignee: Zach Huntington-Meath <zhunting>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.2.0CC: bbuckingham, bkearney, cduryee, sshtein
Target Milestone: UnspecifiedKeywords: Performance, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-09-06 07:18:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Chris Duryee 2016-04-26 21:27:29 UTC
Description of problem:

Postgresql allows for 'ilike' which is case-insensitive like. However, 'ilike' cannot use indexes, resulting in slow queries.

There are a couple of ways to go about fixing this but one way would be to call lower() on both sides of the comparisons, which would let us use LIKE. There is some discussion in http://grokbase.com/t/postgresql/pgsql-hackers/12cwwmjgs9/ilike-vs-indices about the pros and cons of this (mostly related to locale concerns), but I think for the types of data Katello works with, I think a "lowercase everything when searching" approach is OK.

NOTE: this bz is for a SQL optimization to make searches faster, for example when searching for an erratum. Ideally, it should have no functionality impact.

Version-Release number of selected component (if applicable): 6.2.0 beta

Comment 1 Bryan Kearney 2016-04-27 19:21:37 UTC
Upstream bug assigned to zhunting

Comment 3 Shimon Shtein 2017-09-05 08:27:03 UTC
The ILIKE operator comes from scoped search (https://github.com/wvanbergen/scoped_search/blob/c874ab5de817a6d619baaa1d07129b5743a98708/lib/scoped_search/query_builder.rb#L536), so I doubt we want to customize this part easily. 
If there is a place where LIKE queries are very common, we can explore the option of text indices: https://blog.2ndquadrant.com/text-search-strategies-in-postgresql/.

Before we go there, IMHO we should prove negative impact on the user, since it adds more complexity to DB structure.

Comment 4 Chris Duryee 2017-09-05 13:44:22 UTC
Ya agreed, I think its OK to close this bug out. It was found when investigating another issue, but https://bugzilla.redhat.com/show_bug.cgi?id=1330306 already reduced the time by 1/2 without making any changes to scoped search.

Comment 5 Shimon Shtein 2017-09-06 07:18:18 UTC
Closing for now, as it seems like a premature optimization from the last comment.

Thanks, Chris!