我有两张桌子:
CREATE TABLE soils (
sample_id TEXT PRIMARY KEY,
project_id TEXT,
technician_id TEXT
);
CREATE INDEX soils_idx
ON soils
USING btree
(sample_id COLLATE pg_catalog."default");
CREATE TABLE assays (
sample_id TEXT PRIMARY KEY,
mo_ppm NUMERIC
);
CREATE INDEX assays_idx
ON assays
USING btree
(sample_id COLLATE pg_catalog."default");
每个表包含大约 50 万条记录,实际上,每个表大约有 20 个额外的列,类型为 TEXT(在上面发布的 DDL 中省略以节省时间)。
当我执行查询时:
EXPLAIN SELECT
s.sample_id, s.project_id, s.technician_id, a.mo_ppm
FROM
soils AS s INNER JOIN assays AS a ON s.sample_id = a.sample_id
我得到 2 个 SEQ SCAN,而不是查找索引。这是预期的行为吗?