pgdexter 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +18 -3
- data/Rakefile +1 -0
- data/exe/dexter +0 -0
- data/lib/dexter/indexer.rb +9 -6
- data/lib/dexter/version.rb +1 -1
- data/pgdexter.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f136be602609b6abb8f11ef02fa7cf18a8db33a
|
4
|
+
data.tar.gz: c58324b44d32b867df2a5a127a70b4d713e2dfa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f39e8a9794a937fe79a637f46e76ee71eba53e9bf3b60a734ad6af270a9236216d5182440586bde0762fd05d48be11c02bb3e620039ec02e2acce1633b81d36
|
7
|
+
data.tar.gz: b870ca6f00a6bc2f6d76c49d6805d0910d4053457ca5c11ccb666de863406fcd07acf37fdf7f23fb4d89f0df6795724fe74fca601738aa47f6832edbafa03a86
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -40,7 +40,7 @@ tail -F -n +1 <log-file> | dexter <database-url>
|
|
40
40
|
|
41
41
|
This finds slow queries and generates output like:
|
42
42
|
|
43
|
-
```
|
43
|
+
```
|
44
44
|
2017-06-25T17:52:19+00:00 Started
|
45
45
|
2017-06-25T17:52:22+00:00 Processing 189 new query fingerprints
|
46
46
|
2017-06-25T17:52:22+00:00 Index found: genres_movies (genre_id)
|
@@ -54,9 +54,9 @@ This finds slow queries and generates output like:
|
|
54
54
|
|
55
55
|
To be safe, Dexter will not create indexes unless you pass the `--create` flag. In this case, you’ll see:
|
56
56
|
|
57
|
-
```
|
57
|
+
```
|
58
58
|
2017-06-25T17:52:22+00:00 Index found: ratings (user_id)
|
59
|
-
2017-06-25T17:52:22+00:00 Creating index: CREATE INDEX CONCURRENTLY ON ratings (user_id)
|
59
|
+
2017-06-25T17:52:22+00:00 Creating index: CREATE INDEX CONCURRENTLY ON "ratings" ("user_id")
|
60
60
|
2017-06-25T17:52:37+00:00 Index created: 15243 ms
|
61
61
|
```
|
62
62
|
|
@@ -86,3 +86,18 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
86
86
|
- Fix bugs and [submit pull requests](https://github.com/ankane/dexter/pulls)
|
87
87
|
- Write, clarify, or fix documentation
|
88
88
|
- Suggest or add new features
|
89
|
+
|
90
|
+
To get started, run:
|
91
|
+
|
92
|
+
```sh
|
93
|
+
git clone https://github.com/ankane/dexter.git
|
94
|
+
cd dexter
|
95
|
+
bundle
|
96
|
+
rake install
|
97
|
+
```
|
98
|
+
|
99
|
+
To run tests, use:
|
100
|
+
|
101
|
+
```sh
|
102
|
+
rake test
|
103
|
+
```
|
data/Rakefile
CHANGED
data/exe/dexter
CHANGED
File without changes
|
data/lib/dexter/indexer.rb
CHANGED
@@ -106,7 +106,9 @@ module Dexter
|
|
106
106
|
candidates = {}
|
107
107
|
columns(tables).each do |col|
|
108
108
|
unless index_set.include?([col[:table], [col[:column]]])
|
109
|
-
|
109
|
+
unless ["json", "jsonb"].include?(col[:type])
|
110
|
+
candidates[col] = select_all("SELECT * FROM hypopg_create_index('CREATE INDEX ON #{quote_ident(col[:table])} (#{[col[:column]].map { |c| quote_ident(c) }.join(", ")})')").first["indexname"]
|
111
|
+
end
|
110
112
|
end
|
111
113
|
end
|
112
114
|
candidates
|
@@ -190,7 +192,7 @@ module Dexter
|
|
190
192
|
# 3. create indexes that still don't exist
|
191
193
|
# 4. release lock
|
192
194
|
new_indexes.each do |index|
|
193
|
-
statement = "CREATE INDEX CONCURRENTLY ON #{index[:table]} (#{index[:columns].join(", ")})"
|
195
|
+
statement = "CREATE INDEX CONCURRENTLY ON #{quote_ident(index[:table])} (#{index[:columns].map { |c| quote_ident(c) }.join(", ")})"
|
194
196
|
log "Creating index: #{statement}"
|
195
197
|
started_at = Time.now
|
196
198
|
select_all(statement)
|
@@ -198,7 +200,7 @@ module Dexter
|
|
198
200
|
end
|
199
201
|
end
|
200
202
|
else
|
201
|
-
log "No indexes found"
|
203
|
+
log "No new indexes found"
|
202
204
|
end
|
203
205
|
|
204
206
|
new_indexes
|
@@ -222,7 +224,7 @@ module Dexter
|
|
222
224
|
end
|
223
225
|
|
224
226
|
def select_all(query)
|
225
|
-
# use exec_params instead of exec for
|
227
|
+
# use exec_params instead of exec for security
|
226
228
|
#
|
227
229
|
# Unlike PQexec, PQexecParams allows at most one SQL command in the given string.
|
228
230
|
# (There can be semicolons in it, but not more than one nonempty command.)
|
@@ -260,7 +262,8 @@ module Dexter
|
|
260
262
|
columns = select_all <<-SQL
|
261
263
|
SELECT
|
262
264
|
table_name,
|
263
|
-
column_name
|
265
|
+
column_name,
|
266
|
+
data_type
|
264
267
|
FROM
|
265
268
|
information_schema.columns
|
266
269
|
WHERE
|
@@ -268,7 +271,7 @@ module Dexter
|
|
268
271
|
table_name IN (#{tables.map { |t| quote(t) }.join(", ")})
|
269
272
|
SQL
|
270
273
|
|
271
|
-
columns.map { |v| {table: v["table_name"], column: v["column_name"]} }
|
274
|
+
columns.map { |v| {table: v["table_name"], column: v["column_name"], type: v["data_type"]} }
|
272
275
|
end
|
273
276
|
|
274
277
|
def indexes(tables)
|
data/lib/dexter/version.rb
CHANGED
data/pgdexter.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgdexter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- andrew@chartkick.com
|