select
user_id,
date,
SUM(amount) filter(where currency = 'USD') AS USD,
SUM(amount) filter(where currency = 'USD') AS EUR
FROM Table1
GROUP BY user_id, date
CREATE UNIQUE INDEX test_good_default_goods ON test_good (good_id)
WHERE by_default = true
update test_good set by_default = true where id = :id
update test_good set by_default = (id = :new_default_id) where good_id = :good_id
explain analyze select max(time) from params where counter_id in (6001, 15998);
Aggregate (cost=18.52..18.53 rows=1 width=8) (actual time=1.586..1.586 rows=1 loops=1)
-> Index Only Scan using params_counter_id_time_idx on params (cost=0.56..18.51 rows=4 width=8) (actual time=0.769..1.566 rows=12 loops=1)
Index Cond: (counter_id = ANY ('{6001,15998}'::bigint[]))
Heap Fetches: 2
Planning time: 50.191 ms
Execution time: 1.933 ms
Aggregate (cost=25.20..25.21 rows=1 width=8) (actual time=38.797..38.797 rows=1 loops=1)
-> Bitmap Heap Scan on params (cost=9.16..25.19 rows=4 width=8) (actual time=0.362..38.749 rows=12 loops=1)
Recheck Cond: ((counter_id = 6001) OR (counter_id = 15998))
Heap Blocks: exact=12
-> BitmapOr (cost=9.16..9.16 rows=4 width=0) (actual time=0.042..0.042 rows=0 loops=1)
-> Bitmap Index Scan on params_counter_id_time_idx (cost=0.00..4.58 rows=2 width=0) (actual time=0.031..0.031 rows=6 loops=1)
Index Cond: (counter_id = 6001)
-> Bitmap Index Scan on params_counter_id_time_idx (cost=0.00..4.58 rows=2 width=0) (actual time=0.009..0.009 rows=6 loops=1)
Index Cond: (counter_id = 15998)
Planning time: 0.247 ms
Execution time: 39.408 ms
Повторно запрос выполняется много быстрее.
В конфиге postgresql менял настройки только авторизации.
select count(*) from test JOIN (VALUES (1),...,(10000)) AS v(val) USING (val);
CREATE OR REPLACE FUNCTION process_data(
s_input text
)
RETURNS void
AS $function$
DECLARE
a_data text[];
BEGIN
a_data := regexp_matches(s_input, '^Login: ([^;]+); IP ([\d\.]+); Time: ([\d\:\.\s]+)$');
raise notice 'Login %', a_data[1];
raise notice 'IP %', a_data[2];
raise notice 'Time %', to_timestamp(a_data[3], 'DD.MM.YYYY HH24:MI:SS');
END;
$function$
LANGUAGE plpgsql STABLE SECURITY DEFINER;