Database
- PostgreSQL 13.10
Structure
Constraints
- name is "filter_test_group_id_test_group_id_test_name_id_filter_key_uniq"
UNIQUE(id_test_group, id_test_name, id_filter, key)
Indexes
- name is "filter_test_group_index_id_test"
CREATE INDEX filter_test_group_index_id_test ON filter_test_group(id_test_group)
Details
- for most cases(~90%) the
keycolumn contains SHA1 hash - for some cases(~10%) the
keycolumn contains simple strings like 'filter1', 'filter2', ...
Query
INSERT INTO management.filter_test_group
(id_test_group, id_test_name, id_filter, key, value)
VALUES
('{0}', '{1}', '{2}', '{3}', '{4}')
ON CONFLICT ON CONSTRAINT filter_test_group_id_test_group_id_test_name_id_filter_key_uniq
DO UPDATE SET value = '{4}'
Usage
- I have many upserts for the
valuecolumn based on the unique constraint - I do several upserts for unique constraints in a single transaction(ReadCommitted)
- All upserts in a transaction belog to different unique constraints
Problem
- The upsert query run slowly as the size of the table grows
Question
- Who may I optimaze the structure of the tables or optimaze the way how to update the
valuecolumn?
It is possible to leave only SHA1 hash for the key column if it will help

EXPLAIN ANALYZEshow? – J.D. Aug 10 '23 at 12:45