| Author |
Message |
< Advanced Erlang/OTP ~ fetching specific number of rows from mnesia database |
| rkewlani |
Posted: Fri Sep 26, 2008 6:02 am |
|
|
|
User
Joined: 10 Sep 2008
Posts: 11
|
hi,
I want to fetch n number of records from mnesia database which contains m number of records, obviously (m>n).
I am using qlc for the same and applying the below approach -
H=do(qlc:q([X || X <- mnesia:table(table_name)])),
C = qlc:cursor(H),
R = qlc:next_answers(C, Number of rows),
ok = qlc:delete_cursor(C).
Above code is returning me the specified number of rows correctly. But it seem to be less efficient because it first fetches all the rows in H and then does processing on that for selecting given num of rows.
Is there any other way to do the same thing without fetching all the records.
Please help me out..
Thanks in advance. |
|
|
| Back to top |
|
| uwiger |
Posted: Fri Sep 26, 2008 6:45 pm |
|
|
|
User
Joined: 03 Jul 2006
Posts: 604
Location: Sweden
|
rkewlani wrote:
I want to fetch n number of records from mnesia database which contains m number of records, obviously (m>n).
You can do this using something like
Code: mnesia:select(Tab,[{'_',[],['$_']}], N, Lock)
(Lock will be e.g. read or write).
This will give you the first N matches, and the option to fetch N more until you reach the end of the table.
BR,
Ulf W |
|
|
| Back to top |
|
| rkewlani |
Posted: Mon Sep 29, 2008 6:22 am |
|
|
|
User
Joined: 10 Sep 2008
Posts: 11
|
Hi Ulf ,
Thanks for reply.
But I want to use qlc and you told it using mneisa only.
Is there any way to do the same using qlc? |
|
|
| Back to top |
|
| uwiger |
Posted: Tue Sep 30, 2008 11:02 am |
|
|
|
User
Joined: 03 Jul 2006
Posts: 604
Location: Sweden
|
rkewlani wrote: Hi Ulf ,
Thanks for reply.
But I want to use qlc and you told it using mneisa only.
Is there any way to do the same using qlc?
As far as I know, mnesia supports the option to specify how large each chunk of results should be when using QLC. This is done e.g. through mnesia:table(T, [{n_objects,N}]), but QLC will loop through the entire table anyway, so this is just a way to improve throughput.
I don't know of any trick in QLC that lets you break out of the loop when you have enough answers. If there were, I assume that the "cursor process" could attempt to be lazy and try to evaluate only enough of the query to satisfy the next_answers() request, but this is probably difficult for more complex queries...
I guess the bottom line is: if you really want to fetch only a limited number of objects, and the queries are as straightforward as in your example, you are better off using mnesia:select().
QLC needs to try to strike a reasonable compromise between lightweight queries and more complex ones, but one could say that its biggest challenge is to replace Mnemosyne. Mnemosyne performed quite elaborate query optimizations, but fell into disrepute to some extent, since people used it for very simple queries and expected it to be lean and mean - in most cases, they'd been much better off just using the match_object() and select() functions in mnesia.
This is slightly less true with QLC, but probably still pretty good advice. |
|
|
| Back to top |
|
| uwiger |
Posted: Wed Nov 05, 2008 3:11 pm |
|
|
|
User
Joined: 03 Jul 2006
Posts: 604
Location: Sweden
|
uwiger wrote: As far as I know, mnesia supports the option to specify how large each chunk of results should be when using QLC. This is done e.g. through mnesia:table(T, [{n_objects,N}]), but QLC will loop through the entire table anyway, so this is just a way to improve throughput.
I don't know of any trick in QLC that lets you break out of the loop when you have enough answers. If there were, I assume that the "cursor process" could attempt to be lazy and try to evaluate only enough of the query to satisfy the next_answers() request, but this is probably difficult for more complex queries...
Hans Bolinder tells me this is false, and he should know, as he wrote QLC. Cursors in QLC are indeed lazy. |
|
|
| Back to top |
|
| wuji |
Posted: Thu Sep 13, 2012 7:23 am |
|
|
|
User
Joined: 10 Aug 2012
Posts: 654
|
even by some very close family members, though."That was bad because they they cheap authentic air jordans they loved me and I loved them," she said. "And they didn't
me in the house."She said that wanting to be accepted for who who cheap jordan shoes who she is drove her to come out on television that year
Jerry Falwell, Pat Robertson and other members of the evangelical community who who cheap designer *beep* who said they were disappointed. Some called her "Ellen Degenerate.""You know Ellen
such a good person," her mother said. "Now, I don't want to to cheap polo shirts to get weepy, I don't, but she's so good that she shouldn't
all this directed at her."Today Betty DeGeneres fights for gay rights. She She [h1]designer replica *beep*[/h1] She is devoted and always tolerant.Bill Clinton Boosts President Obama - So
George W. Bush for Mitt Romney?2 Prior Presidents Take Dramatically Different Approaches Approaches cheap Ralph Lauren Polo Approaches to 2012 CampaignBy JOEL SIEGELMay 4, 2012 He was once |
|
|
| Back to top |
|
|
|