假设我有一张桌子:
CREATE TABLE transactions (
id NUMERIC(20, 0) PRIMARY_KEY,
account_id VARCHAR(512),
...
transaction_date TIMESTAMP
);
因此,对于 SQL Server,索引:
CREATE NONCLUSTERED INDEX my_index ON transactions (account_id, transaction_date, id);
和一个查询:
SELECT id FROM transactions
WHERE account_id = '123'
AND transaction_date > '2023-01-01'
执行索引查找,这意味着查询是从索引完成的,而不是引用表,因为它需要的所有数据都存在于表中。如果我的索引是:
CREATE NONCLUSTERED INDEX my_index ON transactions (account_id, transaction_date);
查询将转到表来完成查询(索引扫描)。以下哪个数据库:
- 甲骨文
- MySQL
- PostgreSQL
支持以上行为吗?
大多数主要数据库供应商都提供此功能: