DATE(...) seems to be slightly faster than DATE_FORMAT(...) on MYSQL - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit b026d0c5c59126e57f28e5405c04c9505671a955
(DIR) parent 22209f004c013566cbd6aa6acb167dd6b9950771
(HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
Date: Thu, 11 Mar 2010 22:02:55 +0100
DATE(...) seems to be slightly faster than DATE_FORMAT(...) on MYSQL
Diffstat:
M lib/saulabs/reportable/grouping.rb | 4 ++--
M spec/classes/grouping_spec.rb | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/lib/saulabs/reportable/grouping.rb b/lib/saulabs/reportable/grouping.rb
@@ -66,7 +66,7 @@ module Saulabs
if @identifier == :week
parts = [db_string[0..3], db_string[4..5]].map(&:to_i)
else
- db_string.split('/').map(&:to_i)
+ db_string.split(@identifier == :day ? '-' : '/').map(&:to_i)
end
end
@@ -99,7 +99,7 @@ module Saulabs
when :hour
"DATE_FORMAT(#{date_column}, '%Y/%m/%d/%H')"
when :day
- "DATE_FORMAT(#{date_column}, '%Y/%m/%d')"
+ "DATE(#{date_column})"
when :week
"YEARWEEK(#{date_column}, 3)"
when :month
(DIR) diff --git a/spec/classes/grouping_spec.rb b/spec/classes/grouping_spec.rb
@@ -23,7 +23,7 @@ describe Saulabs::Reportable::Grouping do
end
it 'should use DATE_FORMAT with format string "%Y/%m/%d" for grouping :day' do
- Saulabs::Reportable::Grouping.new(:day).send(:to_sql, 'created_at').should == "DATE_FORMAT(created_at, '%Y/%m/%d')"
+ Saulabs::Reportable::Grouping.new(:day).send(:to_sql, 'created_at').should == "DATE(created_at)"
end
it 'should use YEARWEEK with mode 3 for grouping :week' do