How do I efficiently get the first n rows of a query from partitioned table?

967 views
Skip to first unread message

Pavel Hejbal

unread,
May 23, 2014, 10:59:28 AM5/23/14
to personal...@googlegroups.com
I want to get for example first 10 rows from partitioned table in specific date (date is a partition column). The solution is

10# select from trade where date = 2014.01.02


but this query has the same usage of memory as

select from trade where date = 2014.01.02

(I used \ts and get same values for both cases)

so I hope, theres more efficient solution. Any ideas, please?

Thanks Pavel

Charles Skelton

unread,
May 23, 2014, 11:12:32 AM5/23/14
to personal...@googlegroups.com
This isn't necessary on 64bit, but on 32bit this should reduce your mem load; using functional select, load a column at a time. Here using trade table, last date. Use parse"select …." to figure out how to form functional select.

q)flip raze {flip 10#?[trade;enlist(=;`date;2014.01.02);0b;(enlist x)!enlist x]}each cols trade


--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl...@googlegroups.com.
To post to this group, send email to personal...@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.

Sean O'Hagan

unread,
May 23, 2014, 11:47:22 AM5/23/14
to personal...@googlegroups.com
select from trade where date=2014.01.02,i within (1;1+10)
or look at 

Thanks,
Sean

Attila Vrabecz

unread,
May 23, 2014, 11:55:29 AM5/23/14
to [kdb+] [kdb+]
address-space/mapping is the problem
hence Charlie's suggestion

10#..
or
..i<10

does not matter

Cheers,
  Attila

  Attila


--

Pavel Hejbal

unread,
May 23, 2014, 1:11:51 PM5/23/14
to personal...@googlegroups.com
I can't use i<10 nor select [10] becase it is partitioned table. It tried .Q.ind before, but I waited for resuresult almost half an hour.Selecting by date is quite complicated with .Q.ind and not efficient (searching for starting index of the particilar date).

Charles Skelton

unread,
May 23, 2014, 1:29:22 PM5/23/14
to personal...@googlegroups.com
With 32bit, for ease of querying, you probably don't want to go above ~500MB per partition.


On Fri, May 23, 2014 at 7:11 PM, Pavel Hejbal <pavel....@gmail.com> wrote:
I can't use i<10 nor select [10] becase it is partitioned table. It tried .Q.ind before, but I waited for resuresult almost half an hour.Selecting by date is quite complicated with .Q.ind and not efficient (searching for starting index of the particilar date).
Message has been deleted

Pavel Hejbal

unread,
May 26, 2014, 3:31:45 AM5/26/14
to personal...@googlegroups.com
Thank you for all responses. So it looks, there is no less memory consuming solution, the only way is to keep partiones "small" enough.

Dne pátek, 23. května 2014 19:29:22 UTC+2 Charles Skelton napsal(a):
Reply all
Reply to author
Forward
0 new messages