В Core Data можно создать таблицу без индекса, а затем добавить индекс после завершения всех вставок?

Вопрос:

Я использую Core Data, поддерживаемый Sqllite в большом приложении данных. Моя текущая проблема заключается в том, что если я индексирую конкретный атрибут, скорость импорта со временем значительно снижается по мере увеличения числа вставок:

Скорость вставки SQLite замедляется по мере увеличения количества записей из-за индекса

Очевидно, что НЕ индексирование вызывает проблемы с представлением, поэтому это не вариант. Исходный код был опубликован здесь: встроенный объект ввода данных в цикле вызывает проблемы с свойством NSNumber * для объекта new во внутреннем цикле

В Core Data, возможно ли создать индекс по атрибуту ПОСЛЕ того, как я сделаю импорт?

Лучший ответ:

Для этого вам понадобится цикл компиляции. Или, возможно, две xcdatamodels внутри вашего пакета, которые идентичны, за исключением установки индекса xcdatamodels атрибута объекта.

Существует множество способов ускорить вставку в Core Data. Можем ли мы увидеть код вставки? Что говорит вам подробный вывод (-com.apple.CoreData.SQLDebug 1)?

Вот выдержка из журнала, отправленного в Dropbox:

CoreData: annotation: creating schema.
CoreData: sql: pragma page_size=4096
CoreData: sql: pragma auto_vacuum=2
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'
CoreData: sql: CREATE TABLE ZDATUM ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZSAMPLEID INTEGER, ZTAGID INTEGER, ZLOCUS INTEGER, ZSAMPLE INTEGER, ZDEPTHDATA VARCHAR, ZNAME VARCHAR, ZALLELEDATA BLOB, ZDATUMDATA BLOB, ZHAPLOTYPEDATA BLOB, ZMETADATA BLOB, ZSNPDATA BLOB, ZSTACKDATA BLOB )
CoreData: sql: CREATE INDEX ZDATUM_ZSAMPLEID_INDEX ON ZDATUM (ZSAMPLEID)
CoreData: sql: CREATE INDEX ZDATUM_ZLOCUS_INDEX ON ZDATUM (ZLOCUS)
CoreData: sql: CREATE INDEX ZDATUM_ZSAMPLE_INDEX ON ZDATUM (ZSAMPLE)
CoreData: sql: CREATE TABLE ZGENERICHASH ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZKEY VARCHAR, ZSTRINGVALUE VARCHAR, ZTYPE VARCHAR, ZDATAVALUE BLOB )
CoreData: sql: CREATE TABLE ZLOCUS ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZBASEPAIRS INTEGER, ZLENGTH INTEGER, ZLOCUSID INTEGER, ZPARENTCOUNT INTEGER, ZPROGENYCOUNT INTEGER, ZCHROMOSOME VARCHAR, ZCONSENSUS VARCHAR, ZMARKER VARCHAR, ZRATIO VARCHAR, ZSTRAND VARCHAR, ZTYPE VARCHAR, ZALLELEDATA BLOB, ZMETADATA BLOB, ZSNPDATA BLOB )
CoreData: sql: CREATE INDEX ZLOCUS_ZBASEPAIRS_INDEX ON ZLOCUS (ZBASEPAIRS)
CoreData: sql: CREATE INDEX ZLOCUS_ZLOCUSID_INDEX ON ZLOCUS (ZLOCUSID)
CoreData: sql: CREATE TABLE ZPOPULATION ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZPOPULATIONID INTEGER, ZNAME VARCHAR, ZMETADATA BLOB )
CoreData: sql: CREATE TABLE ZSAMPLE ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZSAMPLEID INTEGER, ZPOPULATION INTEGER, ZNAME VARCHAR, ZMETADATA BLOB )
CoreData: sql: CREATE INDEX ZSAMPLE_ZPOPULATION_INDEX ON ZSAMPLE (ZPOPULATION)
CoreData: sql: CREATE TABLE ZSTACKENTRYDATUM ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZSAMPLEID INTEGER, ZTAGID INTEGER, ZNAME VARCHAR, ZMETADATA BLOB, ZSTACKDATA BLOB )
CoreData: sql: CREATE INDEX ZSTACKENTRYDATUM_ZSAMPLEID_INDEX ON ZSTACKENTRYDATUM (ZSAMPLEID)
CoreData: sql: CREATE INDEX ZSTACKENTRYDATUM_ZTAGID_INDEX ON ZSTACKENTRYDATUM (ZTAGID)
CoreData: annotation: Creating primary key table.
CoreData: sql: CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER)
CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(1, 'Datum', 0, 0)
CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(2, 'GenericHash', 0, 0)
CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(3, 'Locus', 0, 0)
CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(4, 'Population', 0, 0)
CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(5, 'Sample', 0, 0)
CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(6, 'StackEntryDatum', 0, 0)
CoreData: sql: CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB)
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'
CoreData: sql: DELETE FROM Z_METADATA WHERE Z_VERSION = ?
CoreData: sql: INSERT INTO Z_METADATA (Z_VERSION, Z_UUID, Z_PLIST) VALUES (?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: pragma cache_size=500
CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZMETADATA, t0.ZNAME, t0.ZPOPULATIONID FROM ZPOPULATION t0
CoreData: annotation: sql connection fetch time: 0.0003s
CoreData: annotation: total fetch execution time: 0.0005s for 0 rows.
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: SELECT Z_MAX FROM Z_PRIMARYKEY WHERE Z_ENT = ?
CoreData: sql: UPDATE Z_PRIMARYKEY SET Z_MAX = ? WHERE Z_ENT = ? AND Z_MAX = ?
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZGENERICHASH(Z_PK, Z_ENT, Z_OPT, ZDATAVALUE, ZKEY, ZSTRINGVALUE, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZGENERICHASH(Z_PK, Z_ENT, Z_OPT, ZDATAVALUE, ZKEY, ZSTRINGVALUE, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZGENERICHASH(Z_PK, Z_ENT, Z_OPT, ZDATAVALUE, ZKEY, ZSTRINGVALUE, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZLOCUS(Z_PK, Z_ENT, Z_OPT, ZALLELEDATA, ZBASEPAIRS, ZCHROMOSOME, ZCONSENSUS, ZLENGTH, ZLOCUSID, ZMARKER, ZMETADATA, ZPARENTCOUNT, ZPROGENYCOUNT, ZRATIO, ZSNPDATA, ZSTRAND, ZTYPE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZPOPULATION(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZPOPULATIONID) VALUES(?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZPOPULATION(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZPOPULATIONID) VALUES(?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZPOPULATION(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZPOPULATIONID) VALUES(?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZSAMPLE(Z_PK, Z_ENT, Z_OPT, ZPOPULATION, ZMETADATA, ZNAME, ZSAMPLEID) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZSAMPLE(Z_PK, Z_ENT, Z_OPT, ZPOPULATION, ZMETADATA, ZNAME, ZSAMPLEID) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZSAMPLE(Z_PK, Z_ENT, Z_OPT, ZPOPULATION, ZMETADATA, ZNAME, ZSAMPLEID) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: pragma page_count
CoreData: annotation: sql execution time: 0.0003s
CoreData: sql: pragma freelist_count
CoreData: annotation: sql execution time: 0.0002s
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: INSERT INTO ZDATUM(Z_PK, Z_ENT, Z_OPT, ZLOCUS, ZSAMPLE, ZALLELEDATA, ZDATUMDATA, ZDEPTHDATA, ZHAPLOTYPEDATA, ZMETADATA, ZNAME, ZSAMPLEID, ZSNPDATA, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZALLELEDATA, t0.ZDATUMDATA, t0.ZDEPTHDATA, t0.ZHAPLOTYPEDATA, t0.ZMETADATA, t0.ZNAME, t0.ZSAMPLEID, t0.ZSNPDATA, t0.ZSTACKDATA, t0.ZTAGID, t0.ZLOCUS, t0.ZSAMPLE FROM ZDATUM t0
CoreData: annotation: sql connection fetch time: 0.0020s
CoreData: annotation: total fetch execution time: 0.0091s for 1202 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZMETADATA, t0.ZNAME, t0.ZPOPULATIONID FROM ZPOPULATION t0 WHERE  t0.ZNAME = ?
CoreData: annotation: sql connection fetch time: 0.0003s
CoreData: annotation: total fetch execution time: 0.0005s for 1 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZMETADATA, t0.ZNAME, t0.ZPOPULATIONID FROM ZPOPULATION t0 WHERE  t0.ZNAME = ?
CoreData: annotation: sql connection fetch time: 0.0002s
CoreData: annotation: total fetch execution time: 0.0004s for 1 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZMETADATA, t0.ZNAME, t0.ZPOPULATIONID FROM ZPOPULATION t0 WHERE  t0.ZNAME = ?
CoreData: annotation: sql connection fetch time: 0.0002s
CoreData: annotation: total fetch execution time: 0.0004s for 1 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDATAVALUE, t0.ZKEY, t0.ZSTRINGVALUE, t0.ZTYPE FROM ZGENERICHASH t0 WHERE  t0.ZKEY = ?
CoreData: annotation: sql connection fetch time: 0.0003s
CoreData: annotation: total fetch execution time: 0.0005s for 1 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZMETADATA, t0.ZNAME, t0.ZSAMPLEID, t0.ZPOPULATION FROM ZSAMPLE t0 WHERE  t0.ZNAME = ?
CoreData: annotation: sql connection fetch time: 0.0002s
CoreData: annotation: total fetch execution time: 0.0004s for 1 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZALLELEDATA, t0.ZDATUMDATA, t0.ZDEPTHDATA, t0.ZHAPLOTYPEDATA, t0.ZMETADATA, t0.ZNAME, t0.ZSAMPLEID, t0.ZSNPDATA, t0.ZSTACKDATA, t0.ZTAGID, t0.ZLOCUS, t0.ZSAMPLE FROM ZDATUM t0 WHERE  t0.ZSAMPLEID = ?
CoreData: annotation: sql connection fetch time: 0.0010s
CoreData: annotation: total fetch execution time: 0.0045s for 421 rows.
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZDATUM SET ZSNPDATA = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?


CoreData: sql: UPDATE ZLOCUS SET ZPROGENYCOUNT = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZLOCUS SET ZPROGENYCOUNT = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: UPDATE ZLOCUS SET ZPROGENYCOUNT = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
CoreData: sql: COMMIT
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZMETADATA, t0.ZNAME, t0.ZSAMPLEID, t0.ZPOPULATION FROM ZSAMPLE t0 WHERE  t0.ZNAME = ?
CoreData: annotation: sql connection fetch time: 0.0003s
CoreData: annotation: total fetch execution time: 0.0005s for 1 rows.
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDATAVALUE, t0.ZKEY, t0.ZSTRINGVALUE, t0.ZTYPE FROM ZGENERICHASH t0 WHERE  t0.ZKEY = ?
CoreData: annotation: sql connection fetch time: 0.0002s
CoreData: annotation: total fetch execution time: 0.0005s for 1 rows.
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: pragma page_count
CoreData: annotation: sql execution time: 0.0003s
CoreData: sql: pragma freelist_count
CoreData: annotation: sql execution time: 0.0002s
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT



CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZSTACKENTRYDATUM(Z_PK, Z_ENT, Z_OPT, ZMETADATA, ZNAME, ZSAMPLEID, ZSTACKDATA, ZTAGID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: COMMIT

Ответ №1

Ответ оказался больше связан с SQLite, и я нашел его здесь:

http://sqlite.1065341.n5.nabble.com/Improving-Bulk-Insert-Speed-CC-td74827.html

Я уверен, что есть лучшие варианты, но настройка размера кеша, по крайней мере, для массового импорта значительно помогает.

NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];
[pragmaOptions setObject:@"EXCLUSIVE" forKey:@"locking_mode"];
[pragmaOptions setObject:@"OFF" forKey:@"synchronous"];
[pragmaOptions setObject:[NSNumber numberWithInt:400000] forKey:@"cache_size"];
[pragmaOptions setObject:@"MEMORY" forKey:@"temp_store"];
[pragmaOptions setObject:@"OFF" forKey:@"count_changes"];
[pragmaOptions setObject:@"NONE" forKey:@"auto_vacuum"];


NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption
,[NSNumber numberWithBool:YES],NSInferMappingModelAutomaticallyOption
,pragmaOptions,NSSQLitePragmasOption
, nil];

Оцените статью
TechArks.Ru
Добавить комментарий