My MS SQL database is executing a large amount of wildcard (select *) queries. I will include below some of the metrics I have captured. I believe this to be an unnecessary strain on my database and am looking to see if anyone else has observed this behavior and if there are any solutions available.
Regarding this queries I am having some issue finding any information to help me answer some of the following questions:
- Does Totara support MSSQL database record caching?
- Is any attempt being made to cache these particular queries?
Without really digging into the Totara code and cataloging the system behavior I can't tell what is making these database calls. Here are the top 3 offenders:
- SELECT * FROM [mdl_context] WHERE [contextlevel]=@1 AND [instanceid]=@2
- SELECT * FROM [mdl_course] WHERE [id]=@1
- SELECT * FROM [mdl_course_completions] WHERE [userid]=@1 AND [course]=@2
Judging by the other performance metrics I have observed I believe that these queries return a single row on average and the result remains unchanged provided the same parameters. The expected caching strategy would be to cache the query results per parameter and invalidate that cache item if the record was modified or if the table was altered. I can't seem to find that any database record caching exists in Totara for MSSQL.
I am hoping to get some guidance around this prior to upgrading to the latest version of Totara. We are relatively new Totara users and are trying to obtain performance benchmarks prior to upgrades. I know we are a couple major versions behind, but I feel it is more responsible to analyze the root cause of problems before attempting to resolve them (and potentially introducing new ones) by pushing monthly upgrades.
- Totara 11.14
- Build 20190429.00
- SQL Server 13.0.5622.0
- Compatibility level SQL Server 2012 (110)
- Totara active user count: 73727
- Average concurrent user count: 277
- Max concurrent user count: 1152
Cost | Query Text | # Executions | Executions / Minute | Total CPU (ms) | Avg CPU (ms) | Total Duration (ms) | Avg Duration (ms) | Total Reads |
0.00657 | SELECT * FROM [mdl_context] WHERE [contextlevel]=@1 AND [instanceid]=@2 | 5751496 | 1230 | 243055 | 0 | 451489 | 0 | 34507908 |
0.003283 | SELECT * FROM [mdl_course] WHERE [id]=@1 | 6059935 | 1296 | 215018 | 0 | 215845 | 0 | 12119878 |
0.00657 | SELECT * FROM [mdl_course_completions] WHERE [userid]=@1 AND [course]=@2 | 812192 | 1574 | 35277 | 0 | 206991 | 0 | 5637328 |