Re: Optimizing ORDER BY any ideas?
I rerun this query without the ORDER BY now a dozens of time and it never gives me the Using Index anymore at 5.row also the results are different from the results i just run a few minutes ago.
again the results are similar but it seems mysql for some reason???? has done the same query differnt now and now the first ROW doesn't have the Index in case of the ORDER BY.... don't understand why it is different.... then just a minute ago... but at least the results are similar between the 2 queries...
and in Both results (the one NOW here and the one in previous mail) there is seems to be taken the index in case you don't use ORDER BY)
So here what I have now:
mysql> EXPLAIN select
-> DISTINCT SAO_INDEX
-> from
-> T_SALES_ORDER_ITEM,
-> T_PROGRAM_PRODUCT,
-> T_PROPERTY,
-> T_SCHEDULE_ITEM,
-> T_SALES_ORDER
-> where
-> SOI_LNK_PRODUCT NOT IN (7,8,9)
-> and PMP_LNK_CHANNEL = 1
-> and PMP_LNK_PROGRAM = 1
-> and SOI_LNK_PRODUCT = PMP_LNK_PRODUCT
-> and SOI_LNK_SALES_ORDER = SAO_INDEX
-> and PRY_LNK_SALES_ORDER_ITEM = SOI_INDEX
-> and SCI_LNK_SALES_ORDER_ITEM = SOI_INDEX
-> and SCI_LNK_MEDIUM IN (1,2)
-> and SCI_LNK_CHANNEL = 1
-> and ( ((SCI_START_DATE <= '2004-09-08') and ( SCI_FINISHED_DATE >= '2004-09-08' ))
-> OR ((SCI_START_DATE >= '2004-09-08') and (SCI_FINISHED_DATE <= '2005-09-06'))
-> OR (SCI_START_DATE between '2004-09-08' and '2005-09-06')) \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: T_PROPERTY
type: index
possible_keys: PRY_LNK_SALES_ORDER_ITEM
key: PRY_LNK_SALES_ORDER_ITEM
key_len: 4
ref: NULL
rows: 5210
Extra: Using index; Using temporary
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: T_SCHEDULE_ITEM
type: ref
possible_keys: SCI_FINISHED_DATE,SCI_START_DATE,SCI_LNK_CHANNEL,SCI_LNK_SALES_ORDER_ITEM,SCI_LNK_MEDIUM
key: SCI_LNK_SALES_ORDER_ITEM
key_len: 4
ref: tvplanner4.T_PROPERTY.PRY_LNK_SALES_ORDER_ITEM
rows: 4
Extra: Using where
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: T_SALES_ORDER_ITEM
type: eq_ref
possible_keys: SOI_INDEX,SOI_LNK_SALES_ORDER,SOI_LNK_PRODUCT
key: SOI_INDEX
key_len: 4
ref: tvplanner4.T_SCHEDULE_ITEM.SCI_LNK_SALES_ORDER_ITEM
rows: 1
Extra: Using where
*************************** 4. row ***************************
id: 1
select_type: SIMPLE
table: T_SALES_ORDER
type: eq_ref
possible_keys: SAO_INDEX
key: SAO_INDEX
key_len: 4
ref: tvplanner4.T_SALES_ORDER_ITEM.SOI_LNK_SALES_ORDER
rows: 1
Extra: Using index
*************************** 5. row ***************************
id: 1
select_type: SIMPLE
table: T_PROGRAM_PRODUCT
type: ref
possible_keys: PMP_LNK_PROGRAM,PMP_LNK_CHANNEL,PMP_LNK_PRODUCT
key: PMP_LNK_PRODUCT
key_len: 4
ref: tvplanner4.T_SALES_ORDER_ITEM.SOI_LNK_PRODUCT
rows: 2
Extra: Using where; Distinct
Running with ORDER BY it gives:
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: T_PROPERTY
type: ALL
possible_keys: PRY_LNK_SALES_ORDER_ITEM
key: NULL
key_len: NULL
ref: NULL
rows: 5210
Extra: Using temporary; Using filesort
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: T_SCHEDULE_ITEM
type: ref
possible_keys: SCI_FINISHED_DATE,SCI_START_DATE,SCI_LNK_CHANNEL,SCI_LNK_SALES_ORDER_ITEM,SCI_LNK_MEDIUM
key: SCI_LNK_SALES_ORDER_ITEM
key_len: 4
ref: tvplanner4.T_PROPERTY.PRY_LNK_SALES_ORDER_ITEM
rows: 4
Extra: Using where
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: T_SALES_ORDER_ITEM
type: eq_ref
possible_keys: SOI_INDEX,SOI_LNK_SALES_ORDER,SOI_LNK_PRODUCT
key: SOI_INDEX
key_len: 4
ref: tvplanner4.T_SCHEDULE_ITEM.SCI_LNK_SALES_ORDER_ITEM
rows: 1
Extra: Using where
*************************** 4. row ***************************
id: 1
select_type: SIMPLE
table: T_SALES_ORDER
type: eq_ref
possible_keys: SAO_INDEX
key: SAO_INDEX
key_len: 4
ref: tvplanner4.T_SALES_ORDER_ITEM.SOI_LNK_SALES_ORDER
rows: 1
Extra: Using index
*************************** 5. row ***************************
id: 1
select_type: SIMPLE
table: T_PROGRAM_PRODUCT
type: ref
possible_keys: PMP_LNK_PROGRAM,PMP_LNK_CHANNEL,PMP_LNK_PRODUCT
key: PMP_LNK_PRODUCT
key_len: 4
ref: tvplanner4.T_SALES_ORDER_ITEM.SOI_LNK_PRODUCT
rows: 2
Extra: Using where; Distinct
Subject
Views
Written By
Posted
5050
September 06, 2005 05:35PM
2810
September 06, 2005 06:39PM
2978
September 06, 2005 08:30PM
2744
September 06, 2005 09:18PM
2722
September 07, 2005 07:10AM
2694
September 07, 2005 06:28PM
2751
September 07, 2005 08:55PM
2576
September 08, 2005 08:28AM
2683
September 08, 2005 11:12PM
2681
September 09, 2005 10:00AM
Re: Optimizing ORDER BY any ideas?
2616
September 09, 2005 10:22AM
2625
September 09, 2005 10:03PM
2870
September 10, 2005 07:30AM
3255
September 10, 2005 09:22AM
2640
September 12, 2005 02:45PM
2573
September 12, 2005 04:41PM