【问题标题】:SQLite Database gives warning automatic index on <table_name>(column) After upgrading Android LSQLite 数据库在 <table_name>(column) 上给出警告自动索引升级 Android L 后
【发布时间】:2015-02-07 00:21:02
【问题描述】:

我已经用 Android 5.0 Lollipop 升级了我的 Nexus 7,在此之前我的应用程序在 SQLite 数据库 上运行良好,但现在每当我执行任何类型的查询时,它都会给我 log cat error 喜欢:

12-09 12:37:04.942: E/SQLiteLog(13041): (284) automatic index on area(server_id)
12-09 12:37:04.942: E/SQLiteLog(13041): (284) automatic index on account(area_id)
12-09 12:37:04.942: E/SQLiteLog(13041): (284) automatic index on staff_visit(account_id)
12-09 12:37:04.942: E/SQLiteLog(13041): (284) automatic index on ordertab(account_id)
12-09 12:37:04.960: E/SQLiteLog(13041): (284) automatic index on area(server_id)
12-09 12:37:04.960: E/SQLiteLog(13041): (284) automatic index on account(area_id)
12-09 12:37:04.960: E/SQLiteLog(13041): (284) automatic index on staff_visit(account_id)
12-09 12:37:04.960: E/SQLiteLog(13041): (284) automatic index on ordertab(account_id)
12-09 12:37:04.978: E/SQLiteLog(13041): (284) automatic index on area(server_id)
12-09 12:37:04.978: E/SQLiteLog(13041): (284) automatic index on account(area_id)
12-09 12:37:04.978: E/SQLiteLog(13041): (284) automatic index on staff_visit(account_id)
12-09 12:37:04.978: E/SQLiteLog(13041): (284) automatic index on ordertab(account_id)

所以这是任何棒棒糖错误的错误吗?我是这么认为的,因为我在升级这个操作系统之前和之后都没有更新我的代码。

【问题讨论】:

  • BTW 自动索引很好地提高了查询性能时间
  • 这很奇怪,因为我已经为搜索或连接列手动创建了索引,但仍在创建自动索引。

标签: android android-sqlite android-5.0-lollipop android-logcat


【解决方案1】:

Automatic indexing 在 sqlite 3.7.17 中引入。具有此功能的 sqlite 版本只有 included in Android L developer preview。这就是为什么您只在 Lollipop 上而不是更早地收到消息的原因。即使它被记录为错误,它实际上也只是一条消息。

基本上,当您对非索引列进行查找时,自动索引就会发挥作用。 sqlite 假设数据太多,生成临时索引比原始查找便宜。

考虑使用CREATE INDEX 为您的查找列添加明确的永久索引。例如,在您的CREATE TABLE 之后:

CREATE INDEX indexname ON tablename(columnname);

您可以从 sqlite 生成的自动索引消息中选择 tablename(columnname)

如果你只想恢复旧的行为,你可以禁用自动索引

PRAGMA automatic_index=off;

【讨论】:

  • 谢谢@laalto,如果我什么都不做,会有什么问题吗?
  • 那么这是更好的索引它们的方法。这有问题吗?
  • @MuhammadBabar 取决于例如关于数据量和读写比例。
  • 我不明白为什么我一直收到这些消息,尽管我已经在那个表列上创建了一个索引......
  • 我讨厌开发人员无法理解错误日志的含义...它弄脏了我的 logcat 输出!最多应该是信息日志或警告...
【解决方案2】:

这是我在研究这个问题时的头条帖子。虽然我有一个 C# 项目,它可能与 OP 无关,但我认为它可能对某人仍有帮助。

对于那些想知道为什么消息不断出现的人,尽管已明确创建了索引;也许您的查询使用了不同的排序规则。

我有一个带有文本列的表和一个带有指定 where name = @var1 COLLATE NOCASE 的 where 语句的选择查询。这触发了警告,因为我创建的索引是默认排序规则。

因此,重写索引或 create table 语句以指定该列的 nocase 会使警告消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-20
    • 2017-02-20
    • 1970-01-01
    • 2019-03-06
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多