【问题标题】:Does a substring search with LIKE benefit from an index?使用 LIKE 进行子字符串搜索是否受益于索引?
【发布时间】:2020-07-23 15:53:00
【问题描述】:

假设 HSQLDB 中的表定义如下:

create table message(id varchar(255) primary key not null, data clob not null);

HSQLDB 自动在id(作为主键)上创建的索引会加速如下的子字符串搜索吗?

select * from message where id like 'foo:%'

【问题讨论】:

    标签: indexing sql-like hsqldb


    【解决方案1】:

    显然,子字符串搜索确实受益于该列上的索引。

    跑步

    explain plan for select * from message where id like 'foo:%'
    

    给我

    …
    access=INDEX PRED
    …
    

    就像一个简单的等号比较。这似乎适用于任何子字符串,例如'%foo%',不只是字符串的开头。

    为了比较,如果我在 data 列(没有索引,因此需要全表扫描)上尝试相同的操作,我得到

    …
    access=FULL SCAN
    …
    

    【讨论】:

      猜你喜欢
      • 2013-03-14
      • 1970-01-01
      • 2014-03-06
      • 2015-12-12
      • 2021-11-21
      • 2013-10-10
      • 1970-01-01
      • 2019-11-01
      • 2013-08-09
      相关资源
      最近更新 更多