pg_query_analyzer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +73 -0
  2. data/lib/pg_query_analyzer.rb +32 -0
  3. metadata +63 -0
data/README ADDED
@@ -0,0 +1,73 @@
1
+ == PostgreSQL Query Analyzer for Rails
2
+
3
+ Provides a PostgreSQL query analysis in your development logs.
4
+
5
+
6
+ == Installation
7
+
8
+ gem install pg_query_analyzer
9
+
10
+ # config/enviroments/development.rb
11
+
12
+ config.gem "pg_query_analyzer"
13
+
14
+
15
+ == Example
16
+
17
+ Analyzing Car Load Execution Time:
18
+
19
+ Hash Join (cost=8.01..21.90 rows=6 width=2699)
20
+ Hash Cond: (cars.group_id = group.id)
21
+ -> Seq Scan on cars (cost=0.00..12.80 rows=280 width=2699)
22
+ -> Hash (cost=8.00..8.00 rows=1 width=8)
23
+ -> Hash Join (cost=3.90..8.00 rows=1 width=8)
24
+ Hash Cond: (groups.id = contracts.group_id)
25
+ -> Seq Scan on groups (cost=0.00..3.79 rows=79 width=4)
26
+ -> Hash (cost=3.89..3.89 rows=1 width=4)
27
+ -> Seq Scan on contracts (cost=0.00..3.89 rows=1 width=4)
28
+ Filter: (user_id = 8)
29
+
30
+
31
+ == Options
32
+
33
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.explain_analyze = true
34
+
35
+ Use ANALYZE to carry out the command and show the actual run times.
36
+
37
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.explain_verbose = true
38
+
39
+ Use VERBOSE to show the full internal representation of the plan tree, rather than a summary.
40
+
41
+
42
+ == Credits
43
+
44
+ MODIFIED by John Eberly originally take from http://svn.nfectio.us
45
+ PostgreSQL and Oracle Adapter from Luca Mearelli http://spazidigitali.com
46
+ Cooked and gemified by Marcos Piccinini http://github.com/nofxx/query-analyzer
47
+ PostgreSQL Only Version from Trevor Turk http://github.com/trevorturk/pg_query_analyzer
48
+
49
+
50
+ == MIT License
51
+
52
+ Spatial Adapter Copyright (c) 2006 Guilhem Vellut <guilhem.vellut+georuby@gmail.com>
53
+ PostGis Adapter Functions (c) 2008 Marcos Piccinini <nofxx>
54
+ PostgreSQL Only Version (c) 2010 Trevor Turk <trevorturk>
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining
57
+ a copy of this software and associated documentation files (the
58
+ "Software"), to deal in the Software without restriction, including
59
+ without limitation the rights to use, copy, modify, merge, publish,
60
+ distribute, sublicense, and/or sell copies of the Software, and to
61
+ permit persons to whom the Software is furnished to do so, subject to
62
+ the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be
65
+ included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
68
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
70
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
71
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
72
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
73
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class PostgreSQLAdapter < AbstractAdapter
4
+ include CommonAnalyzer
5
+
6
+ cattr_accessor :explain_analyze
7
+ @@explain_analyze = true
8
+
9
+ cattr_accessor :explain_verbose
10
+ @@explain_verbose = true
11
+
12
+ private
13
+
14
+ alias_method :select_without_analyzer, :select
15
+
16
+ def select(sql, name = nil)
17
+ start_time = Time.now
18
+ query_results = select_without_analyzer(sql, name)
19
+ spent = Time.now - start_time
20
+
21
+ if @logger and @logger.level <= Logger::INFO
22
+ select_logger(@spent, @logger.silence do
23
+ format_log_entry("Analyzing #{name} Execution Time: #{spent}\n\n",
24
+ "#{select_without_analyzer("explain #{'analyze' if @@explain_analyze} "+
25
+ "#{'verbose' if @@explain_verbose} #{sql}", name).map(&:values).join("\n ")}\n")
26
+ end) if sql =~ /^select/i
27
+ end
28
+ query_results
29
+ end
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg_query_analyzer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Trevor Turk
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-24 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Provides a PostgreSQL query analysis in your development logs.
22
+ email: trevorturk@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - lib/pg_query_analyzer.rb
31
+ - README
32
+ has_rdoc: true
33
+ homepage: http://github.com/trevorturk/pg_query_analyzer
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.6
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Provides a PostgreSQL query analysis in your development logs.
62
+ test_files: []
63
+