我有下表:
CREATE TABLE dpg2
(
account_id integer NOT NULL,
tank_id integer NOT NULL,
battles integer,
dmg integer,
frags integer,
wins integer,
recent_battles integer[],
recent_dmg integer[],
recent_frags integer[],
recent_wins integer[],
dpg real,
recent_ts timestamp with time zone[],
recent_dpg real,
CONSTRAINT dpg2_pkey PRIMARY KEY (account_id, tank_id)
)
Run Code Online (Sandbox Code Playgroud)
使用此索引:
CREATE INDEX dpg_tank_id_idx
ON dpg2
USING btree
(tank_id, dpg DESC NULLS LAST);
Run Code Online (Sandbox Code Playgroud)
我运行了以下查询:
explain analyze
select dpg2.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg2.account_id), dpg2.battles, dpg,
frags*1.0/dpg2.battles, wins*100.0/dpg2.battles, dpg2.recent_dpg
from dpg2
where …Run Code Online (Sandbox Code Playgroud)