Skip to content
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

[Proposal]: unsafe change_column_null default value #36

Closed
twonegatives opened this issue Feb 10, 2018 · 3 comments
Closed

[Proposal]: unsafe change_column_null default value #36

twonegatives opened this issue Feb 10, 2018 · 3 comments

Comments

@twonegatives
Copy link
Contributor

twonegatives commented Feb 10, 2018

Rails change_column_null method accepts four arguments, with the fourth one replacing existing NULLs with some other value. Looks kinda useful feature although the implementation of such a replacement might be pretty dangerous on large tables (postgres, mysql):

UPDATE #{quote_table_name(table_name)}
SET #{quote_column_name(column_name)}=#{quote_default_expression(default, column)}
WHERE #{quote_column_name(column_name)} IS NULL

What we're doing here is a WHERE query on a table which might be lacking of needed index on column_name and UPDATE for (potentially) millions of records at once.
A little more safe way might be to require user to make this UPDATE in batches manually before firing change_column_null up.
WDYT?

@ankane
Copy link
Owner

ankane commented Feb 10, 2018

Hey @twonegatives, makes sense to me. Do you want to try adding it?

@twonegatives
Copy link
Contributor Author

hey @ankane sure, I'll give it a try.

@ankane
Copy link
Owner

ankane commented Feb 18, 2018

Merged!!

@ankane ankane closed this as completed Feb 18, 2018
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

No branches or pull requests

2 participants