From: | Jan Kort <jan(dot)kort(at)genetics(dot)nl> |
---|---|
To: | "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
Subject: | Index not used without explicit typecast |
Date: | 2020-08-05 13:05:12 |
Message-ID: | AM0PR0502MB362043B5A7B389D4986E6D619B4B0@AM0PR0502MB3620.eurprd05.prod.outlook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Hi,
When I have a large table, the index is not used if the type I use in the comparison does not match exactly. The result is the same, but it takes longer.
Below is an example that illustrates this.
Is it possible to fix this?
Regards,
Jan
-- Create 4M records
drop table if exists table1;
create table table1 (
id integer NOT NULL,
CONSTRAINT table1p PRIMARY KEY (id),
date1 timestamp without time zone);
insert into table1 (id) values (1);
insert into table1 (id) select id + 1 from table1;
insert into table1 (id) select id + 2 from table1;
insert into table1 (id) select id + 4 from table1;
insert into table1 (id) select id + 8 from table1;
insert into table1 (id) select id + 16 from table1;
insert into table1 (id) select id + 32 from table1;
insert into table1 (id) select id + 64 from table1;
insert into table1 (id) select id + 128 from table1;
insert into table1 (id) select id + 256 from table1;
insert into table1 (id) select id + 512 from table1;
insert into table1 (id) select id + 1024 from table1;
insert into table1 (id) select id + 2048 from table1;
insert into table1 (id) select id + 4096 from table1;
insert into table1 (id) select id + 8192 from table1;
insert into table1 (id) select id + 16384 from table1;
insert into table1 (id) select id + 32768 from table1;
insert into table1 (id) select id + 65536 from table1;
insert into table1 (id) select id + 65536 * 2 from table1;
insert into table1 (id) select id + 65536 * 4 from table1;
insert into table1 (id) select id + 65536 * 8 from table1;
insert into table1 (id) select id + 65536 * 16 from table1;
insert into table1 (id) select id + 65536 * 32 from table1;
vacuum analyze table1;
select count(*) from table1
UPDATE TABLE1 SET date1 = current_timestamp WHERE ID = 1000000;
-- 45ms
UPDATE TABLE1 SET date1 = current_timestamp WHERE ID = 1000000::numeric;
-- 490ms
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2020-08-05 14:32:22 | Re: Index not used without explicit typecast |
Previous Message | PG Bug reporting form | 2020-08-05 11:46:01 | BUG #16574: Error in configuration of pgadmin4-server (amd64 4.24) on Debian version 10.5 |