FOUR-17365 39399 - Fidelity Bank Performance, queries constantly running #7327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue & Reproduction Steps
On the our analysis we found 3 queries that are constantly running in the database
For the first 2, we searched the process and also other assets int he database and there is no place in the scripts, screens and saved searches where the criteria for the queries was explicitly set from the UI, so I assume it is internal, however, on a quick review I can tell that tue queries are poorly written:
SELECT * FROM collection_x WHERE ( LOWER ( DATA ) LIKE ? OR id LIKE ? OR created_at LIKE ? OR updated_at LIKE ? ) ORDER BY id ASC LIMIT ? OFFSET ?
SELECT COUNT ( * ) AS AGGREGATE FROM collection_x WHERE ( LOWER ( DATA ) LIKE ? OR id LIKE ? OR created_at LIKE ? OR updated_at LIKE ? )
For this 3rd query, we notices this runs for every customer, but it case of Fidelity it shows high peaks in coudwatch
select table_name as name, (data_length + index_length) as size, table_comment as comment, engine as engine, table_collation as collation from information_schema.tables where table_schema = 'test' and table_type = 'BASE TABLE' order by table_name
Solution
This line of code
Schema::hasTable('scheduled_tasks')
makes a query toselect table_name as name, (data_length + index_length) as size, table_comment as comment, engine as engine, table_collation as collation from information_schema.tables where table_schema = 'test' and table_type = 'BASE TABLE' order by table_name
, so it should be avoided whenever possible.
With this solution, we are going to reduce the use of the following query (please verify this in the monitor)
These two queries are used to perform searches based on a filter string.
SELECT * FROM collection_x WHERE ( LOWER ( DATA ) LIKE ? OR id LIKE ? OR created_at LIKE ? OR updated_at LIKE ? ) ORDER BY id ASC LIMIT ? OFFSET ?
SELECT COUNT ( * ) AS AGGREGATE FROM collection_x WHERE ( LOWER ( DATA ) LIKE ? OR id LIKE ? OR created_at LIKE ? OR updated_at LIKE ? )
The DATA field is a JSON string, so
LIKE
is used to filter records that match the filter string and then retrieve the total results to display them in a paginated format for the client. This table is frequently used by the client, which is why high spikes are observed.The best solution to optimize the queries on this table would be to avoid using JSON to store the information, but this would involve significant changes (For now, we are not doing anything).
How to Test
Check in the query execution monitor to ensure that this execution has been reduced.
Related Tickets & Packages