mysql query optimization -
I have this database:
tab 1 --- 1: n ---> tab 2 (parent -> id) (max 1: 4) - complex part
tab 1 --- 1: n ---> tab3 (original-> id) - simple access
Tab 1
id
name
version
..
tab2
id = paternity = type < Br> value .. ..
tab3
id = parent / type
data
I want to select the complete information, but I need to use several variable conditions, Slia I need to come up with probably the best solution.
I use this query:
SELECT tab1.id, CONCAT (tab 1.name, '', tab 1. version) AS NV, ndvar. Price, tab3.data, ndvar.v1 [and column] to tab 1 inner join (select parent, type, groupconcat (type SEPARATOR '') + "AS V1, min (price) AS value [more column] Tab 2 from where show = 1 [more circumstance] Typing typing type IN (2,3) [1-3 parameters] by parents) Click on tab 1.id = ndvar. Tabs on panning content 1.id = Tab3.parent and tab3.type = 0 where name '% xyz%' [max Conditions] ORDER BY NV
I've tried so easy to understand me as I could.
My questions: 1) How to optimize this query as soon as possible 2) Do the columns use as indexes? For now, this is just the 'id' column.
In the 'Type' column in Tab 2 there are 0-3 values and for each ID there is only the line with that type, therefore the index is trash by, but I
Edit:
This is a query that is used during the on-line search. Line catalogs will only contain some inserts or updates during the month, but each day will be known about many searches. Tab 1 will have hundreds of records, tabs will be around Tab 2 * 4 records and tab 1 * 15 records around Tab 3. For most parameters, most tab-1 (1-15 parameters) and tab2-related search status are all the names except the name and version number (double), varchar (25) and variant - varchar (20) .
The query is going to be executed on mysql 5.0.70, DB Engine MyISAM
According to all the data I have, tab2.price is searched for the range and tab 2. Type is the most common and search tab 1 for other number ranges. Name or tab 1
BTW: Sorry for my poor grammar, English is not my home language :)
> EDIT2:
I I can interpret the entire "HAVING" concept incorrectly. In V1, I have to store the entire set from 2 rows of tabs for each parent of Tab 1, but I have to type them in tab 2. How to do this?
EDIT3:
This sort of aggregation really what I want, but I know its terrible solution, someone knows how to improve it?
Parents have their parents '% 0%' like 'V1'
Tab2.type and tab1.id, tab2.parent and tab3.parent are probably the most important rows to index, if they identify very specific rows
As far as the indices go, others can be helpful tab 2. Price, Tab 3 type.
As a rule, in the case of more rows the results have to be eliminated, and in return it requires an index.
"Wherever the name '% stuff%' is probably one of the worst circumstances to use in the world, (although one of the most common) traditional indexes do nothing. If this test By destroying many rows from the result (which means that it is testing multiple rows and passing some positions), then you should use a full-text index.
After internal selection Selectable may be a performance hog, as a result do not need to create a result set.
Comments
Post a Comment