2013-02-01 36 views
0
  1. 我的查詢需要很長時間約1小時。因此,它影響了數據庫性能。 3.即使解釋計劃也需要很長時間。 4.我的查詢很大。

查詢:即使爲解釋計劃掙扎也長時間運行的查詢也需要非常多的時間

​​

表結構:

mysql> show create table t_keyword_paid_analytics_google_ib\G 
*************************** 1. row *************************** 
Table: t_keyword_paid_analytics_google_ib 
Create Table: CREATE TABLE `t_keyword_paid_analytics_google_ib` (
`keyword_name` varchar(255) DEFAULT NULL, 
`id` int(11) NOT NULL, 
`keyword_id` int(11) NOT NULL, 
`target_url_id` int(11) DEFAULT NULL, 
`own_domain_id` int(11) NOT NULL, 
`log_date` date NOT NULL, 
`traffic_date` date NOT NULL, 
`impressions` int(11) DEFAULT NULL, 
`clicks` int(11) DEFAULT NULL, 
`entrances` int(11) DEFAULT NULL, 
`match_type` int(11) DEFAULT NULL COMMENT '1: Phrase, 2: Exact, 3:Broad 4: etc', 
`ad_group_name` varchar(200) DEFAULT NULL, 
`ad_distribution_network` varchar(500) CHARACTER SET latin1 DEFAULT NULL, 
`match_query` varchar(500) CHARACTER SET latin1 DEFAULT NULL, 
`cost` decimal(10,2) DEFAULT NULL, 
`cpm` decimal(10,2) DEFAULT NULL, 
`ctr` decimal(10,2) DEFAULT NULL COMMENT 'percent', 
`cpc` decimal(10,2) DEFAULT NULL, 
`campaign` varchar(200) CHARACTER SET latin1 DEFAULT NULL, 
`keyword_status` tinyint(4) DEFAULT NULL COMMENT '1: Active,2: Approved, 3: Disapproved, 4: Paused , 5:Pending, 6: Failed, 7:etc', 
`ad_group_status` tinyint(4) DEFAULT NULL COMMENT '1:ELIGIBLE; 2=PAUSED;3=LOW_SEARCH_VOLUME;4 =LOW_QUALITY_SCORE; 5=DISAPPROVED; 6=AD_GROUP_PAUSED; 7=etc', 
`max_cpc` decimal(10,2) DEFAULT NULL, 
`quality_score` tinyint(4) DEFAULT NULL, 
`channel` varchar(100) DEFAULT NULL, 
`first_page_cpc` decimal(10,2) DEFAULT NULL, 
`avg_position` decimal(10,2) DEFAULT NULL, 
`itemRevenue` decimal(10,2) DEFAULT NULL, 
`goal1value` decimal(10,2) DEFAULT NULL, 
`goal2value` decimal(10,2) DEFAULT NULL, 
`goal3value` decimal(10,2) DEFAULT NULL, 
`goal4value` decimal(10,2) DEFAULT NULL, 
`transactions` int(10) DEFAULT NULL, 
`goal1completions` int(10) DEFAULT NULL, 
`goal2completions` int(10) DEFAULT NULL, 
`goal3completions` int(10) DEFAULT NULL, 
`goal4completions` int(10) DEFAULT NULL 
) ENGINE=BRIGHTHOUSE DEFAULT CHARSET=utf8 
1 row in set (0.00 sec) 

mysql> show create table t_keyword_conversion_ga_ib\G 
*************************** 1. row *************************** 
Table: t_keyword_conversion_ga_ib 
Create Table: CREATE TABLE `t_keyword_conversion_ga_ib` (
`keyword_name` varchar(255) COLLATE latin1_bin DEFAULT NULL, 
`id` int(11) NOT NULL, 
`own_domain_id` int(11) DEFAULT NULL, 
`keyword_id` int(11) DEFAULT NULL, 
`traffic_date` date DEFAULT NULL, 
`targeturl_id` int(11) DEFAULT NULL, 
`entrance` int(11) DEFAULT NULL, 
`transactions` int(11) DEFAULT NULL, 
`item_revenue` decimal(9,2) DEFAULT NULL, 
`goal1completions` int(11) DEFAULT NULL, 
`goal2completions` int(11) DEFAULT NULL, 
`goal3completions` int(11) DEFAULT NULL, 
`goal4completions` int(11) DEFAULT NULL, 
`goal5completions` int(11) DEFAULT NULL, 
`goal6completions` int(11) DEFAULT NULL, 
`goal7completions` int(11) DEFAULT NULL, 
`goal8completions` int(11) DEFAULT NULL, 
`goal9completions` int(11) DEFAULT NULL, 
`goal10completions` int(11) DEFAULT NULL, 
`goal1Value` decimal(9,2) DEFAULT NULL, 
`goal2Value` decimal(9,2) DEFAULT NULL, 
`goal3Value` decimal(9,2) DEFAULT NULL, 
`goal4Value` decimal(9,2) DEFAULT NULL, 
`goal5Value` decimal(9,2) DEFAULT NULL, 
`goal6Value` decimal(9,2) DEFAULT NULL, 
`goal7Value` decimal(9,2) DEFAULT NULL, 
`goal8Value` decimal(9,2) DEFAULT NULL, 
`goal9Value` decimal(9,2) DEFAULT NULL, 
`goal10Value` decimal(9,2) DEFAULT NULL, 
`medium` varchar(255) COLLATE latin1_bin DEFAULT NULL, 
`source` varchar(255) COLLATE latin1_bin DEFAULT NULL 
) ENGINE=BRIGHTHOUSE DEFAULT CHARSET=latin1 COLLATE=latin1_bin 
1 row in set (0.00 sec) 

請幫我在這裏。

+1

乍一看,您似乎在該SQL中有很多冗餘計算。您的第一個子查詢似乎有9個SUMED值,它們在主選擇中不使用也不輸出。 您似乎也沒有在Brighthouse存儲引擎上檢查表 – Kickstart

+0

位上的索引,它看起來像索引支持很少。因此,我不希望使用此引擎的複雜查詢很快。 – Kickstart

回答

2

創建索引並更改條件。在outer_t.own_domain_id = 720(paid.channel is null or paid.channel = 'Google')之後放(outer_t.medium = 'organic' or outer_t.medium is null)paid.own_domain_id = 720。試試吧,我希望它能讓你的查詢更快。

+0

請寄給我重寫的查詢。 –