Answering questions asked on the site.
Princess asks:
Hello, I’ve got a problem with SQL.
I have a table which contains the production details for the factories. They are not factories and items of course but I cannot disclose the project and need to obfuscate so let’s pretend they are :)
I need to select the items for which the first 5 factories have low production rate.
I tried to do the query like this:
SELECT ProductionItem FROM FactoryProductions WHERE 5 >= FactoryID AND 100 >= ProductionAmount
which returns correct results but is slow.
I have an index on (FactoryID, ProductionAmount)
.
There are 13 Factories and 2,300,000 Items
This is in MySQL
This is a nice illustration of how index range evaluation works …
[Read more]