Faster queries with index on JSONB columns in Postgres

Поделиться
HTML-код
  • Опубликовано: 3 фев 2025

Комментарии • 19

  • @dshukertjr
    @dshukertjr 8 месяцев назад +4

    With the JSON query video, pg_jsonschema video, and this indexing JSONB video, learn JSON in Postgres series is concluded. Let us know in the comments below what other Postgres topics you would you like us to cover in future videos 👇

  • @JonMeyers
    @JonMeyers 8 месяцев назад +6

    This is sick! Makes working with json so much more performant! 🙌

    • @dshukertjr
      @dshukertjr 8 месяцев назад +1

      Yeah, I genuenly thought indexing JSONB columns was going to be more complex, but it turns out Postgres handles a lot of the complexity for us!

  • @bepamungkas
    @bepamungkas 7 месяцев назад

    to add some tips:
    if the data is stored as jsonb, and the structure is standardized (e.g with some kind of schema), and we only do positive lookup; we can forego "key exists" operators for smaller index size and faster index lookup using jsonb_path_ops. With default (jsonb_ops) indexing, the index will contain both key and value to allows keys lookup. Without those operators, postgres will only index the value of each key/ path.
    One gotcha of above index type is when you do negative lookup (e.g filtering for empty field) the query basically do full index scan to get list of unindexed rows.

  • @nicolascalderon9366
    @nicolascalderon9366 8 месяцев назад +1

    Awesome, thanks! that is exactly what we need

  • @deefdragon
    @deefdragon 3 месяца назад

    TY for the explination on indexing further into the json object. I've looked at a number of tutorials/documentation around indexing jsonb, and have never seen anything actually go into that particular topic. It always stops at indexing root level keys.

  • @peterchaploutskiy2555
    @peterchaploutskiy2555 4 месяца назад

    This is awesome! Thank you much for sharing. Any performance issues with indexing json you can think of?

  • @sayyidj6406
    @sayyidj6406 8 месяцев назад +1

    Hey @dshukertjr, hope you're having a great afternoon! こんにちは!
    May I ask you a question? I've got some data that's a bit repetitive, stored as a string. It's basically JSON, but I don't need to directly search through it because another column handles that. So, I'm thinking of compressing and encrypting it to save space and keep it secure. Once I do that, it turns into a bunch of bytes. Usually, I'd save it as a base64 encoded string, but I'm wondering if it's possible - or even a good idea - to save it as bits instead. What do you think?

    • @dshukertjr
      @dshukertjr 8 месяцев назад

      It sounds like with what you are currently doing, you are able to satisfy your technical requirements, and saving space in your DB, so why not?

  • @beertocode
    @beertocode 8 месяцев назад +1

    This is great!
    I wonder does an index on jsonb fields take a lot of space?

    • @dshukertjr
      @dshukertjr 8 месяцев назад

      Great question, and generally yes. That is why if you only query with certain subfields, you should create indexes for them rather than creating one for all the columns.

  • @mikejohneviota9293
    @mikejohneviota9293 8 месяцев назад +1

    i have tried it and it's freaking awsome than mongodb 😂

  • @35b7aishwarya9
    @35b7aishwarya9 5 месяцев назад

    How to run the query?

  • @nicolascalderon9366
    @nicolascalderon9366 7 месяцев назад

    One question, I noticed the gin index worked when you did the query like this "... where metadata @>", but not when you did it on this way "... where metadata->>". So my question is, what of the two options are executed by supabaseClient? for example doing a query like this "supabase.ilike(
    `metadata->>${search.field}`,
    `%${searchValue}%`
    )"... in order to know which of the two indexing approaches I should use

  • @alinagy
    @alinagy 8 месяцев назад +1

    Just starting to use Supabase in a client project and it’s too good

  • @sumitpurohit8849
    @sumitpurohit8849 8 месяцев назад +1

    Please create a video on hybrid search and it's indexing.

    • @Supabase
      @Supabase  8 месяцев назад

      Thanks for the suggestion! Just to be sure, hybrid search as in semantic search + full text search? supabase.com/docs/guides/ai/hybrid-search

  • @davemarko9480
    @davemarko9480 8 месяцев назад +2

    First here 😊

    • @dshukertjr
      @dshukertjr 8 месяцев назад

      You beat me to it 😂