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

empty array encoding compatibility with Sequel and ActiveRecord #14

Merged
merged 2 commits into from Feb 20, 2020

Conversation

ermolaev
Copy link
Contributor

Sequel

DB.fetch("SELECT ?", []).sql
=> "SELECT (NULL)"

ActiveRecord

Product.find_by_sql(['select ? ', []])
  Product Load (0.7ms)  select NULL

@@ -50,19 +50,19 @@ def quoted_date(value)

def quote_val(value)
case value
when String then "'#{conn.escape_string(value.to_s)}'"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are commonly used types, for performance, they should be placed on top

var = 2

Benchmark.ips do |r|
  r.report('bottom') do |n|
    while n > 0
      case var
      when String  then 1
      when Array   then 1
      when Symbol  then 1
      when Numeric then 1
      end
      n -= 1
    end
  end
  r.report('top') do |n|
    while n > 0
      case var
      when Numeric then 1
      when String  then 1
      when Array   then 1
      when Symbol  then 1
      end
      n -= 1
    end
  end
  r.compare!
end
# Comparison:
#                  top: 18495320.6 i/s
#               bottom:  5602695.7 i/s - 3.30x  slower

@SamSaffron
Copy link
Member

Thanks @ermolaev ! change looks good to me

@SamSaffron SamSaffron merged commit e5d394f into discourse:master Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants