mirror of https://github.com/postgres/postgres
If the value of an index expression is unchanged after UPDATE, allow HOT updates where previously we disallowed them, giving a significant performance boost in those cases. Particularly useful for indexes such as JSON->>field where the JSON value changes but the indexed value does not. Submitted as "surjective indexes" patch, now enabled by use of new "recheck_on_update" parameter. Author: Konstantin Knizhnik Reviewer: Simon Riggs, with much wordsmithing and some cleanuppull/31/merge
parent
1944cdc982
commit
c203d6cf81
@ -0,0 +1,61 @@ |
||||
create table keyvalue(id integer primary key, info jsonb); |
||||
create index nameindex on keyvalue((info->>'name')) with (recheck_on_update=false); |
||||
insert into keyvalue values (1, '{"name": "john", "data": "some data"}'); |
||||
update keyvalue set info='{"name": "john", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
0 |
||||
(1 row) |
||||
|
||||
drop table keyvalue; |
||||
create table keyvalue(id integer primary key, info jsonb); |
||||
create index nameindex on keyvalue((info->>'name')) with (recheck_on_update=true); |
||||
insert into keyvalue values (1, '{"name": "john", "data": "some data"}'); |
||||
update keyvalue set info='{"name": "john", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
1 |
||||
(1 row) |
||||
|
||||
update keyvalue set info='{"name": "smith", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
1 |
||||
(1 row) |
||||
|
||||
update keyvalue set info='{"name": "smith", "data": "some more data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
2 |
||||
(1 row) |
||||
|
||||
drop table keyvalue; |
||||
create table keyvalue(id integer primary key, info jsonb); |
||||
create index nameindex on keyvalue((info->>'name')); |
||||
insert into keyvalue values (1, '{"name": "john", "data": "some data"}'); |
||||
update keyvalue set info='{"name": "john", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
1 |
||||
(1 row) |
||||
|
||||
update keyvalue set info='{"name": "smith", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
1 |
||||
(1 row) |
||||
|
||||
update keyvalue set info='{"name": "smith", "data": "some more data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
pg_stat_get_xact_tuples_hot_updated |
||||
------------------------------------- |
||||
2 |
||||
(1 row) |
||||
|
||||
drop table keyvalue; |
@ -0,0 +1,30 @@ |
||||
create table keyvalue(id integer primary key, info jsonb); |
||||
create index nameindex on keyvalue((info->>'name')) with (recheck_on_update=false); |
||||
insert into keyvalue values (1, '{"name": "john", "data": "some data"}'); |
||||
update keyvalue set info='{"name": "john", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
drop table keyvalue; |
||||
|
||||
create table keyvalue(id integer primary key, info jsonb); |
||||
create index nameindex on keyvalue((info->>'name')) with (recheck_on_update=true); |
||||
insert into keyvalue values (1, '{"name": "john", "data": "some data"}'); |
||||
update keyvalue set info='{"name": "john", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
update keyvalue set info='{"name": "smith", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
update keyvalue set info='{"name": "smith", "data": "some more data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
drop table keyvalue; |
||||
|
||||
create table keyvalue(id integer primary key, info jsonb); |
||||
create index nameindex on keyvalue((info->>'name')); |
||||
insert into keyvalue values (1, '{"name": "john", "data": "some data"}'); |
||||
update keyvalue set info='{"name": "john", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
update keyvalue set info='{"name": "smith", "data": "some other data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
update keyvalue set info='{"name": "smith", "data": "some more data"}' where id=1; |
||||
select pg_stat_get_xact_tuples_hot_updated('keyvalue'::regclass); |
||||
drop table keyvalue; |
||||
|
||||
|
Loading…
Reference in new issue