Window function 😊. CTE with window function 😮. Hierarchical recursive CTE 🤯. Recommended all the way. Can’t wait to see the rest of the videos!M Wildan Zulfikar
Shorten dev cycles with branching and zero-downtime schema migrations.
One last thing I want to cover here before we really get going is an index naming strategy or pattern. Index names are not global to a database, but they are global to a schema.
If you have an index on email and you name it email and you have another index on email and a different table, you're gonna be host. I want to show you a little bit of an index naming strategy and then at the end we'll talk about why I am not gonna do that in these videos. If I ran create index and I just named it foo on, we'll just call it users(id);. I think we have, what do we have? We have addresses still lying around and I'm gonna try to name that one foo as well.
You cannot create two of the exact same index name in the same schema. We're in the public schema here and you just can't do that. A very common pattern here, let me get, let me get down here and let's just do this. A very common pattern here is to say {tablename}_{column} or {column(s)}, you know, depending, and then some sort of type. You could have just an {index}, you could have a {check}, you could have a {unique}, you could do something like that. In reality, this index would be better names users_id.
Right here I'm just creating a regular index. You'd probably do it on something like email where you have a regular index there and you say, users_email_idx. You can come up with whatever pattern you want. I do think prefixing with the table name is probably a good idea 'cause that does add a little layer of separation between all of your separate indexes. It's up to you. It's up to your team. It might even be up to your framework. I know that a lot of these frameworks with ORMs that generate migrations, create their own index names. That's great. You're almost guaranteed that they're gonna be unique. That's a good thing. I'm not gonna spend all the time typing these out in the next videos.
You should, in production, have nice clean index names for the sake of brevity and to keep things moving quickly. I'm just gonna type out some short index names, but don't do that in production.