1.將插入操作放到乙個transaction裡,預設的每條insert語句都會開啟乙個transaction,參見:
2.手動拼寫插入語句,不要運用orm,雖然**會看起來很多,但是效率絕對大幅度提公升
未優化前**:
nsarray *organizations = [organizationsdic allvalues];
for (organization *organization in organizations)
優化後**:
//手動拼接sql語句,不採用or模式,提公升點效能,有待進入內網測試
fmdatabase *db = [md_databasetool getdb];
nsstring *sql;
//儲存公司或部門
[db begintransaction];
nsarray *organizations = [organizationsdic allvalues];
for (organization *organization in organizations)
//儲存使用者-部門對映表
for (userorganizationmap *userorganizationmap in userorganizations)
[db commit];
Python使用SQLite插入大量資料耗時問題
使用python爬蟲 ip時,最先使用了sqlite作為儲存ip資料庫,sqlite簡單 靈活 輕量 開源,和檔案系統一樣。而當大量插入爬取的資料時,出現了嚴重的耗時,檢視一起資料後,發現 sqlite在每條insert都使用commit的時候,就相當於每次訪問時都要開啟一次檔案,從而引起了大量的i...
Python中大量插入資料到SQLITE
這是我的第乙個python和sqlte的文章,雖然短小,但相信對遇到的會很有用。當你需要向sqlite資料庫插入上百萬條資料時,你會怎麼做?for i in range 0 len s list db.execute insert into txt txt values i,這樣效率奇低,你會怎麼做...
mysql插入大量資料,時間的優化。
背景 業務場景假設,公司原有excel記錄了千萬級客戶的相關資料,公司業務結構實現了資訊化的布局,需要在新開發的crm系統中匯入千萬級的客戶資料。此時需要用到mysql的insert操作來插入使用者的海量資料。普通情況下,會使用for迴圈一條一條的插入資料。假設客戶的資料量為10萬條資料。conne...