GithubHelp home page GithubHelp logo

activerecord-pedantmysql2-adapter's People

Contributors

adrianna-chang-shopify avatar byroot avatar casperisfine avatar eapache avatar edouard-chin avatar etiennebarrie avatar fw42 avatar girasquid avatar nvasilevski avatar ryanseys avatar sunblaze avatar technicalpickles avatar wvanbergen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activerecord-pedantmysql2-adapter's Issues

pedantmysql doesn't work with rails dbconsole

While setting up cod-app for cloud, I realized that rails dbconsole would fail with unknown command-line client for #{database_name}.

I dug through the dbconsole source and attached a few puts to the dbconsole in cluster and observed the following output:
screen shot 2018-01-17 at 12 37 20 pm

The regex match on the case predicate in dbconsole.rb will always fail since when /^(jdbc)?mysql/ begins with pedant, not mysql.

Not sure if this is worthy of a fix since I don't know how often rails dbconsole gets used, but a simple solution seems to be simply renaming the adapter to mysql_pedant.

cc @casperisfine, @goldenson

Ignore warnings on EXPLAIN queries

Currently EXPLAIN queries fail with this adapter installed because on recent versions of MySQL, the server generates a warning with level = "Note" and code = 1003 because the EXPLAIN query is optimized away. This makes sense because an EXPLAIN query doesn't actually execute the query it is explaining.

Example output when calling EXPLAIN SELECT 1:

[1] pry(main)> ActiveRecord::Base.connection.exec_query("EXPLAIN SELECT 1;")
  SQL (1.1ms)  EXPLAIN SELECT 1;
{:severity=>:warn, :messages=>["/* select#1 */ select 1 AS `1`"], :query=>"EXPLAIN SELECT 1;"}
MysqlWarning: /* select#1 */ select 1 AS `1`
from /Users/ryanseys/repo/pedant_mysql2.rb:14:in `block in <main>'

[2] pry(main)> ActiveRecord::Base.connection.exec_query("SHOW WARNINGS")
  SQL (15.9ms)  SHOW WARNINGS
#<ActiveRecord::Result:0x000000010d8becb0 @columns=["Level", "Code", "Message"], @rows=[["Note", 1003, "/* select#1 */ select 1 AS `1`"]], @hash_rows=nil, @column_types={}>

There's currently no great way to ignore these queries because PedantMySQL2.ignore can only ignore based on warning messages, and does not ignore based on warning code or warning level.

Current workaround

The current workaround I found was to exit the on_warning lambda early if the warning meets the conditions of an EXPLAIN query.

PedantMysql2.on_warning = lambda do |warning|
  return if warning.level == "Note" && warning.code == 1003 && warning.query.start_with?("EXPLAIN")

  raise warning
end

There's a few different ways I think we could solve this:

Option 1: Hardcode the ignore of these EXPLAIN queries into the default behavior of this gem

Similar to how drop_table queries are already ignored, we could ignore these warnings by default. Also not backward compatible per-se because perhaps someone wants to catch these warnings?

That said, these warnings are safe to ignore because they are just a warning that the MySQL query optimizer has optimized the query away and did not execute it, which is to be expected for EXPLAIN queries. It also follows a similar behavior to the drop_table behavior where a table cannot be found -- the query optimizer is doing the same thing in this case by not executing the query because the table does not exist.

I've implemented this in #24

Option 2: Introduce PedantMySQL.ignore_if(&block)

Introduce a way to ignore based on the contents of a block. This would be backward compatible as it is a new method, but it would require anyone who wants this functionality to manually implement it, which is annoying and probably means that people are more likely to not implement this correctly, and adds additional overhead to all developers using this gem.

PedantMySQL2.ignore_if do |warning|
  warning.code == 1003 && warning.level == "Note" && warning.query.start_with?("EXPLAIN")
end

Option 3: PedantMySQL.ignore(&block)

Re-use the existing ignore but allow it to take a block. Not backward compatible as it reuses the same method that already exists. Probably the worst of the three options.

PedantMySQL2.ignore do |warning|
  warning.code == 1003 && warning.level == "Note" && warning.query.start_with?("EXPLAIN")
end

Doesn't work in rails 3.2?

I added the gem, bundled and changed the adapter in my datbase.yml. Then, I get this when starting a console:

/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in require': Please install the pedantmysql2 adapter:gem install activerecord-pedantmysql2-adapter` (cannot load such file -- active_record/connection_adapters/pedantmysql2_adapter) (LoadError)

Seems to work fine in a rails 4.1 app though.... is rails 3.x supported?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.