4 ms·
eh, I only brought it up because SQL is a funny beast. You have to think like the optimizer in some cases. I recently found a report query that was taking >90 s
by noduerme 5y ago
eh, I only brought it up because SQL is a funny beast. You have to think like the optimizer in some cases. I recently found a report query that was taking >90 seconds to execute. It was looking at something like 2 billion records, but it shouldn't have taken that long. It really tangled my mind. Each of the records had a `start` and `end` timestamp, and were being collated in a join on a separate key and sorted by MAX(`end`). So there's a joint key on the table that is start+end, but not a separate key for each. I figured out the query could be speeded up by about 80% if I added a parameter for `start`, a meaningless WHERE `start`>0 even though I didn't need one. Basically any start would be OK, I just had to have it there because even forcing key on the start/end index didn't kick the optimizer into realizing it needed to search that as a hash space. I don't know. It was a feeling. This is just in the vein of someone asking, "what is jujitsu to you?" But no, don't learn it if you don't need it.
- warrenm 5y agoreminds me of helping a friend at work years ago (the halcyon MySQL 3.23 days) they had a query that ran every 5 minutes, but on non-trivial data sets (network monitoring data for more than ~200 devices on a network), the query would take more than 5 minutes to run ... throwing hardware at the problem didn't help noticeably (double the CPU speed? run time would drop by ~5%) converting their query from OR form to IN() cut runtime by 90% All because of how the SQL engine thought it should run comparisons (MySQL, at the time, at least, used the IN() as functionally equivalent to a jump table, whereas the OR format was treated as a series of it...then...elseif...else statements)