1

To increase a big query's performance (~2 seconds), I cache the result in another table (~0.016 milliseconds), but the result is not always present, so I tried this:

SELECT 
  IFNULL(
    (Query_with_cached_values), 
    (Big_Slow_Query_with_live_values)
  ) AS My_cool_result

I tried it on workbench, and while it works, the duration for the cached query is about 1 second, like if it tries both at the same time and aborts the second query. What is the right way to do it, executing just the first, and only if necessary the second?

Fehu
  • 381
  • 1
  • 3
  • 18
  • 1
    Have you seen this [post](https://stackoverflow.com/questions/17199604/if-condition-perform-query-else-perform-other-query) maybe it helps you... I think is quite similar what you are doing, you can add a NULL case. – Alvaro Niño Feb 01 '18 at 13:33
  • It works! i don't like to test a query and then requery it to retrieve the data, but it works – Fehu Feb 01 '18 at 16:23

0 Answers0