Erlang Mailing Lists

Author Message

<  Erlang questions mailing list  ~  mnesia secondary index

mattevans
Posted: Tue Jun 22, 2010 11:20 pm Reply with quote
User Joined: 07 Jun 2009 Posts: 47
Hi,

I have a fragmented mnesia table that I need to add a second index to.

It appears that to get this working I need to call mnesia:add_table_index/2 for each fragment.

i.e.

mnesia:add_table_index(content_table,file_id).
mnesia:add_table_index(content_table_frag2,file_id).
mnesia:add_table_index(content_table_frag3,file_id).
....
mnesia:add_table_index(content_table_fragN,file_id).

Likewise, to do an index read of the fragmented table I need to search each fragment in turn:

mnesia:activity(sync_dirty,fun mnesia:dirty_index_read/3,[content_table,{1,1,1},file_id],mnesia_frag).
mnesia:activity(sync_dirty,fun mnesia:dirty_index_read/3,[content_table_frag2,{1,1,1},file_id],mnesia_frag).
....
until match found, or
....
mnesia:activity(sync_dirty,fun mnesia:dirty_index_read/3,[content_table_fragN,{1,1,1},file_id],mnesia_frag).

I guess searching through multiple fragments is quicker than a brute-force mnesia:match_object/1 or mnesia:select/4, but I was wondering if there is a better way to do this?

I could, of course, have my own secondary index table (in the example above the key would be file_id and the data would be the primary key I ultimately want). But I now need to ensure the two tables remain in sync.

Is there another way anyone is aware of?

Thanks

Matt



Post received from mailinglist
View user's profile Send private message
chandru.m
Posted: Wed Jun 23, 2010 8:47 am Reply with quote
User Joined: 24 Oct 2007 Posts: 85
Hi Matt,

On 23 June 2010 00:18, Evans, Matthew <mevans@verivue.com> wrote:

> Hi,
>
> I have a fragmented mnesia table that I need to add a second index to.
>
> It appears that to get this working I need to call mnesia:add_table_index/2
> for each fragment.
>
>
Yes - that is correct.


> Likewise, to do an index read of the fragmented table I need to search each
> fragment in turn:
>

Not really - the following code should do.

dirty_index_read(Tab, SecondaryKey, Pos) ->
F = fun(T, Sk, P) -> mnesia:index_read(T,Sk,P) end,
mnesia:activity(async_dirty, F, [Tab, SecondaryKey, Pos], mnesia_frag).

cheers
Chandru


Post received from mailinglist
View user's profile Send private message
mattevans
Posted: Wed Jun 23, 2010 12:08 pm Reply with quote
User Joined: 07 Jun 2009 Posts: 47
Many thanks. I was thrown by me doing:

74> mnesia:activity(sync_dirty,fun mnesia:dirty_index_read/3,[cmfs_content_uuid_table,{1,1,1},file_id],mnesia_frag).
[]

When I should've done:

73> mnesia:activity(sync_dirty,fun mnesia:index_read/3,[cmfs_content_uuid_table,{1,1,1},file_id],mnesia_frag).
[#cmfs_content_uuid_table{content_uuid = 1,
file_id = {1,1,1},
nts_start_offset = '_',nts_duration = '_',start_time = '_',
end_time = '_',restripe_time = '_',version_id = '_',
start_of_content = '_',average_bit_rate = '_',
peak_bit_rate = '_',program_id = '_',frame_rate_code = '_',
video_format = '_',video_size = '_',pid_info_list = '_',
duration = '_',media_type = '_',size = '_',data_state = '_',
checksum = '_'}]

________________________________________
From: Chandru [chandrashekhar.mullaparthi@gmail.com]
Sent: Wednesday, June 23, 2010 4:44 AM
To: Evans, Matthew
Cc: erlang-questions@erlang.org
Subject: Re: [erlang-questions] mnesia secondary index

Hi Matt,

On 23 June 2010 00:18, Evans, Matthew <mevans@verivue.com<mailto:mevans@verivue.com>> wrote:
Hi,

I have a fragmented mnesia table that I need to add a second index to.

It appears that to get this working I need to call mnesia:add_table_index/2 for each fragment.


Yes - that is correct.

Likewise, to do an index read of the fragmented table I need to search each fragment in turn:

Not really - the following code should do.

dirty_index_read(Tab, SecondaryKey, Pos) ->
F = fun(T, Sk, P) -> mnesia:index_read(T,Sk,P) end,
mnesia:activity(async_dirty, F, [Tab, SecondaryKey, Pos], mnesia_frag).

cheers
Chandru


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscribe@erlang.org

Post received from mailinglist
View user's profile Send private message
wuji
Posted: Wed Sep 12, 2012 8:43 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
PressSANAA, Yemen Yemeni President Ali Abdullah Saleh was wounded when opposition opposition [h3]cheap Ralph Lauren[/h3] opposition tribesmen determined to topple him hammered his palace with rockets Friday
a major escalation of nearly two weeks of fighting with government forces. forces. [h2]cheap authentic jordans[/h2] forces. At least six guards were killed and seven top officials were
wounded, an official said.The official said Saleh suffered slight injuries to the the knockoff designer *beep* the neck and was treated in the palace. Yemeni state TV quickly
a statement that Saleh was "in good health," denying a claim on on [h4]knockoff designer *beep*[/h4] on an opposition TV station that the president was killed in the
was the first time that tribal fighters have directly targeted Saleh's palace palace [h3]cheap Ralph Lauren[/h3] palace in the fighting that has rocked the capital since May 23.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum