SQLite Database gives warning automatic index on <table_name>(column) After upgrading Android L

£可爱£侵袭症+ 提交于 2019-12-17 22:17:53

问题


I have upgraded my Nexus 7 with Android 5.0 Lollipop, Before that my application going well with SQLite Database but now Whenever I execute any type of query, It gives me log cat error like:

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)

So Is it Error of Any Lollipop Mistakes? I think so because i dont have updated my code before and after upgrading this OS.


回答1:


Automatic indexing was introduced in sqlite 3.7.17. A version of sqlite with this feature was only included in Android L developer preview. This is why you get the message only on Lollipop but not earlier. Even if it is logged as an error, it's really just a message.

Basically, the automatic indexing comes into play when you're doing lookups on non-indexed columns. sqlite assumes there's so much data that generating a temporary index is cheaper than raw lookup.

Consider adding explicit, permanent indices for your lookup columns with CREATE INDEX. For example, after your CREATE TABLE:

CREATE INDEX indexname ON tablename(columnname);

where you can pick tablename(columnname) from the autoindex messages as produced by sqlite.

If you just want the old behavior back, you can disable auto-indexing with

PRAGMA automatic_index=off;



回答2:


This was the top post while i was looking into this problem. Although i have a C# project and it might not be relevant for the OP, i thought it might still be helpfull for someone.

For those that wonder why the message keeps appearing, although an index was created explicitly; maybe your query is using a different collation.

I had a table with a text column and a select query with a where statement specifying where name = @var1 COLLATE NOCASE. This triggered the warnings, as the index i had created was default collation.

Thus, rewriting either the index, or the create table statement, to specify nocase for that column, made the warning disappear.



来源:https://stackoverflow.com/questions/27373344/sqlite-database-gives-warning-automatic-index-on-table-namecolumn-after-upgr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!