activerecord-analyze 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5163e6745e43205926a1c88a02c4459bd3d9971dde022f5dd64c3368d2c72c13
4
- data.tar.gz: f084b56b9a5b9c5ba1e6ae69e6653c01224287b6e0107ca97666cbd695c04b73
3
+ metadata.gz: d4a7ef7ec9a322a55d31e636725eaa77273059926ebb4a744697b23d612a59b4
4
+ data.tar.gz: 93dbe428ea7bfda307d5362c3ee2623dc5d1aa3a93ada7fe5449affb03eb3c30
5
5
  SHA512:
6
- metadata.gz: 10a11c9983859c51270ae38503e6f751b49f281c85c2f5fd7f28a7709f93d285e6288db8c00741e402f031771b1208c531a142ee28b2bcf5f84d8f14f84c8c18
7
- data.tar.gz: 3669dc47d6dc8e4b1b63881d3bf61fa2d6eff4be1264dab55f77a98a6e55d98ebf22cd37e22b731f1d866954c20032f381d3577db168527d7490b88275037f98
6
+ metadata.gz: a100348c560f7c04733e2d0390a298fe5c8818d06a7c095e5fa4a15099af2bbd8b4263dc2c9ad68315f17905569eb4874d634ae48e8cc4732a5984b06272f4a6
7
+ data.tar.gz: a786120ba3bb4bc3ffe4c8a4a36b7b4e972c9618da55b96e8e3b1494734ef76a5ce8424f8de736d5510026642f0f79b6ed91d8574bce0d5248b549b730b32b27
data/README.md CHANGED
@@ -12,6 +12,96 @@ gem 'activerecord-analyze'
12
12
 
13
13
  ```
14
14
 
15
+ ## Options
16
+
17
+ The `analyze` method supports the following EXPLAIN query options (PG docs reference)[https://www.postgresql.org/docs/12/sql-explain.html]:
18
+
19
+ ```
20
+ VERBOSE [ boolean ]
21
+ COSTS [ boolean ]
22
+ SETTINGS [ boolean ]
23
+ BUFFERS [ boolean ]
24
+ TIMING [ boolean ]
25
+ SUMMARY [ boolean ]
26
+ FORMAT { TEXT | XML | JSON | YAML }
27
+ ```
28
+
29
+ You can pass the options like that:
30
+
31
+ ```ruby
32
+
33
+ User.all.analyze(
34
+ format: :json,
35
+ verbose: true,
36
+ costs: true,
37
+ settings: true,
38
+ buffers: true,
39
+ timing: true,
40
+ summary: true
41
+ )
42
+
43
+ # EXPLAIN (FORMAT JSON, ANALYZE, VERBOSE, COSTS, SETTINGS, BUFFERS, TIMING, SUMMARY)
44
+ # SELECT "users".* FROM "users"
45
+ # [
46
+ # {
47
+ # "Plan": {
48
+ # "Node Type": "Seq Scan",
49
+ # "Parallel Aware": false,
50
+ # "Relation Name": "users",
51
+ # "Schema": "public",
52
+ # "Alias": "users",
53
+ # "Startup Cost": 0.00,
54
+ # "Total Cost": 11.56,
55
+ # "Plan Rows": 520,
56
+ # "Plan Width": 127,
57
+ # "Actual Startup Time": 0.006,
58
+ # "Actual Total Time": 0.007,
59
+ # "Actual Rows": 2,
60
+ # "Actual Loops": 1,
61
+ # "Shared Hit Blocks": 1,
62
+ # "Shared Read Blocks": 0,
63
+ # "Shared Dirtied Blocks": 0,
64
+ # "Shared Written Blocks": 0,
65
+ # "Local Hit Blocks": 0,
66
+ # "Local Read Blocks": 0,
67
+ # "Local Dirtied Blocks": 0,
68
+ # "Local Written Blocks": 0,
69
+ # "Temp Read Blocks": 0,
70
+ # "Temp Written Blocks": 0,
71
+ # "I/O Read Time": 0.000,
72
+ # "I/O Write Time": 0.000
73
+ # },
74
+ # "Settings": {
75
+ # "cpu_index_tuple_cost": "0.001",
76
+ # "cpu_operator_cost": "0.0005",
77
+ # "cpu_tuple_cost": "0.003",
78
+ # "effective_cache_size": "10800000kB",
79
+ # "max_parallel_workers_per_gather": "1",
80
+ # "random_page_cost": "2",
81
+ # "work_mem": "100MB"
82
+ # },
83
+ # "Planning Time": 0.033,
84
+ # "Triggers": [
85
+ # ],
86
+ # "Execution Time": 0.018
87
+ # }
88
+ # ]
89
+
90
+ ```
91
+
92
+ Optionally you can disable running the `ANALYZE` query and only generate the plan:
93
+
94
+ ```ruby
95
+
96
+ User.all.analyze(analyze: false)
97
+
98
+ # EXPLAIN ANALYZE for: SELECT "users".* FROM "users"
99
+ # QUERY PLAN
100
+ # ----------------------------------------------------------
101
+ # Seq Scan on users (cost=0.00..15.20 rows=520 width=127)
102
+
103
+ ```
104
+
15
105
  ### Disclaimer
16
106
 
17
107
  It is a bit experimental and can break with new Rails release.
@@ -50,6 +50,7 @@ module ActiveRecord
50
50
  .strip.gsub(/\s+/, " ")
51
51
  .gsub(/\(\s?\s?\s?,/, "(")
52
52
  .gsub(/\s,\s/, " ")
53
+ .gsub(/\(\s?\)/, "")
53
54
 
54
55
  sql = "EXPLAIN #{opts_sql} #{to_sql(arel, binds)}"
55
56
  PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN #{opts_sql}".strip, binds))
@@ -71,7 +72,13 @@ module ActiveRecord
71
72
  module Explain
72
73
  def exec_analyze(queries, opts = {}) # :nodoc:
73
74
  str = queries.map do |sql, binds|
74
- msg = "EXPLAIN ANALYZE for: #{sql}".dup
75
+ analyze_msg = if opts[:analyze] == false
76
+ ""
77
+ else
78
+ " ANALYZE"
79
+ end
80
+
81
+ msg = "EXPLAIN#{analyze_msg} for: #{sql}".dup
75
82
  unless binds.empty?
76
83
  msg << " "
77
84
  msg << binds.map { |attr| render_bind(attr) }.inspect
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAnalyze
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-analyze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb