這篇文章主要介紹“使用JDBC Update時(shí)不能使用索引的原因是什么”,在日常操作中,相信很多人在使用JDBC Update時(shí)不能使用索引的原因是什么問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”使用JDBC Update時(shí)不能使用索引的原因是什么”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供洛陽網(wǎng)站建設(shè)、洛陽做網(wǎng)站、洛陽網(wǎng)站設(shè)計(jì)、洛陽網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、洛陽企業(yè)網(wǎng)站模板建站服務(wù),10余年洛陽做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
表DYN_DAYAHEAD_BID按時(shí)間data_time分區(qū),有5個(gè)分區(qū),建立了一個(gè)本地分區(qū)索引index ind_dyn_daybid_store,索引列是data_time, tag_phy, tag_app,version四個(gè)字段。
一直以來,覺得JDBC Update修改數(shù)據(jù)時(shí)特別慢(根據(jù)業(yè)務(wù)邏輯,往往是一次update 481條記錄)。今天trace了應(yīng)用程序的執(zhí)行計(jì)劃(應(yīng)用程序通過jdbc訪問數(shù)據(jù)庫,數(shù)據(jù)庫版本為oracle 9.2.0.1)。通過jdbc的執(zhí)行計(jì)劃(trace文件)如下:
select Data_Time,Tag_Phy,Tag_App,Value_0,Value_1,Value_2,Value_3,Value_4, Value_5,Value_6,Value_7,Value_8,Value_9,Version from DYN_DAYAHEAD_BID where Tag_Phy = :1 and version = :2 and Data_Time > :3 and Data_Time <= :4+1 and Tag_App in ('5TMS01DBS07','5TMS01DBS08','5TMS01DBS09', '5TMS01DBS10','5TMS01DBS11','5TMS01DBS12') call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 49 0.04 0.02 0 609 0 481 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 51 0.04 0.02 0 609 0 481 Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 62 Rows Row Source Operation ------- --------------------------------------------------- 481 PARTITION RANGE ITERATOR PARTITION: 1 KEY 481 TABLE ACCESS BY LOCAL INDEX ROWID DYN_DAYAHEAD_BID PARTITION: 1 KEY 481 INDEX RANGE SCAN IND_DYN_DAYBID_STORE PARTITION: 1 KEY (object id 30391) .... update DYN_DAYAHEAD_BID set Value_0 = :1 , Value_1 = :2 , Value_2 = :3 , Value_3 = :4 , Value_4 = :5 , Value_5 = :6 , Value_6 = :7 , Value_7 = :8 , Value_8 = :9 , Value_9 = :10 where Data_Time= :11 and Tag_Phy= :12 and Tag_App= :13 and Version= :14 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 481 0.02 0.03 0 0 0 0 Execute 481 12.85 13.23 346 277537 500 481 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 962 12.87 13.26 346 277537 500 481 Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 62 Rows Row Source Operation ------- --------------------------------------------------- 0 UPDATE 1 PARTITION RANGE ALL PARTITION: 1 5 1 TABLE ACCESS FULL DYN_DAYAHEAD_BID PARTITION: 1 5
顯然,查詢時(shí)是JDBC Update用到了索引,而修改時(shí)JDBC Update沒有使用索引,但我在sqlplus下執(zhí)行類似的語句,則明顯的使用了索引:
SQL> update DYN_DAYAHEAD_BID set value_0=111 where data_time=to_date('2006-04-14 0:15:00','yyyy-mm-dd hh34:mi:ss') and tag_phy='303101120211' and tag_app='5TMS01DBS07' and version=1 SQL> /
JDBC Update已更新 1 行。
Execution Plan ---------------------------------------------------------- 0 UPDATE STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=51) 1 0 UPDATE OF 'DYN_DAYAHEAD_BID' 2 1 INDEX (UNIQUE SCAN) OF 'IND_DYN_DAYBID_STORE' (UNIQUE) ( Cost=1 Card=1 Bytes=51)
然后,我對(duì)程序中的sql語句增加了hint,強(qiáng)制使用索引,然后程序的執(zhí)行計(jì)劃如下:
update /*+ INDEX(dyn_dayahead_bid ind_dyn_daybid_store) */ DYN_DAYAHEAD_BID set Value_0 = :1 , Value_1 = :2 , Value_2 = :3 , Value_3 = :4 , Value_4 = :5 , Value_5 = :6 , Value_6 = :7 , Value_7 = :8 , Value_8 = :9 , Value_9 = :10 where Data_Time= :11 and Tag_Phy= :12 and Tag_App= :13 and Version= :14 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 481 0.04 0.02 0 0 0 0 Execute 481 11.37 11.48 0 247234 502 481 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 962 11.41 11.50 0 247234 502 481 Misses in library cache during parse: 0 Optimizer goal: CHOOSE Parsing user id: 62 Rows Row Source Operation ------- --------------------------------------------------- 0 UPDATE 1 PARTITION RANGE ALL PARTITION: 1 5 1 INDEX FULL SCAN IND_DYN_DAYBID_STORE PARTITION: 1 5 (object id 30391)
現(xiàn)在看起來是JDBC Update使用了索引,但好像對(duì)索引進(jìn)行全表掃描,跟查詢和在sqlplus下使用范圍掃描不一樣。
到此,關(guān)于“使用JDBC Update時(shí)不能使用索引的原因是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!