4 ms·
Just a nitpick, but I believe it would be more efficient to create index as the last step here.
by takeda 10y ago
Just a nitpick, but I believe it would be more efficient to create index as the last step here.
- brightball 10y agoNot necessarily. If the table is already fairly large you'd have to use Postgres CREATE INDEX CONCURRENTLY to avoid locking the table while it sorted out the index. The only downside is that you have very little control of the process. If you already have the data available in a JSONB column you can create the column, create the index and then set your app code to look to the JSON data if the column is null during transition while a background job goes through and populates rows either individually or in smaller batches to avoid disrupting user experience.
- Mister_Snuggles 10y agoThis was just an example of what you can do. I'd do this sort of thing while developing an application, but if it were in Production I'd take a much closer look at how the steps in my change would impact the running application.