Skip to content

Easiest way to do an EXPLAIN  #363

@sobri909

Description

@sobri909

I'm doing a bunch of performance tuning this week, and am at the point where I want to EXPLAIN a bunch of queries, to make sure I'm not doing anything dumb with indexes etc.

But so far I haven't found a tidy way to get EXPLAIN results via GRDB.

This is an example of my current attempts:

let query = "EXPLAIN SELECT * FROM LocomotionSample WHERE timelineItemId = '5F7E4537-74A0-48A0-9E75-A2F29BF5BD6' AND deleted = 0 ORDER BY date"
try! Stalker.store.pool.read { db in
    if let row = try Row.fetchOne(db, query) {
        print("EXPLAIN: \(row)")
    }
}

Which results in this:

EXPLAIN: [addr:0 opcode:"Init" p1:0 p2:76 p3:0 p4:"" p5:"00" comment:NULL]

I suspect there's more detail in there that I can extract, but I haven't stumbled onto a way to find it yet. (I'm poking about in the Row code now, but not sure if that's the right place to look).

Do you have any tips, to save me from fumbling around like an idiot for too much longer? 😂

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions