mysql - Is there a way to improve this query with if in it? -


I use this query to select language strings from wired databases in many languages, the database looks like this: < / P>

  `string_id` BIGINT`_Language_ID 'start_dateplay' DATETIME` text` TEXT   

For example, you can see the data like this:

  `string_id` | `Language_id` | `Day-time` | `Text` 1 | 1 | 2014.04.22 14:43:00 | Hello world 1 | 2 | 2014.04.22 14:43:02 | Hello, Well   

So it is the same string in German and English, one in German was replaced after two seconds of English.

I suppress this ( sub ) query to get the famous string. If the requested language is not present, then it will automatically convert to any language. For example, if I need a string in span (= 3 id) then this query will fallback to English or German:

  SELECT z.`text` to `language_strings` form Z in one where IF (z.`language_id` = 3, 1, 0) DESC, z.`tatetime` DESC LIMIT 1   

display issue is here by `join_string_id` = z.`string_id` ORDER , That IF (..., 1, 0) extract too many opportunities because the result is calculated every time the query is executed.

I tried a lot to improve this query, all useful indexes are still created. MySQL is able to hit this query with internal cache, but without cache it takes some time to calculate. This is a display problem (like 1000) on getting many lines, because MySQL has to show 1000 subclasses.

Do you have an idea to improve this question? Adding new columns to archive accurate data will be an option for me.

  (choose 1 as Ord, z.`text` to `language_string` As Z. A.Joined_string_id` = z.`string_id` and z.`language_id` = 3 boundary 1) Union All (Order 2 as selection, from Z.`text` to FROM `language_string` Jade A. Jenode_string_id` = z.`String_ID` order by Z. DTime DESC limit1) Order   

was updated by order limit 1. Twinkle thanked for the note.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -