Skip to content

First pass (incomplete) of "rich" JSONB indexing docs #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

freshtonic
Copy link
Contributor

@freshtonic freshtonic commented Oct 14, 2024

I'm winging it a bit here.

  1. I landed on rich_jsonb as the name of the new index type (had to pick something!)
  2. I circumvented the bike-shedding naming EQL function equivalents for nameless Postgres operators by making the operator an argument to a generic cs_binop_v1 function:

cs_binop_v1(left_arg, '->', right_arg)

I'm fairly certain this can be made to work in PGPLSQL

@freshtonic freshtonic changed the title First pass (incomplete) as "rich" JSONB indexing First pass (incomplete) of "rich" JSONB indexing docs Oct 14, 2024

Extracts n'th element of JSON array, as text.

`cs_binop_v1(jsonb, '->>', text)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would cs_binop_v1 handle the different return types between operators (jsonb, text, or bool)? Can Pl/pgSQL handle multiple return types for a single function?

Copy link
Contributor Author

@freshtonic freshtonic Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CDThomas that is a very good question!

Postgres does support limited polymorphism via anyelement, anyarray, anynonarray, anyenum, or anyrange.

The way it works is that if you have a function foo(anyelement) -> anyelement then anyelement becomes the same type everywhere it appears.

So foo(text) -> text would be allowed, but foo(text) -> integer would not.

I think that is sufficient to express all of the variations required by cs_binop_v1 but I will need to double check.


Extracts JSON object field with the given key, as text.

`cs_binop_v1(jsonb, '<', jsonb)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would cs_binop_v1 determine which index to use for a particular operator? For example, if it needed to choose between regular ORE and rich JSON's ORE, how would that work?

Or is cs_binop_v1 only intended to be used with rich JSON? In that case could we add the index name to the func name (something like cs_rich_jsonb_binop_v1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CDThomas given that a function can be polymorphic - I think that means cs_binop_v1 will have multiple definitions. So if both left and right args are the encrypted jsonb type, then the ORE index defined for that particular type will be used, for example.

Co-authored-by: Lindsay Holmwood <lindsay@holmwood.id.au>
@auxesis
Copy link
Contributor

auxesis commented Oct 17, 2024

Closing in lieu of #14.

@auxesis auxesis closed this Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants