Faster queries with index on JSONB columns in Postgres

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ม.ค. 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.

  • @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.

  • @nicolascalderon9366
    @nicolascalderon9366 8 หลายเดือนก่อน +1

    Awesome, thanks! that is exactly what we need

  • @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?

  • @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

  • @35b7aishwarya9
    @35b7aishwarya9 5 หลายเดือนก่อน

    How to run the query?

  • @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.

  • @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

  • @mikejohneviota9293
    @mikejohneviota9293 8 หลายเดือนก่อน +1

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

  • @alinagy
    @alinagy 8 หลายเดือนก่อน +1

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

  • @davemarko9480
    @davemarko9480 8 หลายเดือนก่อน +2

    First here 😊

    • @dshukertjr
      @dshukertjr 8 หลายเดือนก่อน

      You beat me to it 😂