Skip to content

FOUR-17365 39399 - Fidelity Bank Performance, queries constantly running #7327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

gproly
Copy link
Contributor

@gproly gproly commented Sep 5, 2024

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 to
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
, 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

@boliviacoca boliviacoca added 4.11.4 and removed 4.11.3 labels Sep 19, 2024
@ryancooley ryancooley added this to the v4.11.5 milestone Oct 2, 2024
@ryancooley ryancooley removed the 4.11.4 label Oct 2, 2024
@ryancooley ryancooley merged commit 71ea923 into next Oct 2, 2024
18 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants