realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.28k stars 2.14k forks source link

distinct query in Realm database #1103

Closed alexwillrock closed 6 years ago

alexwillrock commented 9 years ago

hello, realm is super fast db but very necessary distinct query from database e.g. schedules = Schedules.objectsWhere("areas.id = '(idAreas)' distict")

bartleby commented 7 years ago

+100500

kunalsood commented 7 years ago

We have sortedResultsUsingKeyPath:, could we possibly have distinctedResultsUsingKeyPath: ?

PS: Without having looked it up, I'm not sure if 'distincted' is the correct past-participle for 'distinct' (English isn't my first language).

jpsim commented 7 years ago

Sorted isn't used as a verb in the past tense but rather as an adjective: "the results are sorted".

So the equivalent naming for distinct would be distinctResultsUsingKeyPath:: "the results are distinct".

But I think the current implementation doesn't support nested key paths, so they can only be applied to direct properties of an object, so we might not call it a "key path" either, simply just "property".

tgoyne commented 7 years ago

I think the objectstore part doesn't support nested keypaths, but that would be pretty easy to fix. The core distinct logic does support all the same things as sorting.

shuhaodo commented 7 years ago

+1

MihaelIsaev commented 7 years ago

Please implement it at last

FreudGit commented 7 years ago

Hi Any status? 220000 rows. Query are fast, but get distinct are very slow.

chml commented 7 years ago

Any updates? This issue open at 2014; and seems the "Core" already finished the distinct API.

ivedeneev commented 7 years ago

I need it so badly, pls implement it ;)

0xxxD commented 7 years ago

@FreudGit what's your meaning?? so, Is there any indirectly way to implement it ?

jpsim commented 7 years ago

@0xdatou you can perform a distinct operation in memory by copying data out of a Realm: https://github.com/realm/realm-cocoa/issues/1103#issuecomment-125381124

This issue is tracking adding built-in support in Realm itself, with auto-updating Results consistent with all our other querying capabilities.

krummler commented 7 years ago

The table I want to use distinct on has about 100.000 objects, also to be able to make sections in the table that displays the data. Post-query filtering/mapping to figure out the section count and titles is a hit on performance, because the user can filter the data using a search bar on the fly. Currently that means it'll need to re-map the sections and go over those 100.000 records with every keystroke.

Is there any other way to keep this performing well without the use of distinct? Or can we expect this feature soon?

qubblr commented 7 years ago

@krummler you might want to checkout this pull request.

krummler commented 6 years ago

@qubblr Thanks, sounds great, but so far this hasn't been implemented/merged? Is there any alternative or temporary solution?

Zhuinden commented 6 years ago

With Realm-Core 3.0+ the behavior seems well-determined enough so that this could be made available in Cocoa, just like in Realm-Java

FreudGit commented 6 years ago

@jpsim Will this be implemented in Cocoa version? :)

bdash commented 6 years ago

Fixed by #5467.

michael-mckenna commented 6 years ago

When will the next release be in which this is included?

stuartro commented 6 years ago

» When will the next release be in which this is included? +1

bdash commented 6 years ago

https://github.com/realm/realm-cocoa/releases/tag/v3.1.0