OK-謝謝,以上建議。我看了一下Instruments Trace,但這並不是真的必要,因爲調試告訴我運行速度慢的確切查詢。
但我的問題的關注,爲什麼它是從iOS8上移動到iOS9將導致查詢優化器以不同的方式評估相同的查詢。它絕對如此。爲了完整性,我自己回答了這個問題,因爲我已經解決了這個問題。但是,只是因爲我不得不重新調整SQL以適應優化器現在正在做的任何事情。
有趣的是,使用中的相同SQLite庫並沒有改變。所以,我仍然不知道爲什麼遷移到iOS9會給我帶來這個問題。在下面,查詢。我不希望任何人理解它,只要說句法是可以理解的即可。但是,我改變查詢的方式是從一個嵌套選擇中取出一個SELECT(或替換)。
這幾乎就好像SQLite不喜歡iOS9下嵌套查詢的深度。當然這沒有意義。但這是我觀察到的。
NSString *view = @" CREATE VIEW IF NOT EXISTS OFF_VIEW_5_FIXED_AMT_OFF AS "
" SELECT OTV_OOL_OOH_SEQ_NO AS R_OOL_OOH_SEQ_NO, "
" OTV_OOL_SEQ_NO AS R_OOL_SEQ_NO, "
" OTV_OO_SEQ_NO AS R_OO_SEQ_NO, "
" AMOUNT_DUE AS R_OOL_TOTAL_SAVINGS, "
" TOTAL_PAYABLE_WITHOUT_OFFER AS R_OOL_TOTAL_PAYABLE_NO_OFFER, "
" CASE "
" WHEN (100.00/TOTAL_PAYABLE_WITHOUT_OFFER * AMOUNT_DUE) > 100.00 THEN "
" 100.00 "
" ELSE "
" (100.00/TOTAL_PAYABLE_WITHOUT_OFFER * AMOUNT_DUE) "
" END AS R_OOL_PICKED_PERC_OFF_ALL_ORD, "
" CASE "
" WHEN SUM(OFFER_PAYABLE_BY_LINE) < 0 THEN "
" 0.00 "
" ELSE "
" SUM(OFFER_PAYABLE_BY_LINE) "
" END AS R_OFFER_TOTAL_PAYABLE_BY_LINE "
" FROM (SELECT OTV_OOL_SEQ_NO, "
" OTV_OO_SEQ_NO, "
" OTV_OOL_OOH_SEQ_NO, "
" (CASE "
" WHEN OO_ORD_VAL_BASED_ON_PERC_YN = 'Y' THEN "
" TOTAL_PAYABLE_WITHOUT_OFFER - (TOTAL_PAYABLE_WITHOUT_OFFER/100.00 * ORDER_TOTAL_TRIGGER) "
" ELSE "
" CASE "
" WHEN OO_DISCOUNT_ENTIRE_ORDER_YN = 'Y' THEN "
" ORDER_TOTAL_TRIGGER " // -- * -1 -- When actioned, this needs to be taken off the order, perhaps defined as a negative amount.
" ELSE "
" TOTAL_PAYABLE_WITHOUT_OFFER - ORDER_TOTAL_TRIGGER "
" END "
" END) * (100.00/TOTAL_PAYABLE_WITHOUT_OFFER * OTV_OOL_UNIT_PRICE)/100.00 AS OFFER_PAYABLE_BY_LINE, "
" TOTAL_PAYABLE_WITHOUT_OFFER, "
" ORDER_TOTAL_TRIGGER AS AMOUNT_DUE "
" FROM (SELECT OTV_OOL_SEQ_NO, "
" OTV_OO_SEQ_NO, "
" OTV_OO_OFFER_ID, "
" OTV_OOL_OOH_SEQ_NO, "
" OTV_OOL_UNIT_PRICE, "
" TOTAL_PAYABLE_WITHOUT_OFFER, "
" OO_ORD_VAL_BASED_ON_PERC_YN, "
" OO_DISCOUNT_ENTIRE_ORDER_YN, "
" OTV_TRIG_VAL_ON_ENTIRE_ORD_YN, "
" TOTAL_SALES_VALUE_ALL_ORDER, "
" (SELECT OAOBOV_AMOUNT_OFF "
" FROM OFF_AMOUNT_OFF_BY_ORDER_VALUE "
" WHERE OAOBOV_OO_SEQ_NO = OTV_OO_SEQ_NO "
" AND OAOBOV_TRIGGER_VALUE = "
" (SELECT MAX(OAOBOV_TRIGGER_VALUE) "
" FROM OFF_AMOUNT_OFF_BY_ORDER_VALUE "
" WHERE OAOBOV_TRIGGER_VALUE <= CASE "
" WHEN OTV_TRIG_VAL_ON_ENTIRE_ORD_YN = 'Y' THEN "
" TOTAL_SALES_VALUE_ALL_ORDER "
" ELSE "
" TOTAL_PAYABLE_WITHOUT_OFFER "
" END "
" AND OAOBOV_OO_SEQ_NO = OTV_OO_SEQ_NO)) AS ORDER_TOTAL_TRIGGER "
" FROM (SELECT OTV_OOL_SEQ_NO, "
" OTV_OO_OFFER_ID, "
" OTV_OO_SEQ_NO, "
" OTV_OOL_OOH_SEQ_NO, "
" OTV_OOL_UNIT_PRICE, "
" OO_ORD_VAL_BASED_ON_PERC_YN, "
" OO_DISCOUNT_ENTIRE_ORDER_YN, "
" OTV_TRIG_VAL_ON_ENTIRE_ORD_YN, "
" (SELECT SUM(OTV_OOL_UNIT_PRICE) FROM OFF_TEMP_5) AS TOTAL_PAYABLE_WITHOUT_OFFER, "
" CASE "
" WHEN OTV_USE_ORD_VAL_AFTER_DISC_YN = 'Y' THEN "
/*
" (SELECT SUM(OOL_PICKED_PRICE) "
" FROM OFF_ORDER_LINES "
" WHERE OOL_OOH_SEQ_NO = OTV_OOL_OOH_SEQ_NO "
" AND OOL_SEQ_NO NOT IN "
" (SELECT OOL_OOL_SEQ_NO "
" FROM OFF_CHOICE_LOCKED_CORES, "
" OFF_ORDER_LINES "
" WHERE OCLC_OOH_SEQ_NO = OTV_OOL_OOH_SEQ_NO "
" AND OCLC_OOL_SEQ_NO = OOL_SEQ_NO "
" AND OOL_DISCOUNT_ENTIRE_ORDER_YN = 'N')) "
*/
" (SELECT OTAOV_AFTER_OFFER_ORDER_VALUE FROM OFF_TEMP_AFTER_OFFER_VALUE) "
" ELSE "
" (SELECT SUM(OOL_UNIT_PRICE * OOL_QTY) "
" FROM OFF_ORDER_LINES OOL "
" WHERE OOL_OOH_SEQ_NO = OTV_OOL_OOH_SEQ_NO "
" AND OOL.OOL_LINE_TYPE_ID = 'S') "
" END AS TOTAL_SALES_VALUE_ALL_ORDER "
" FROM OFF_TEMP_5)) "
" WHERE ORDER_TOTAL_TRIGGER IS NOT NULL) "
" GROUP BY OTV_OOL_OOH_SEQ_NO, "
" OTV_OOL_SEQ_NO, "
" AMOUNT_DUE, "
" TOTAL_PAYABLE_WITHOUT_OFFER, "
" OTV_OO_SEQ_NO ";
因此,/ *和* /之間的灰色部分是我拿出來的。
這...
(SELECT OTAOV_AFTER_OFFER_ORDER_VALUE FROM OFF_TEMP_AFTER_OFFER_VALUE)
...是我與取代它。在我運行視圖之前,我在上面的表中插入一行,一行,一列,然後從中選擇。所以實質上,我刪除了在引號中運行查詢的需要。
所以,我想所有這一切的結尾,對於遇到類似問題的任何人來說,我都在追查複雜性。但我仍然困惑於爲什麼它在iOS8,Xcode 6.x上完全正常。
也許它會幫助別人。
嘗試使用Xcode 6.4附帶的sqlite3.dylib。 – rmaddy
您可以發佈儀器跟蹤嗎? – quellish