sqlite - Can the LIKE statement be optimized to not do full table scans? -
i want subtree table tree path.
the path
column stores strings like:
foo/ foo/bar/ foo/bar/baz/
if try select records start path:
explain query plan select * f path "foo/%"
it tells me table scanned, though path
column indexed :(
is there way make use index , not scan table?
i found way achieve want closure table, it's harder maintain , writes extremely slow...
to able use index in sqlite,
- the table column must have text affinity, i.e., have type of text or varchar or that; and
the index must declared collate nocase (either directly, or because column has been declared collate nocase):
> create table f(path text); > create index fi on f(path collate nocase); > explain query plan select * f path 'foo/%'; 0|0|0|search table f using covering index fi (path>? , path<?)
the second restriction removed case_sensitive_like pragma, change behaviour of like. alternatively, 1 use case-sensitive comparison, replacing like 'foo/%'
glob 'foo/*'
.
Comments
Post a Comment