Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过定义索引提高iOS上Sqlite DB的性能?_Ios_Sqlite - Fatal编程技术网

通过定义索引提高iOS上Sqlite DB的性能?

通过定义索引提高iOS上Sqlite DB的性能?,ios,sqlite,Ios,Sqlite,“我的表”表示具有以下列的层次结构: int ID (PK, unique, not null) int ParentID int MasterID (not null) smallint Type (not null) varchar(255) Name 我需要通过以下方式查询此数据库: 通过ID获取一个条目 获取项的所有子项(按ParentID查询并限制为一个特定MasterID) 获取特定类型项的所有子项 我最好在这个Sqlite DB上定义哪些索引? 同样值得注意的是:我需要插入

“我的表”表示具有以下列的层次结构:

int ID (PK, unique, not null)
int ParentID 
int MasterID (not null)
smallint Type (not null)
varchar(255) Name
我需要通过以下方式查询此数据库:

  • 通过ID获取一个条目
  • 获取项的所有子项(按ParentID查询并限制为一个特定MasterID)
  • 获取特定类型项的所有子项
我最好在这个Sqlite DB上定义哪些索引? 同样值得注意的是:我需要插入相当多的记录(删除属于特定MasterID的所有内容,然后插入大约20000行)。我认为定义许多索引会降低性能,对吗?目前,我一次插入500条记录,并将其包装为“开始”和“结束”


另外,我应该对DB应用哪些其他设置,特别是在iOS场景中?

您定义的索引将直接受您正在查找的键的影响。一般来说,关系中的任何内容(外键)都是索引的好位置。乍一看,我建议为int数据类型编制索引,因为这样比较便宜。但请记住,只有索引能够提高性能。在这种情况下,测试是一条出路

您可以添加索引,但结果表明它只会降低您的速度(索引会降低写入操作的速度,但不会降低读取速度)。最好在各种配置中进行测试。关于如何创建索引,还没有什么包罗万象的。如果您发布正在运行的查询,我们可能会提供更多的见解


最后,保持索引尽可能窄(即,除非你已经测试了一吨并发现这是最有效的,否则不要在多个列上创建它)

你定义的索引将直接受到你正在查找的键的影响。一般来说,关系中的任何内容(外键)都是索引的好位置。乍一看,我建议为int数据类型编制索引,因为这样比较便宜。但请记住,只有索引能够提高性能。在这种情况下,测试是一条出路

您可以添加索引,但结果表明它只会降低您的速度(索引会降低写入操作的速度,但不会降低读取速度)。最好在各种配置中进行测试。关于如何创建索引,还没有什么包罗万象的。如果您发布正在运行的查询,我们可能会提供更多的见解

最后,保持索引尽可能窄(即,不要在多个列上创建索引,除非您已经测试了一吨并发现这是最有效的)