postgresql-performance

Is there any way to speed up this Postgres bitmap heap scan?

你说的曾经没有我的故事 提交于 2019-12-11 11:10:37
问题 Database newbie here. This is my query, I'm using Postgres 9.3.5: =# explain analyse SELECT SUM(actual_cost) as cost, SUM(total_items) as num_items, processing_date FROM frontend_items WHERE chemical_id='0501013B0' GROUP BY processing_date; And this is the query plan: HashAggregate (cost=1648624.91..1648624.92 rows=1 width=16) (actual time=12591.844..12591.848 rows=17 loops=1) -> Bitmap Heap Scan on frontend_items (cost=14520.24..1643821.35 rows=640474 width=16) (actual time=254.841..12317

Slow Postgres 9.3 Queries, again

≡放荡痞女 提交于 2019-12-11 08:15:35
问题 This is a follow-up to the question at Slow Postgres 9.3 queries. The new indexes definitely help. But what we're seeing is sometimes queries are much slower in practice than when we run EXPLAIN ANALYZE. An example is the following, run on the production database: explain analyze SELECT * FROM messages WHERE groupid=957 ORDER BY id DESC LIMIT 20 OFFSET 31980; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------

Is it possible to answer queries on a view before fully materializing the view?

戏子无情 提交于 2019-12-11 07:16:43
问题 In short: Distinct,Min,Max on the Left hand side of a Left Join, should be answerable without doing the join. I’m using a SQL array type (on Postgres 9.3) to condense several rows of data in to a single row, and then a view to return the unnested normalized view. I do this to save on index costs, as well as to get Postgres to compress the data in the array. Things work pretty well, but some queries that could be answered without unnesting and materializing/exploding the view are quite

Efficient way to move large number of rows from one table to another new table using postgres

流过昼夜 提交于 2019-12-10 16:31:46
问题 I am using PostgreSQL database for live project. In which, I have one table with 8 columns. This table contains millions of rows, so to make search faster from table, I want to delete and store old entries from this table to new another table. To do so, I know one approach: first select some rows create new table store this rows in that table than delete from main table. But it takes too much time and it is not efficient. So I want to know what is the best possible approach to perform this in

How to get unique values from each column based on a condition?

♀尐吖头ヾ 提交于 2019-12-10 10:01:34
问题 I have been trying to find an optimal solution to select unique values from each column . My problem is I don't know column names in advance since different table has different number of columns. So first, I have to find column names and I could use below query to do it: select column_name from information_schema.columns where table_name='m0301010000_ds' and column_name like 'c%' Sample output for column names: c1, c2a, c2b, c2c, c2d, c2e, c2f, c2g, c2h, c2i, c2j, c2k, ... Then I would use

Faster search for records where 1st character of field doesn't match [A-Za-z]?

百般思念 提交于 2019-12-09 18:29:59
问题 I currently have the following: User (id, fname, lname, deleted_at, guest) I can query for a list of user's by their fname initial like so: User Load (9.6ms) SELECT "users".* FROM "users" WHERE (users.deleted_at IS NULL) AND (lower(left(fname, 1)) = 's') ORDER BY fname ASC LIMIT 25 OFFSET 0 This is fast thanks to the following index: CREATE INDEX users_multi_idx ON users (lower(left(fname, 1)), fname) WHERE deleted_at IS NULL; What I want to do now is be able to query for all Users that do

Postgresql IN operator Performance: List vs Subquery

爷,独闯天下 提交于 2019-12-08 21:38:31
问题 For a list of ~700 ids the query performance is over 20x slower than passing a subquery that returns those 700 ids. It should be the opposite. e.g. (first query takes under 400ms, the later 9600 ms) select date_trunc('month', day) as month, sum(total) from table_x where y_id in (select id from table_y where prop = 'xyz') and day between '2015-11-05' and '2016-11-04' group by month is 20x faster on my machine than passing the array directly: select date_trunc('month', day) as month, sum(total)

Improve performance on SQL query with Nested Loop - PostgreSQL

笑着哭i 提交于 2019-12-07 09:39:57
问题 I am using PostgreSQL and I have a weird problem with my SQL query. Depending on wich date paramter I'm using . My request doesn't do the same operation. This is my working query : SELECT DISTINCT app.id_application FROM stat sj LEFT OUTER JOIN groupe gp ON gp.id_groupe = sj.id_groupe LEFT OUTER JOIN application app ON app.id_application = gp.id_application WHERE date_stat >= '2016/3/01' AND date_stat <= '2016/3/31' AND ( date_stat = date_gen-1 or (date_gen = '2016/04/01' AND date_stat =

postgres query with IN is very slow

◇◆丶佛笑我妖孽 提交于 2019-12-06 16:42:49
I have a table which has an index on (column A, column B). And I'm running a query that looks like this: SELECT * FROM table WHERE (A, B) IN ((a_1, b_1), (a_2, b_2), ..., (a_5000, b_5000)) This query is very slow ! The plan looks like: Bitmap Heap Scan on table Recheck Cond: (((A = a_1) AND (B = b_1)) OR ((A = a_2) AND (B = b_2)) OR ... -> BitmapOr -> Bitmap Index Scan on idx Index Cond: ((A = a_1) AND (B = b_1)) -> Bitmap Index Scan on idx Index Cond: ((A = a_2) AND (B = b_2)) ...(5000 other Bitmax Index Scan) Instead of doing one index scan with 5000 values, postgres seems to be doing 5000

Efficient PostgreSQL query on timestamp using index or bitmap index scan?

陌路散爱 提交于 2019-12-06 07:32:09
In PostgreSQL, I have an index on a date field on my tickets table. When I compare the field against now() , the query is pretty efficient: # explain analyze select count(1) as count from tickets where updated_at > now(); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=90.64..90.66 rows=1 width=0) (actual time=33.238..33.238 rows=1 loops=1) -> Index Scan using tickets_updated_at_idx on tickets (cost=0.01..90.27 rows=74 width=0) (actual time=0.016..29.318 rows=40250 loops=1)