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

PostgreSQL < 9.3 does not respect a new search_path for prepared statements #449

Merged

Conversation

meganemura
Copy link
Collaborator

@mikecmpbll

I finally straighten out the failing spec with PostgreSQL + Rails 5.0 + Apartment that I described in #448.

The issue is caused by older PostgreSQL version (< 9.3). That version of PostgreSQL behaves a supprising behavior (as official document described in E.18.2.2. Other) for the cached statements.

Force cached plans to be replanned if the search_path changes (Tom Lane)
Previously, cached plans already generated in the current session were not redone if the query was re-executed with a new search_path setting, resulting in surprising behavior.

And the PREPARE statement documentation is here: https://www.postgresql.org/docs/9.3/static/sql-prepare.html

Remarkable point:

Also, if the value of search_path changes from one use to the next, the statement will be re-parsed using the new search_path. (This latter behavior is new as of PostgreSQL 9.3.)

So, clearing the cache of prepared statements for the older version of PostgreSQL is to solve the problem about the tests.

You can confirm what the statements are cached in the specs by adding the lines below.

p Apartment.connection.instance_variable_get(:@statements)

The query for the ar_internal_metadata are cached and executed for a removed schema under PostgreSQL 9.1 (default version for the Travis-CI), so the test is failed with PG::UndefinedTable: ERROR: relation "ar_internal_metadata" does not exist at character 39.


And I fixed some rarely (occasionally?) failing spec.

capybara (the development dependency) depends on xpath,
and xpath depends on nokogiri.
@mikecmpbll
Copy link
Collaborator

love love love this ❤️. thanks so much for doing the digging.

any ideas on the jruby fails?

@meganemura
Copy link
Collaborator Author

any ideas on the jruby fails?

No 😩 I'm not familiar with JRuby.
I started setup a docker file for jruby envs to reproduce and dig it the failure.

Exclude Rails (>= 5.0) with JRuby, because of
the activerecord-jdbc-adapter is unstable for Rails 5.x.
@meganemura
Copy link
Collaborator Author

meganemura commented Jul 5, 2017

I figured out 🎉
Failures in 4.2 and 5.0 are the JRuby issue. Here is the related issue at rails/rails.
rails/rails#28342
Newer rails must be run by JRuby > 9.1.9.0.

And the another problem is activerecord-jdbc-adapter, not apartment.
jruby/activerecord-jdbc-adapter#700
I have tested against Rails 5.0 with activerecord-jdbc-adapter (rails-5 branch), but it's failed.
activerecord-jdbc-adapter for rails 5.0 is unstable and not officially supprted.
So, I exclude 5.0 + JRuby from Travis-CI build. What do you think?

@meganemura
Copy link
Collaborator Author

✅ test passed

@mikecmpbll mikecmpbll merged commit c7db2e3 into influitive:development Jul 5, 2017
@mikecmpbll
Copy link
Collaborator

yayyyy 💃

@meganemura meganemura deleted the clear-cache-for-older-postgresql branch July 5, 2017 08:54
@meganemura
Copy link
Collaborator Author

Thanks 🎉

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

Successfully merging this pull request may close these issues.

2 participants