From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Anton <djeday84(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [HACKERS] optimization join on random value |
Date: | 2015-05-04 07:01:43 |
Message-ID: | 20150504070143.GA4595@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Mon, May 04, 2015 at 12:15:54AM +0300, Anton wrote:
> Hello guru of postgres, it's possoble to tune query with join on
> random string ?
> i know that it is not real life example, but i need it for tests.
>
> soe=# explain
> soe-# SELECT ADDRESS_ID,
> soe-# CUSTOMER_ID,
> soe-# DATE_CREATED,
> soe-# HOUSE_NO_OR_NAME,
> soe-# STREET_NAME,
> soe-# TOWN,
> soe-# COUNTY,
> soe-# COUNTRY,
> soe-# POST_CODE,
> soe-# ZIP_CODE
> soe-# FROM ADDRESSES
> soe-# WHERE customer_id = trunc( random()*45000) ;
> QUERY PLAN
> -------------------------------------------------------------------------------------------
> Seq Scan on addresses (cost=0.00..165714.00 rows=22500 width=84)
> Filter: ((customer_id)::double precision = trunc((random() *
> 45000::double precision)))
> (2 rows)
If you look carefully you'll see that the comparison here is done as a
"double precision" and so can't use the index. If you say something
like:
WHERE customer_id = trunc( random()*45000)::bigint
it will probably work fine.
Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
-- Arthur Schopenhauer
From | Date | Subject | |
---|---|---|---|
Next Message | sanjeetkamble | 2015-05-04 07:02:29 | Re: Setting up a database for 10000 concurrent users |
Previous Message | David G. Johnston | 2015-05-04 02:16:12 | Re: Errors using JDBC batchUpdate with plpgsql function |
From | Date | Subject | |
---|---|---|---|
Next Message | Bernd Helmle | 2015-05-04 08:36:20 | Re: Disabling trust/ident authentication configure option |
Previous Message | Michael Paquier | 2015-05-04 05:02:18 | Potential pointer dereference in plperl.c (caused by transforms patch) |