Start with one slow category and a reproducible combination of filters. Measure total server time and time spent in SQL. A PHP profiler or staging query trace can show whether one statement dominates or whether the page repeats many small statements. Grab the real statement shape using representative non-sensitive values before considering a schema change.
Practical check. Record the SQL shape, filter values, query count and response time before each trial. Change one factor and rerun the same workload.
Find the expensive part of the request
Read type, key, rows and Extra for each step in EXPLAIN. The optimizer estimates the number of rows it needs to examine. An ALL access type for a small lookup table can be appropriate. A full scan over a large relationship table is worth investigating in the context of the join order and selected predicates.
| Check | What it shows | Where to verify |
|---|---|---|
type | Access method | Check expensive scans in large tables |
key | Index selected | Compare its leading columns with the predicates |
rows | Optimizer row estimate | Compare with measured results on staging |
Extra | Additional processing | Examine sorting and temporary work in context |
Compare plans before and after one change
Composite indexes should fit the filters, joins and sorting used by actual requests. Compare the candidate with existing indexes and verify that the joined columns have compatible types. A new index can help the storefront and slow down writes or imports, so measure both. Benchmark with comparable values, stable sorting and a consistent cache state.
MariaDB's ANALYZE SELECT runs the query and returns actual execution statistics. Use it for a heavy query on a representative test copy. For an N+1 pattern, count queries per page and evaluate grouping the repeated lookup into a batch. Query count and end-to-end latency will show an improvement that an individual EXPLAIN plan may miss.
Frequently asked questions
Is Using filesort automatically a problem?
It marks an extra sort. Check the number of rows and measured cost before changing the index.
Can EXPLAIN uncover N+1 by itself?
Use a per-request query trace to find repeated statements with different IDs. EXPLAIN describes each statement separately.
What do I measure after adding an index?
Check catalogue latency, import throughput and storage costs against the same representative data set.







