0

如果我索引一个属性并且在查询中我不使用 orderBy 子句,是否会使用索引?

示例代码:

DBIndexDefinition* index = [[DBIndexDefinition alloc] init];
[index addIndexForProperty:@"prop1" propertyOrder:DBIndexSortOrderAscending | DBIndexSortOrderDescending | DBIndexSortOrderNoCase secondaryProperty:@"prop2" secondaryOrder:DBIndexSortOrderAscending | DBIndexSortOrderDescending | DBIndexSortOrderNoCase];

prop1 和 prop2 是 NSString 类型。

谢谢!

4

1 回答 1

0

如果我只能以上面的示例为例,您只能指定一个顺序,不幸的是它们不是按位运算符。

DBIndexDefinition* index = [[DBIndexDefinition alloc] init];
[index addIndexForProperty:@"prop1" propertyOrder:DBIndexSortOrderAscending secondaryProperty:@"prop2" secondaryOrder:DBIndexSortOrderAscending];

然后,如果您省略 orderby 子句,那么不幸的是,在执行查询时,您将受到 SQLite 利用索引的支配。DBAccess 中没有添加任何内容以允许您为结果指定索引。

您可以使用分析来查看查询使用了哪个索引,这将告诉您 SQLite 做了哪些优化。

于 2016-01-11T14:38:03.203 回答