Skip to content

Database Optimizations - #3167

Merged
jekkos merged 4 commits into
masterfrom
database_optimizations
May 25, 2021
Merged

jekkos merged 4 commits into
masterfrom
database_optimizations

Conversation

@objecttothis

Copy link
Copy Markdown
Member
  • Add indexes to tables to improve query times.
  • Delete orphaned attribute values.
  • Resolve duplicate attribute values.
  • Deleted whitespace after migration which was causing Severity: Warning --> Cannot modify header information - headers already sent by...

This is the first of four PRs that I will break out of the big import_update branch, so that it's easier to test and merge. Those having issues with large product stocks should see immediate improvement in transactions.

- Add indexes to tables to improve query times.
- Delete orphaned attribute values.
- Resolve duplicate attribute values.
- Deleted whitespace after migration which was causing Severity: Warning --> Cannot modify header information - headers already sent by
@objecttothis objecttothis added this to the 3.4.0 milestone Apr 22, 2021
@objecttothis
objecttothis requested a review from jekkos April 22, 2021 09:37
@objecttothis objecttothis self-assigned this Apr 22, 2021
@objecttothis
objecttothis requested a review from daN4cat April 22, 2021 09:37
@objecttothis objecttothis linked an issue Apr 22, 2021 that may be closed by this pull request
7 tasks done
@objecttothis
objecttothis requested a review from odiea April 22, 2021 09:43
Comment thread application/models/Attribute.php Resolved

@jekkos jekkos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I think we're good if we resolve the last comments in here.

- Removed unnecessary indices on deleted column where there would not be many rows.
- Explicitly stated NULL in second parameter of WHERE to improve readability.
@objecttothis

Copy link
Copy Markdown
Member Author

Thanks I think we're good if we resolve the last comments in here.

OK, then just the composite indices to figure out. I've pushed a commit that fixes the other issues.

@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos I decided to just do the item model and here is what the better part of a day got me in terms of moving through each function that contained a select query and running MYSQL EXPLAIN against the query that gets generated (thanks for the tip on the $this->db->last_query() function).
image
Now, armed with this data, we need to decide which queries are worth creating a composite index for the whole thing (Item->Search() on the items table for example?) and which ones we can get away with just finding the common denominator and creating the composite index that will encompass most of those queries (The orange indexes are ones that appear more than once in that column... items (PRIMARY, deleted) or item_quantities (PRIMARY, item_id, location_id) for example). Thoughts?

@objecttothis

Copy link
Copy Markdown
Member Author

Also, if possible, since it takes so long to do, I'd like to limit this round of DB improvements to those affected by the Item and Attribute models. We can go back through and revamp the indexes on the other tables later if needed. I think an entire PR could be dedicated just to the Report model tables.

- Removed unnecessary indices on deleted column where there would not be many rows.
- Removed unnecessary parenthesis in Item Model.
- Added Composite indices based on MySQL EXPLAIN results.
@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos, @opensourcepos/org I removed the deleted indexes on a few of the tables and added a few composite indices (see below) based on the results of the explain. Can we move on this yet?

image

@jekkos

jekkos commented May 25, 2021

Copy link
Copy Markdown
Member

@objecttothis thanks for the good work here, I didn't have too much time to look in to it yet thoroughly,

Also, if possible, since it takes so long to do, I'd like to limit this round of DB improvements to those affected by the Item and Attribute models. We can go back through and revamp the indexes on the other tables later if needed. I think an entire PR could be dedicated just to the Report model tables.

The items / inventory table is enough for now. I think that is typically the table that has most of the data. Also running a report is not something that is used that often, it can be done afterwards as it might be acceptable to be a little bit slower.

@jekkos

jekkos commented May 25, 2021

Copy link
Copy Markdown
Member

Were you able to verify that the queries use the composite index ? I think it would already be a great improvement if an index is able to accelerate the commonly used Item->search() query.

@objecttothis

Copy link
Copy Markdown
Member Author

Were you able to verify that the queries use the composite index ? I think it would already be a great improvement if an index is able to accelerate the commonly used Item->search() query.

I'll confirm that they are using the indexes.

@jekkos
jekkos merged commit 3520362 into master May 25, 2021
@jekkos

jekkos commented May 25, 2021

Copy link
Copy Markdown
Member

Ok I have merged this change already. Minor nitpick maybe try to refer to an issue number in your commit message next time, it makes the git changelog better as you can find more info about a changeset under the github issue tracker.

@objecttothis
objecttothis deleted the database_optimizations branch February 11, 2022 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loading speed very slow with large DB - Part 1 - Items

2 participants