0
我有以下查詢。當我通過查詢底部的陳述刪除訂單時,它會在幾秒鐘內運行。SQL順序通過造成大的運行時間
當我按順序添加命令可能需要幾分鐘。
這個查詢有什麼明顯的錯誤會讓它變慢嗎?
SELECT TOP (10) addedBy, contactName, title_name, title_short_description, private, Art_medium, Artist_collection, Art_permanent_collection, dateEntered, dateModified,
title_translated_description, weblink, type, start_date, end_Date, Subcategory, title_art_description, id, title_name_translated, translated_short_description, pickDate,
pickOfTheMonth, event_periods, other_categories, rating, cnt, Artists_represented, city, country, county, district, latitude, longitude, openingTimes, Short_description,
sub_categories, venue_address1, venue_address2, venue_Name, venue_translated_name, title_id, venue_id, isLive, venueLive, tags, invite_only, featured_venue,
translated_description, venue_addedBy
FROM tblTitle_popular AS title
WHERE (id NOT IN (SELECT TOP (91) id
FROM tblTitle_popular AS title
WHERE (0 = 0)
AND (start_date >= '27-Jan-2012')
AND (start_date <= '31-Dec-2999')
AND (isLive = 1)
AND (venueLive = 1)
AND (private <> 1 OR private IS NULL)
ORDER BY pickOfTheMonth DESC, pickDate DESC, featured_venue DESC, start_date, city))
AND (0 = 0)
AND title.start_date >= '27-Jan-2012'
AND (title.start_date <= '31-Dec-2999')
AND (title.isLive = 1)
AND (title.venueLive = 1)
AND
(title.private <> 1 OR title.private IS NULL)
/*
ORDER BY title.pickOfTheMonth DESC, title.pickDate DESC, title.featured_venue DESC, title.start_date, title.city
*/
可能有些缺失的索引。 – 2012-02-17 16:07:01
'id不在(SELECT ... >>> ORDER BY ... <<<)'是不必要的,但它可能被忽略。 – biziclop 2012-02-17 16:09:44
你可以嘗試使用'ROW_NUMBER'來做這個分頁。 @biziclop - 這是SQL Server或sybase,'ORDER BY'是指定'TOP'的地方。 '@ James' - 請指定RDBMS和版本幷包含執行計劃。 – 2012-02-17 16:10:10