Skip to content

Select queries are not instrumented correctly #3073

@stefanosiano

Description

@stefanosiano

Description

In Android select queries return a Cursor, and the query is actually executed when the Cursor is read.
Our instrumentation wraps the query method, which is always fast.
Here is an example of a transaction with a slow query select * from storeitem where first_name regexp '.*.*.*.*1'. The Dao span is correct, but the db.sql.query span is 1ms long, which is wrong. The related profile gives some more insight.
This affects only select queries, as updates don't return a cursor.
We should wrap the cursor with a custom wrapper and override the correct methods.
Some challenges:

  • getCount() fills the data only the first time, so we should account for that
  • onMove() is not available in Cursor, but only in SQLiteCursor. But we get a Cursor and we should return a Cursor
  • accessing private fields in SQLiteCursor with reflection failed

Metadata

Metadata

Assignees

Labels

BugIssue type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions