A database administrator wants to create an index on the address column in the CUSTOMER_MSTR table. Their statement is below:
CREATE INDEX ADDRESS ON CUSTOMER_MSTR (Address(64));
You think the index can be a lot shorter and therefore more efficient. Write an example SQL query that you could run to show that an index based on Address with a length of 32 characters is just as good as one with a length of 64 characters.
题目说在CUSTOMER_MSTR表中在address建一个index如下:
CREATE INDEX ADDRESS ON CUSTOMER_MSTR (Address(64));
你认为index没必要那么长因此能够更加有效。写一个可以运行的SQL查询来表明32个字母长度的地址和64个长度的地址运行一样好?
有sql的专家来说说吗
希望能写出完整的query,插入数据insert可以省略
那你自己试试就行。插入大量的数据用来测试。
一般整形字段创建索引比较合适,字符串创建索引是比较慢的,因为要逐个字符按照ASCII码的大小进行比较,所以字符串越长速度越慢。
这个题目问的是前缀索引,sql如下:
select * from CUSTOMER_MSTR where Address like 'xxx%';
或者
select * from CUSTOMER_MSTR where Address = 'xxxxx';
用address作为检索条件就行。