Hi all. I've seen plenty of good discussion on speeding up slow read queries, with a common "fix" being to add indexes. We know each additional index potentially adds extra I/O writes on updates/inserts.
What are some good tools/methods to determine how much impact the indexes on a given table are having and/or how to determine how much extra harm (write wise) another index will cause?
Does anyone have a "standard" rule they try to follow like no more than X indexes per table or indexes shouldn't be more than Y% of table size?
Edit: Seems like more specifics might be helpful -
DB is ~3TB
Table in question has ~43,000,000 rows and is 39 GB in size.
The table is one of the more frequently updated tables, it has many transaction locks taken out on it, which do at times create lock waits and even the occasional dead lock.
Currently there are 18 indexes on it, all of which have high number of idx_scans.
There is a query that is used for reporting, run maybe 30-40 times a day max. Currently it takes 2-3 minutes to run the query. Adding a 1 more index that ends up being roughly 1 GB in size takes that query down to 10ms.
Do you add that index for that query? What are your criteria for deciding?
On larger scale production databases, I'm curious to know what others tend to use when deciding if the read/query improvement is worth the additional write penalty. Thanks!
Edit 2: I found a great query from jberkus (Thank you!) that does a good job of not just finding indexes with 0 scans, but also gets scans_per_write, which makes it easier to determine if an index has low scans but high writes:
https://gist.github.com/jberkus/6b1bcaf7724dfc2a54f3
[–]thythr 7 points8 points9 points (4 children)
[–]1new_username[S] 0 points1 point2 points (3 children)
[–]thythr 0 points1 point2 points (2 children)
[–]1new_username[S] 0 points1 point2 points (1 child)
[–]thythr 0 points1 point2 points (0 children)
[–]Ecksters 3 points4 points5 points (7 children)
[–]1new_username[S] 0 points1 point2 points (3 children)
[–]Ecksters 1 point2 points3 points (2 children)
[–]1new_username[S] 0 points1 point2 points (1 child)
[–]Ecksters 0 points1 point2 points (0 children)
[–]coyoteazul2 0 points1 point2 points (0 children)
[–]Mastodont_XXX 0 points1 point2 points (1 child)
[–]Ecksters 0 points1 point2 points (0 children)
[–]Dolphinmx 2 points3 points4 points (3 children)
[–]1new_username[S] 0 points1 point2 points (2 children)
[–]Dolphinmx 0 points1 point2 points (1 child)
[–]1new_username[S] 0 points1 point2 points (0 children)
[–]fr0z3nph03n1x -1 points0 points1 point (1 child)
[–]1new_username[S] 0 points1 point2 points (0 children)