我有一个分区表...
CREATE TABLE erco.rtprices
(
scedtime timestamp with time zone NOT NULL,
node_id integer NOT NULL,
lmp numeric(12,6),
CONSTRAINT rtprices_pkey PRIMARY KEY (scedtime, node_id)
) PARTITION BY LIST (node_id);
Run Code Online (Sandbox Code Playgroud)
每个都有node_id
自己的分区。
如果我进行直接查询(第一个版本),例如:
explain select scedtime, lmp
from erco.rtprices
where node_id = 11111
Run Code Online (Sandbox Code Playgroud)
然后该计划仅对rtprices_11111
分区进行顺序扫描。 这就是我要的。
但是,如果我执行(第二个版本)查询,例如
explain select scedtime, lmp
from erco.rtprices
inner join erco.nodes using (node_id)
where nodename = 'somename'
Run Code Online (Sandbox Code Playgroud)
那么该计划包括对每个分区进行顺序扫描,即使此查询与第一个查询一样有限制。
我尝试了上述查询的另一种形式(第三个版本)。
explain select scedtime, lmp
from erco.rtprices
where node_id = (select node_id from erco.nodes where nodename='somename') …
Run Code Online (Sandbox Code Playgroud) postgresql execution-plan partitioning postgresql-performance postgresql-13