How can an absolute-error lookup use an expression index?
SQLite can index an expression. The planner generally looks for a matching expression in the query.
SQLite example and interpretation
Index abs(error) and use that expression to filter large misses. Mathematical equivalence alone does not guarantee that a rewritten query will match the index.
CREATE TABLE r(error REAL);
CREATE INDEX abs_err ON r(abs(error));
EXPLAIN QUERY PLAN SELECT error FROM r WHERE abs(error)>5;Result [[3, 0, 206, "SEARCH r USING INDEX abs_err (<expr>>?)"]]
中文
怎样让按绝对误差查询利用表达式索引?
SQLite 可索引表达式;规划器通常要求查询中出现与索引声明相匹配的表达式。
SQLite 示例与适用条件
为 abs(error) 建索引,再用相同表达式过滤大偏差。数学上等价的改写不保证规划器认作同一索引条件。
CREATE TABLE r(error REAL);
CREATE INDEX abs_err ON r(abs(error));
EXPLAIN QUERY PLAN SELECT error FROM r WHERE abs(error)>5;结果 [[3, 0, 206, "SEARCH r USING INDEX abs_err (<expr>>?)"]]