1

In the Google Datastore documentation it says to avoid indexing monotonically increasing fields because they can lead to hotspots: link

What about indexing boolean fields? Can those also lead to tablet hotspots since there are only two possible values? Is it safe to index boolean fields? What if they are a part of a composite index?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Micro
  • 10,303
  • 14
  • 82
  • 120

1 Answers1

1

There is nothing specified in the documentation regarding the use of boolean values. The only problem that can occur is when you are using those monotonically increasing fields. Why? Because that approach doesn't scale and might create hotspots at some point in time. So regarding boolean values, yes, it's safe to create indexes. There is nothing you should worry about.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I know it doesn't say anything in the documentation about indexing booleans - and I wanted to ask just for that reason so I can confirm. As I understand it, the reason you don't want to monotonically increase fields is that the tablet cannot split into different operations. With booleans, you only have two possible values. Therefore, the tablet can only split into two possible options - thus leading to hot spots. At least this is my understanding, I am looking for clarification on the subject and if indexing booleans at scale works. – Micro Nov 23 '21 at 07:06
  • You might also check this out. Boolean values cannot create hot spots on a larger scale. – Alex Mamo Nov 23 '21 at 07:25
  • Where does it say "Boolean values cannot create hot spots on a larger scale." - or how do you know for sure? – Micro Nov 24 '21 at 07:10
  • I forgot to link the [this](https://stackoverflow.com/questions/51024150/firestore-generated-key-versus-custom-key-in-a-collection) earlier. So I cannot see any reason why it may create hot spots. If you aren't still sure about that, you can ask the Firebase team directly. But I have apps that are running at a larger scale and have no problem at all when using boolean values. – Alex Mamo Nov 24 '21 at 07:22
  • Is there everything alright now? – Alex Mamo Nov 25 '21 at 07:30
  • I suppose, I don't see anything in that link about boolean values not creating hot spots though. – Micro Nov 26 '21 at 08:03
  • That answer provides information about the **only** situation in which you can create hot spots. Have you asked the Firebase team about that? Did they answer? Is their answer similar to mine? – Alex Mamo Nov 26 '21 at 08:06
  • You can reach [support](https://firebase.google.com/support). Ask them this question, and keep me posted, ok? You can also link this question if you want. Looking forward to seeing your feedback. – Alex Mamo Nov 27 '21 at 10:06
  • What if instead of boolean values, I have an enum with two, three or four values? If I index them, is it possible I would run into hotspots? Or is having hotspots specifically in reference to anything monotonically increasing as it is being written to the datastore? – Micro Dec 19 '21 at 20:58
  • An enum is not a [supported data type](https://firebase.google.com/docs/firestore/manage-data/data-types). And yes, it's referring to anything monotonically increasing that is written in Firestore. – Alex Mamo Dec 20 '21 at 10:30
  • By enum I mean a defined set of string values for example. Let's say there are only five possible values. I was concerned that since there are not many possible values, tablets may get hotspots since they could only really split into five possibilities - instead of many random ones. – Micro Dec 24 '21 at 04:23
  • I think this post explains what you have been saying? https://stackoverflow.com/a/42380848/3075340 – Micro Dec 26 '21 at 01:32
  • Yes. Dan is part of the Firebase team. – Alex Mamo Dec 26 '21 at 09:25