I have a table payment with a jsonb column application. It contains payments and the total amount for one or more tours. For example, a parent can pay 1000 $ for all his family, e.g. 4 children and his wife. Then one row in payment contains 6 records in the jsonb field application, describing the tour and the customer.
[
{
"tour_id":
{
"id":"d61802ff-3eec-4a72-97ca-832f51b96bf0","name":"Paris 2018"
},
"amount":"500.00",
"customer_id":
{
"id":"f492b26d-d260-4bcb-8e96-6532fdf38665",
"name":"OBAMA John"
},
"id":"5cd8338c-15c2-48c5-b305-9e172bb33a9a"
},
{
"tour_id":
{
"id":"a52d38d4-9bfb-4ffa-1122-e536f04b0c60","name":"London 2018"
},
"amount":"500.00",
"customer_id":
{
"id":"f492b26d-d260-4bcb-8e96-6532fdf38665",
"name":"OBAMA John"
},
"id":"5cd8338c-15c2-48c5-b305-9e172bb33a9a"
},
]
My id is unique in all the postgres database, I'm using UUID v4. Which is the best way to index this id? Really the name is redundant here, because I have a table for customers and tours, and I could just record the id:
[
{
"tour_id":"d61802ff-3eec-4a72-97ca-832f51b96bf0",
"amount":"500.00",
"customer_id":"f492b26d-d260-4bcb-8e96-6532fdf38665",
"id":"5cd8338c-15c2-48c5-b305-9e172bb33a9a"
},
(...more elements)
But I'd like to get advise on the best indexing strategy (or alternative solutions).
idyou want to index exactly. There are several different fields of that name ... And please always declare your Postgres version. – Erwin Brandstetter Dec 18 '17 at 05:08