activerecord-cockroachdb-adapter 6.1.0.pre.beta.2 → 6.1.0.pre.beta.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 +6 -0
- data/README.md +6 -0
- data/activerecord-cockroachdb-adapter.gemspec +1 -1
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +95 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bc55cc2cb9bfa57e9e0d5757aa2e4e892361b68f9f216de0627d3fc01c165dd
|
4
|
+
data.tar.gz: 36582fada5f267b47c827c6b30112c8db955cac8606b3ae5d9c3f73cb77c9424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23656edaccbd223d6573d1a3636263d779ae437b5628d657cd5ed2c0d7773dfa75ea52fd7b228cf06fce477ee35ea9179fa612716dc9d5bbf893d78a8dee797
|
7
|
+
data.tar.gz: 566d24599b0a74edec6bdba172639130b4d6a92dc688870ee9848d124f4523ea400bf334bfa017e92cdc289f39e06c951301f1a8deb2dc74e7b0889cd617b08e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 6.1.0-beta.3 - 2021-04-02
|
4
|
+
|
5
|
+
- Added a configuration option named `use_follower_reads_for_type_introspection`.
|
6
|
+
If true, it improves the speed of type introspection by allowing potentially stale
|
7
|
+
type metadata to be read. Defaults to false.
|
8
|
+
|
3
9
|
## 6.1.0-beta.2 - 2021-03-06
|
4
10
|
|
5
11
|
- Improved connection performance by refactoring an introspection
|
data/README.md
CHANGED
@@ -22,6 +22,12 @@ development:
|
|
22
22
|
user: <username>
|
23
23
|
```
|
24
24
|
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
In addition to the standard adapter settings, CockroachDB also supports the following:
|
28
|
+
|
29
|
+
- `use_follower_reads_for_type_introspection`: Use follower reads on queries to the `pg_type` catalog when set to `true`. This helps to speed up initialization by reading historical data, but may not find recently created user-defined types.
|
30
|
+
|
25
31
|
## Working with Spatial Data
|
26
32
|
|
27
33
|
The adapter uses [RGeo](https://github.com/rgeo/rgeo) and [RGeo-ActiveRecord](https://github.com/rgeo/rgeo-activerecord) to represent geometric and geographic data as Ruby objects and easily interface them with the adapter. The following is a brief introduction to RGeo and tips to help setup your spatial application. More documentation about RGeo can be found in the [YARD Docs](https://rubydoc.info/github/rgeo/rgeo) and [wiki](https://github.com/rgeo/rgeo/wiki).
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "activerecord-cockroachdb-adapter"
|
7
|
-
spec.version = "6.1.0-beta.
|
7
|
+
spec.version = "6.1.0-beta.3"
|
8
8
|
spec.licenses = ["Apache-2.0"]
|
9
9
|
spec.authors = ["Cockroach Labs"]
|
10
10
|
spec.email = ["cockroach-db@googlegroups.com"]
|
@@ -173,6 +173,10 @@ module ActiveRecord
|
|
173
173
|
@crdb_version >= 202
|
174
174
|
end
|
175
175
|
|
176
|
+
def supports_partitioned_indexes?
|
177
|
+
false
|
178
|
+
end
|
179
|
+
|
176
180
|
# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
|
177
181
|
# migration from PostgreSQL to CockroachDB. In practice, this limitation
|
178
182
|
# is arbitrary since CockroachDB supports index name lengths and table alias
|
@@ -440,6 +444,97 @@ module ActiveRecord
|
|
440
444
|
false
|
441
445
|
end
|
442
446
|
|
447
|
+
# override
|
448
|
+
# This method loads info about data types from the database to
|
449
|
+
# populate the TypeMap.
|
450
|
+
#
|
451
|
+
# Currently, querying from the pg_type catalog can be slow due to geo-partitioning
|
452
|
+
# so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
|
453
|
+
def load_additional_types(oids = nil)
|
454
|
+
if @config[:use_follower_reads_for_type_introspection]
|
455
|
+
initializer = OID::TypeMapInitializer.new(type_map)
|
456
|
+
|
457
|
+
query = <<~SQL
|
458
|
+
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
459
|
+
FROM pg_type as t
|
460
|
+
LEFT JOIN pg_range as r ON oid = rngtypid AS OF SYSTEM TIME '-10s'
|
461
|
+
SQL
|
462
|
+
|
463
|
+
if oids
|
464
|
+
query += "WHERE t.oid IN (%s)" % oids.join(", ")
|
465
|
+
else
|
466
|
+
query += initializer.query_conditions_for_initial_load
|
467
|
+
end
|
468
|
+
|
469
|
+
execute_and_clear(query, "SCHEMA", []) do |records|
|
470
|
+
initializer.run(records)
|
471
|
+
end
|
472
|
+
else
|
473
|
+
super
|
474
|
+
end
|
475
|
+
rescue ActiveRecord::StatementInvalid => e
|
476
|
+
raise e unless e.cause.is_a? PG::InvalidCatalogName
|
477
|
+
# use original if database is younger than 10s
|
478
|
+
super
|
479
|
+
end
|
480
|
+
|
481
|
+
# override
|
482
|
+
# This method maps data types to their proper decoder.
|
483
|
+
#
|
484
|
+
# Currently, querying from the pg_type catalog can be slow due to geo-partitioning
|
485
|
+
# so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
|
486
|
+
def add_pg_decoders
|
487
|
+
if @config[:use_follower_reads_for_type_introspection]
|
488
|
+
@default_timezone = nil
|
489
|
+
@timestamp_decoder = nil
|
490
|
+
|
491
|
+
coders_by_name = {
|
492
|
+
"int2" => PG::TextDecoder::Integer,
|
493
|
+
"int4" => PG::TextDecoder::Integer,
|
494
|
+
"int8" => PG::TextDecoder::Integer,
|
495
|
+
"oid" => PG::TextDecoder::Integer,
|
496
|
+
"float4" => PG::TextDecoder::Float,
|
497
|
+
"float8" => PG::TextDecoder::Float,
|
498
|
+
"numeric" => PG::TextDecoder::Numeric,
|
499
|
+
"bool" => PG::TextDecoder::Boolean,
|
500
|
+
"timestamp" => PG::TextDecoder::TimestampUtc,
|
501
|
+
"timestamptz" => PG::TextDecoder::TimestampWithTimeZone,
|
502
|
+
}
|
503
|
+
|
504
|
+
known_coder_types = coders_by_name.keys.map { |n| quote(n) }
|
505
|
+
query = <<~SQL % known_coder_types.join(", ")
|
506
|
+
SELECT t.oid, t.typname
|
507
|
+
FROM pg_type as t AS OF SYSTEM TIME '-10s'
|
508
|
+
WHERE t.typname IN (%s)
|
509
|
+
SQL
|
510
|
+
|
511
|
+
coders = execute_and_clear(query, "SCHEMA", []) do |result|
|
512
|
+
result
|
513
|
+
.map { |row| construct_coder(row, coders_by_name[row["typname"]]) }
|
514
|
+
.compact
|
515
|
+
end
|
516
|
+
|
517
|
+
map = PG::TypeMapByOid.new
|
518
|
+
coders.each { |coder| map.add_coder(coder) }
|
519
|
+
@connection.type_map_for_results = map
|
520
|
+
|
521
|
+
@type_map_for_results = PG::TypeMapByOid.new
|
522
|
+
@type_map_for_results.default_type_map = map
|
523
|
+
@type_map_for_results.add_coder(PG::TextDecoder::Bytea.new(oid: 17, name: "bytea"))
|
524
|
+
@type_map_for_results.add_coder(MoneyDecoder.new(oid: 790, name: "money"))
|
525
|
+
|
526
|
+
# extract timestamp decoder for use in update_typemap_for_default_timezone
|
527
|
+
@timestamp_decoder = coders.find { |coder| coder.name == "timestamp" }
|
528
|
+
update_typemap_for_default_timezone
|
529
|
+
else
|
530
|
+
super
|
531
|
+
end
|
532
|
+
rescue ActiveRecord::StatementInvalid => e
|
533
|
+
raise e unless e.cause.is_a? PG::InvalidCatalogName
|
534
|
+
# use original if database is younger than 10s
|
535
|
+
super
|
536
|
+
end
|
537
|
+
|
443
538
|
def arel_visitor
|
444
539
|
Arel::Visitors::CockroachDB.new(self)
|
445
540
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-cockroachdb-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.1.0.pre.beta.
|
4
|
+
version: 6.1.0.pre.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cockroach Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|