0

I wonder about search in Firebase database and try to understand if this is a good approche or how to change it. the "andromeda-planetgroup.123-local1001-1234548" below is an immutable id string and I would like to perform searches on the list containing them. What I think is a problem is that if this list of "PROPERTY" have hundred miljons entries and performing a range query.

If I create a range query like this:

ref.startAt("andromeda-planetgroup.123-local1001-1234548")
   .endAt("andromeda-planetgroup.123-local1001-1234552~")

What can I expect in terms of speed if the list have miljons of entries. I understand that if the range query return miljons if entries it would be slow because of the data size, but lets say I want to return 10 entries in this range query?

"PROPERTY" : {

      "andromeda-planetgroup.123-local1001-1234548" : {
        "id" : "-KgeKdD94HomnhGHd4WC"
      },
      "andromeda-planetgroup.123-local1001-1234549" : {
        "id" : "-KgeKh28NIFusAfTU_gS"
      },
      "andromeda-planetgroup.123-local1001-1234550" : {
        "id" : "-KgeKmZsuB92uIJqQWq9"
      },
      "andromeda-planetgroup.123-local1001-1234551" : {
        "id" : "-KgeLI417b3E--MAoLY1"
      },
      "andromeda-planetgroup.123-local1001-1234552" : {
        "id" : "-KgeM5K4V1Ytcw4_gGU-"
        ...
        ...
        ...
        ...
      "milkyway-planetgroup.4423-local901-836743" : {
        "id" : "-KgeLd5JH-ffdeOOY1"
      },
      "milkyway-planetgroup.4423-local901-836744" : {
        "id" : "-Kg39e7Gjsa&4_Ksu-"
  }

If this is a bad ide how can I make this fly better?

Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
  • You are using a real time database, right? – AlwaysConfused Apr 07 '17 at 09:51
  • Yes I know but I still learn this. Do you mean my range query will always be real time, minus the time it takes to download the data? – Tord Larsen Apr 07 '17 at 10:10
  • As soon as you are avoiding nesting tables it should be fine. More: [here](https://firebase.google.com/docs/database/android/structure-data#best_practices_for_data_structure) – AlwaysConfused Apr 07 '17 at 10:23
  • @StuckBetweenTrees There are no tables in Firebase! Also, nesting isn't necessarily bad but it depends on the use case. In this use case it could be used to reduce dataset size. For example, note that the OP is looking for *very specific* child nodes keys. In the post, nodes start with *andromeda-planetgroup.123-local1001* and another *milkyway-planetgroup.4423-local901*. There's no reason (based on the data provided) those could not be two separate nodes, and actually nesting the data since the keys are so specific i.e. andromeda/planetgroup/123/local1001. Query for 1234548... 1234552. – Jay Apr 07 '17 at 21:37
  • How fast is very dependent on internet connection actual number of nodes, complexity etc. It appears you could reduce your data set size considerably with a better structure (as mentioned above) – Jay Apr 07 '17 at 21:39
  • Your probably right about the structure. @StuckBetweenTrees think that my setup is "fine" and you say "actual number of nodes" , the Internet speed has nothing to do with this. As you see in my databas there are no nesting in "PROPERTY" . - hundred miljons entries and do a query is that sane :) – Tord Larsen Apr 08 '17 at 17:21

0 Answers0