query optimization - How to optimize an ORDER BY for a computed column on a MASSIVE MySQL table -
I have a very large (80+ million) D-normalized MySQL table, a simplified schema looks like this:
+ ----------- + ------------- + -------------- + --- ----------- + | ID | PARAM1 | PARAM2 | PARAM3 | + ----------- + ------------- + -------------- + -------- ------ + | 1 | .04 | .87 | .78 | + ----------- + ------------- + -------------- + -------- ------ + | 2 | .12 | .02 | .76 | + ----------- + ------------- + -------------- + -------- ------ + | 3 | 24.92 | .23 | + ----------- + ------------- + -------------- + -------- ------ + | 4 | .65 | .12 | .01 | + ----------- + ------------- + -------------- + -------- ------ + | 5 | .98. .45 | .65 | + ----------- + ------------- + -------------- + -------- ------ +
I am trying to see if there is a way to optimize a query in which I have the weight for each paragraph column (where the weight is between 0 and 1) And then the average them to come with a calculated value SCORE then I want to order from that computed skur column. For example, assuming the weight of PARAM1 is 5. The load of PARAM2 is .23 and the load of PARAM3 is 76. You will end up, like something else:
Selection ID, (PARAM1 * .5) + (PARAM2 *. 23) + (PARAM3 * .76)) / 3 SCOR order according to DESC limit 10 with some proper indexing, it is fast for basic questions, but I would like to speed up the above queries on a large table like this Can not understand the way Description:
- The value of each parameter is between 0 and 1
- Every weight applied to PARAMS is between 0 and 1
- Edit - A simplified version of this problem is as follows.
It runs on the appropriate time:
SELECT value1, value2 for some time WHERE id = 1 ORDER BY value2
does not run in fair value:
SELECT value1, (value2 * an_arbitrary_float) value3 for some time WHERE id = 1 ORDER BY value3 < / Code>
Using the example above, is there any solution which allows me to compute the ORDER with computing value before 3?
I have found 2 (one type of clear) things in which to give this query speed up to a satisfactory level Help:
-
Minimize the number of rows that need to be sorted using an index on the 'id' field and trim the number of records first Using sub-style, the file sort is not bad at the calculated column. IEC:
SELECT t.value1, (t.value2 * an_arbitrary_float) as ordered by SCORE FROM (SELECT * FROM SOME WHERE id = 1) SEC DEC
-
Try to accelerate those files in my.conf.
Comments
Post a Comment