有没有办法指示MySQL不使用索引,即使它是可用的?同样,即使列可用,也不使用它吗?(例如,只需将查询错误显示为"column For not exist“。)在准备删除索引或字段时,拥有此功能将非常有用。
Postgres怎么样?
发布于 2021-03-13 04:46:14
免责声明:仅限PostgreSQL ...我已经8年没有使用过MySQL了。
此外,您似乎没有针对查询,但我想我还是要提供它(可能是任何有类似问题的人)。
这是一个小技巧,但是如果你考虑下表:
create table foo (
id integer
);
create index foo_ix1 on foo (id);
insert into foo generate_series (1, 1000000);正如您可能预期的那样,这将使用索引:
explain
select * from foo
where id between 5 and 10;除非该特定函数具有基于函数的索引,否则对列应用任何函数都会使规划器不能使用该索引。简单的例子:
explain
select * from foo
where id + 0 between 5 and 10;我没有改变结果,但我强制进行了全面扫描。
例如,对于文本列,您可以只附加一个空字符串:text_field || ''。
发布于 2021-03-13 03:25:04
在PostgreSQL中,您可以turn off索引扫描:
set enable_indexscan to 'off';
set enable_indexonlyscan to 'off';
set enable_bitmapscan to 'off';或者让它们变得非常昂贵:
set random_page_cost to 10000000;https://stackoverflow.com/questions/66605673
复制相似问题