-
Notifications
You must be signed in to change notification settings - Fork 53
feat: upgrade to Rails 8.1 #386
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
base: master
Are you sure you want to change the base?
Conversation
cb4869f to
d8e3e07
Compare
d8e3e07 to
f9b1c88
Compare
ab74ce6 to
dc9a906
Compare
| # | ||
| # @see: https://github.com/rails/rails/blob/8695b028261bdd244e254993255c6641bdbc17a5/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L829 | ||
| # OVERRIDE(v8.1.1): | ||
| # - comment is retrieved differently than PG for performance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
col_description is the method used to retrieve the comment in PG. @rafiss is still true that this is slower than using information_schema.columns ?
| ARRAY( | ||
| SELECT a.attname | ||
| FROM pg_attribute a | ||
| WHERE a.attrelid = d.indexrelid AND a.attishidden | ||
| ) AS hidden_columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafiss
I added this bit. I'm really unsure about performances, any better idea would be appreciated.
The goal is to remove hidden columns from the columns above. My main issue was that we are using pg_get_indexdef to retrieve the columns. I don't know edge cases so I was not eager to use another method, but if we were not to use it I feel like we could easily have a faster and simpler approach.
My second question is: do you have a simple routine to benchmark two slightly different columns in CRDB, and pitfalls I should avoid?
EDIT: one of the ideas I had:
ARRAY(
SELECT a.attname
FROM pg_attribute a
JOIN unnest(d.indkey) AS k(attnum)
ON a.attrelid = d.indrelid AND a.attnum = k.attnum
AND NOT a.attishidden
) AS visible_columnsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using pg_get_indexdef should actually be fine. The CRDB implementation is a function with a SQL body (https://github.com/cockroachdb/cockroach/blob/08676709fc2c9ee4f9cdbfeb4601b71b273773d8/pkg/sql/sem/builtins/pg_builtins.go#L862), so what that means in practice is that all the SQL gets inlined into the query that's using the function.
do you have a simple routine to benchmark two slightly different columns in CRDB, and pitfalls I should avoid?
Hm, nothing is available externally, but we do have an internal benchmark suite in our codebase: https://github.com/cockroachdb/cockroach/blob/master/pkg/bench/rttanalysis/orm_queries_bench_test.go
I think that's overkill for what you're doing. If you are able to run locally, I think the best way to do a basic comparison is to create ~100 tables and then try executing the different queries to see what's faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
pg_get_indexdefshould actually be fine.
I actually wanted not to use it, to have better perf. Although from what I can see now, I doesn't seem trivial to replace it and improve perf
4b74df4 to
d477fd6
Compare
|
Any timeline when this will get merged and released? |
aebefbe to
f6aa445
Compare
| false | ||
| end | ||
|
|
||
| def supports_close_prepared? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed true by testing in CRDB 25.2, but I could not see any documentation on the CRDB side.
Here's the pg backend function as a reference : https://github.com/postgres/postgres/blob/master/src/backend/commands/prepare.c#L519
And libpq interface is PqMsg_Close with the Statement type ('C', 'S'). In the cockroach codebase I could find ClientMsgClose that maps to PqMsg_Close, but I did not find handling of close_prepared, yet it works... Any clue on that feature @rafiss ?
f5639cd to
d3c0e76
Compare
- update some outdated overrides. - update override comments to know when was the last override. - remove the `#column_names_from_column_numbers` method that was generating N+1 queries. - update related methods. See: - rails/rails@249c367 - rails/rails@4e0546c - rails/rails@c93d1b0
This would silently fail in the test `test_bulk_insert_with_a_multi_statement_query_raises_an_exception_when_any_insert_fails`. Removing some foreign keys and thus failing afterwards in the test suite. Moreover, the `#disable_referential_integrity` method is unfortunately public, so we need it to be robust.
d3c0e76 to
570a0af
Compare
| # prefixes and suffixes. The good thing is: if this happens, tests will crash | ||
| # hard, no way we miss it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the test retry logic was actually proving me wrong. But now that it is removed, we are fine (see later commit)
- remove `debugging?` utility - use variables for `autocommit_before_ddl`: > This is the default intended approach, as it will > quote value if needed. - remove spatial_column_info.rb and its calls as it is never used. See #391 to maybe include it back, properly. - fix geos-config file fetching - refactor for loop into any? - unexclude working tests - reset `test_create_fixtures` to the original, it works. And our version would corrupt foreign keys
If `#disable_referential_integrity` is ran within a transaction, we may be able to still run the user's code. Otherwise we warn the user why it failed.
Since CockroachDB does not support DDL transactions, we adapt the test.
This fixes a bug where our `TestRetryHelper` logic combined with `reset_fixtures` trying to reset a table without foreign keys from another table. It would first crash, removing the foreign key constraint (due to how we handle `disable_referential_integrity`). And then pass, since the foreign key constraint is gone. But we need that constraint in later tests.
This is WIP and there is likely more to do. Hence the reference #390. Fixes the flaky test `PostGISTest#test_spatial_factory_attrs_parsing`
Tests that should fail would instead corrupt the database state, causing subsequent tests to fail. This is of course related to the unfortunate way we disable referential integrity. If we see tests failing again with `InvalidForeignKey` errors, it will be a good time to reopen [cockroach#71496] [cockroach#71496]: cockroachdb/cockroach#71496
570a0af to
1770c41
Compare
|
@rafiss the PR is finally ready for review. It is packed with various intentions, all separated in various commits (except two small exceptions that I was too lazy to fixup). I strongly suggest review commit by commit rather than the whole PR at once. Have a good read :) About flaky tests, I've ran many times the This PR also fixes some past bugs I found along the way, we might want to cherry-pick some of the commits later on. If that's fine with you, I'd rather rebase and merge, not squash nor merge. |
In our adapter, we rely on the sql type string for spatial details to properly map the type to the correct ActiveRecord type. It was not shared.
96ecf5b to
4fc3e5c
Compare
4fc3e5c to
df34946
Compare
Minimal set of test reproduction:
```sh
COCKROACH_SKIP_LOAD_SCHEMA=1 SEED=13092 bundle exec rake test TESTOPTS="--name='/\A("\
"test_concurrent_insert_with_processes"\
"|test_uniqueness_validations_work_when_using_old_encryption_schemes"\
"|test_fixtures_get_encrypted_automatically"\
"|test_ciphertext_for_returns_the_ciphertext_of_a_value_when_the_record_is_new)\z/'"
```
It is important NOT TO run `ActiveRecord::Base.reset_column_information`.
Some tests are eagerly loading information to prevent side effects [^1].
We could run `Avenger.reset_column_information` but we actually do not
need it here.
[^1]: See https://github.com/rails/rails/blob/v8.1.1/activerecord/test/cases/encryption/helper.rb#L115-L120
TODOs:
#foreign_keysworks if t2 doesn't belong to the same namespace as t1