| Author |
Message |
|
| alamb |
Posted: Thu Mar 27, 2008 12:46 pm |
|
|
|
User
Joined: 26 Aug 2007
Posts: 55
Location: Geneva / Switzerland
|
Hello,
If I have a mnesia table configured as a set with two columns.
My key column is rather complexe (a tuple with several fields).
If I fetch records using match object (or match key) on a partial match (e.g. {Field1,'_','_',Field4} for example), how is it optimised? Will it use the index which is automatically put on key columns or will it scann the complete table?
Or, should I create an additionnal column with (for example) Field1 duplicated and first fetch on that additional indexed column before filtering the remaining records in memory?
Thanks,
Alex |
|
|
| Back to top |
|
| francesco |
Posted: Mon Mar 31, 2008 8:31 am |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
match and match object are optimized on the index fields. If the index fields are not included in the query, all elements are scanned.
Francesco
--
http://www.erlang-consulting.com |
|
|
| Back to top |
|
| alamb |
Posted: Mon Mar 31, 2008 10:41 am |
|
|
|
User
Joined: 26 Aug 2007
Posts: 55
Location: Geneva / Switzerland
|
But if my table is of type "set", the first column will be indexed automatically?
So there is an index.
If that column is full of tuples such as:
{a,b,c}
{a,x,d}
{b,c,f}
etc...
then I search for {a,b,'–'}
will the index be used. My problem is really: how does mnesia index a column which is made of tuples? Is it actually several indexes? Like first an index on the number of elements of the tuples, then on element one of the tuple, etc... or does it take the whole tuple for example as a string before adding an index?
Thanks,
Alex |
|
|
| Back to top |
|
| francesco |
Posted: Mon Mar 31, 2008 11:03 am |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
Quote: But if my table is of type "set", the first column will be indexed automatically?
The first column is by default the key, used for the hash. For it to be used, all variables have to be set.
Quote: If that column is full of tuples such as:
{a,b,c}
{a,x,d}
{b,c,f}
etc...
then I search for {a,b,'–'}
will the index be used.
No, it will not, as you are matching on one of the values.
Quote: My problem is really: how does mnesia index a column which is made of tuples? Is it actually several indexes? Like first an index on the number of elements of the tuples, then on element one of the tuple, etc... or does it take the whole tuple for example as a string before adding an index?
If your element is a tuple, it will not index every element. Setting wild cards in a structure in the index will result every element being compared.
Regards,
Francesco
--
http://www.erlang-consulting.com |
|
|
| Back to top |
|
| alamb |
Posted: Mon Mar 31, 2008 11:56 am |
|
|
|
User
Joined: 26 Aug 2007
Posts: 55
Location: Geneva / Switzerland
|
Ok, so it means that if my key column is made of tuples such as:
{A,B,C}
and I often will search for {A, something else...}
I ought to add a column to my table containing A (a duplicat of first tuple element) and index on that column. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
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 can attach files in this forum You can download files in this forum
|
|
|