Index on Realm Object is compound index of properties or distinct indexes for each property
I use 'RealmSwift' to create a Realm Database in my app. Consider a subclass of 'Object' that I use to be 'ClassA'. The 'ClassA' and its properties can be simply described as below(avoiding actual code for brevity):
ClassA: Object
-prop1
-prop2
-prop3
-prop4
-prop5
-prop6
I want to have to two indexes on the 'ClassA'. To be specific I want each index to be a compound index. Lets call the two Indexes as 'Index1' & 'Index2'. And by compound I mean an Index can have multiple properties. So lets define the two Indexes as below:
Index1: prop1, prop2, prop6
Index2: prop3, prop4, prop5
I need these compound indexes, in order to have faster fetches, in case I have the values for those particular properties. This is of critical importance for my application.
Providing indexes on Real Objects using 'RealmSwift' is done by overriding Object.indexedProperties() by returning an array of String containing the names of properties we want to index.
I want to know if this will create a separate index for each property or a single compound index for all the properties.
swift realm
add a comment |
I use 'RealmSwift' to create a Realm Database in my app. Consider a subclass of 'Object' that I use to be 'ClassA'. The 'ClassA' and its properties can be simply described as below(avoiding actual code for brevity):
ClassA: Object
-prop1
-prop2
-prop3
-prop4
-prop5
-prop6
I want to have to two indexes on the 'ClassA'. To be specific I want each index to be a compound index. Lets call the two Indexes as 'Index1' & 'Index2'. And by compound I mean an Index can have multiple properties. So lets define the two Indexes as below:
Index1: prop1, prop2, prop6
Index2: prop3, prop4, prop5
I need these compound indexes, in order to have faster fetches, in case I have the values for those particular properties. This is of critical importance for my application.
Providing indexes on Real Objects using 'RealmSwift' is done by overriding Object.indexedProperties() by returning an array of String containing the names of properties we want to index.
I want to know if this will create a separate index for each property or a single compound index for all the properties.
swift realm
add a comment |
I use 'RealmSwift' to create a Realm Database in my app. Consider a subclass of 'Object' that I use to be 'ClassA'. The 'ClassA' and its properties can be simply described as below(avoiding actual code for brevity):
ClassA: Object
-prop1
-prop2
-prop3
-prop4
-prop5
-prop6
I want to have to two indexes on the 'ClassA'. To be specific I want each index to be a compound index. Lets call the two Indexes as 'Index1' & 'Index2'. And by compound I mean an Index can have multiple properties. So lets define the two Indexes as below:
Index1: prop1, prop2, prop6
Index2: prop3, prop4, prop5
I need these compound indexes, in order to have faster fetches, in case I have the values for those particular properties. This is of critical importance for my application.
Providing indexes on Real Objects using 'RealmSwift' is done by overriding Object.indexedProperties() by returning an array of String containing the names of properties we want to index.
I want to know if this will create a separate index for each property or a single compound index for all the properties.
swift realm
I use 'RealmSwift' to create a Realm Database in my app. Consider a subclass of 'Object' that I use to be 'ClassA'. The 'ClassA' and its properties can be simply described as below(avoiding actual code for brevity):
ClassA: Object
-prop1
-prop2
-prop3
-prop4
-prop5
-prop6
I want to have to two indexes on the 'ClassA'. To be specific I want each index to be a compound index. Lets call the two Indexes as 'Index1' & 'Index2'. And by compound I mean an Index can have multiple properties. So lets define the two Indexes as below:
Index1: prop1, prop2, prop6
Index2: prop3, prop4, prop5
I need these compound indexes, in order to have faster fetches, in case I have the values for those particular properties. This is of critical importance for my application.
Providing indexes on Real Objects using 'RealmSwift' is done by overriding Object.indexedProperties() by returning an array of String containing the names of properties we want to index.
I want to know if this will create a separate index for each property or a single compound index for all the properties.
swift realm
swift realm
edited Jan 2 at 6:36
Rohan Bhale
asked Jan 2 at 5:56


Rohan BhaleRohan Bhale
814615
814615
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
AS I understand the documentation Object.indexedProperties() will create an index for each property that you return, but no compound index.
What you can do to get around this is to create new properties on your objects which combine the properties you want to use for your compound index.
Example:
Create a new property indexProp126 by concatenating prop1, prop2 and prop6 to a String (just as an example, there are probably more efficient ways like hashes etc. depending on what the type and content of those properties really is) and use this as the index then.
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001862%2findex-on-realm-object-is-compound-index-of-properties-or-distinct-indexes-for-ea%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
AS I understand the documentation Object.indexedProperties() will create an index for each property that you return, but no compound index.
What you can do to get around this is to create new properties on your objects which combine the properties you want to use for your compound index.
Example:
Create a new property indexProp126 by concatenating prop1, prop2 and prop6 to a String (just as an example, there are probably more efficient ways like hashes etc. depending on what the type and content of those properties really is) and use this as the index then.
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
add a comment |
AS I understand the documentation Object.indexedProperties() will create an index for each property that you return, but no compound index.
What you can do to get around this is to create new properties on your objects which combine the properties you want to use for your compound index.
Example:
Create a new property indexProp126 by concatenating prop1, prop2 and prop6 to a String (just as an example, there are probably more efficient ways like hashes etc. depending on what the type and content of those properties really is) and use this as the index then.
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
add a comment |
AS I understand the documentation Object.indexedProperties() will create an index for each property that you return, but no compound index.
What you can do to get around this is to create new properties on your objects which combine the properties you want to use for your compound index.
Example:
Create a new property indexProp126 by concatenating prop1, prop2 and prop6 to a String (just as an example, there are probably more efficient ways like hashes etc. depending on what the type and content of those properties really is) and use this as the index then.
AS I understand the documentation Object.indexedProperties() will create an index for each property that you return, but no compound index.
What you can do to get around this is to create new properties on your objects which combine the properties you want to use for your compound index.
Example:
Create a new property indexProp126 by concatenating prop1, prop2 and prop6 to a String (just as an example, there are probably more efficient ways like hashes etc. depending on what the type and content of those properties really is) and use this as the index then.
answered Jan 2 at 8:33


Robin BorkRobin Bork
1326
1326
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
add a comment |
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
This is similar to solving the compound primary key problem for realm. For indexes are you sure if we return 3 properties, then three different indexes are created. I ask you this as I want multiple compound indexes. So If I want two compound indexes I create two new indexProperties as you say. But for this we need to be sure if the properties we return from Object.indexedProperties() result in one index per property.
– Rohan Bhale
Jan 2 at 9:37
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
I am pretty sure. In indexProperties() you return an array of property names. So that would mean you can either: 1) create multiple indices (one for each property) 2) one compound index I think 2) is very unlikely since that would limit you to one index per class, which would not make much sense in my opinion, especially since you can solve this with 1) like in my suggestion. Also I am pretty sure the documentation would be a lot more specific if this would create a composite index.
– Robin Bork
Jan 2 at 10:00
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
In SQLite there is EXPLAIN QUERY PLAN which basically tells if and which index will be used for Querying. Is there something similar to verify this in Realm?
– Rohan Bhale
Jan 2 at 10:31
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
I don't know, but I have not seen anything like that yet.
– Robin Bork
Jan 2 at 10:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001862%2findex-on-realm-object-is-compound-index-of-properties-or-distinct-indexes-for-ea%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown