performance - Postgresql: Select 6M rows - takes 5min? -


when select table below (containing 6 milion rows) takes 5 minutes complete following statement:

select * public.matchmsg order tradeid desc 

what doing wrong?


table definition

create table public.matchmsg (   id bigint not null default nextval('matchmsg_id_seq'::regclass),   tradeid bigint not null,   matchdate timestamp time zone,   price double precision not null,   size double precision not null,   issell boolean not null,   constraint matchmsg_pkey primary key (id) ) (   oids=false,   autovacuum_enabled=true ); alter table public.matchmsg   owner mb;  create unique index tradeid_idx   on public.matchmsg   using btree   (tradeid); 

update 1:

explain analyse select * public.matchmsg;  "seq scan on matchmsg  (cost=0.00..117720.03 rows=6000103 width=41) (actual time=0.041..837.495 rows=6000102 loops=1)" "planning time: 1.769 ms" "execution time: 914.932 ms" 

is query supposed execute in 117 sec?

update 2:

explain analyse select * public.matchmsg order tradeid  "index scan using tradeid_idx on matchmsg  (cost=0.43..278622.57 rows=6177667 width=41) (actual time=0.172..1465.935 rows=6177670 loops=1)" "planning time: 0.246 ms" "execution time: 1553.377 ms" 

update 3:

to right , proper answer have ask right question...and may didnt... realized selecting 6m rows not make sense...but fact did - , didnt understand why pc slow give me proper response (and still dont - no matter of db, ui or ever - think 5 min way slow - im using postgres own native tools: pg enterprise m. or pg pgadminiii - identical). tools faster/better, guys use postgresql?

i realize index doesnt thing - when select rows , columns.

i tried run cluster statement - didnt change - far tell...?

what im going 6m rows? - im going lot of different analysis algorithm/patterns on time... depending on math/expressions need , how difficult/tough calculate ect... think have 2 options here:

either needed math via sql in db or load 1000 rows(only column/s) nodejs code, math on given loaded data...loop through entire db...

to info follow statements perform this:

select sum(price) matchmsg --> 1 sec!  select tradeid matchmsg order tradeid asc limit 1000 offset 5000000 --> 1 sec! 

i tried execute

"select * matchmsg" 

inside nodejs - after 30 sec or crash - error desc:

"fatal error: call_and_retry_last allocation failed - process out of memory". 

but far more interesting fact that:

"select tradeid matchmsg" --> 7 sec! 

and pick out resultset[5000000] , tradeid @ position within 7 sec inside nodejs app...

all these fact make in end of day - have down real math understand way go...

this normal behavior. in such cases main problem fact user has wait lot. might consider repeated sending of chunks of data, show part of data, while whole data being loaded. also, might consider using paging, more-or-less standard, waiting time such task pretty normal.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -