activerecord-cockroachdb-adapter 6.0.0.pre.beta.4 → 6.0.0.pre.beta.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2eca72798ef552202f48b26be2502ef9a9517cf5bd8cda03a0888f67607d6be0
4
- data.tar.gz: e6ca3dc5323251c3e8b77b3e7ea9553cde259557a035fd48f94413e47583ecfe
3
+ metadata.gz: e242232ac6fcfc87b6bddc17eeb852099a959d3a024064ed3a32e85bd80ad786
4
+ data.tar.gz: 5ab114df9f5fee7fb5c18c5cf0eb0dfdc822f7513f19d79312f65e0b55e1e459
5
5
  SHA512:
6
- metadata.gz: 03d0c5cbd633dec23e4092fac1bd678f583ebb0b15688eaf54f9b334890a3edf8f78382424f9549036c179f3c66c6d7276f05f99d92030a19f5895be4ac87d2b
7
- data.tar.gz: 5d1d43cfe25affb953cc423b60ea7d0eef0f10c6bb33133b06d1e5d18aed30f3b2c8a7d0ba259148a2d91d2060cecc1848a81e6b6b25c3e2bb02b42eb5cb0038
6
+ metadata.gz: a2de1e036b53ebeb11185eaeb10bd465f9a1103a34307354bc4bbbe94b8beb4c5a2313938e01703db8b68f5a689ee6b9b778b8282bceac3bb852b6569340351b
7
+ data.tar.gz: 4138ea2ccad0bac070c277adb9ec4aa837be440900f72fe8f2728bac78d58a96d96ed7df9a830841b3389e5f51678dba9377e0598b3aa96d682d36c609dcedfb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.0-beta.5 - 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.0.0-beta.4 - 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.0.0-beta.4"
7
+ spec.version = "6.0.0-beta.5"
8
8
  spec.licenses = ["Apache-2.0"]
9
9
  spec.authors = ["Cockroach Labs"]
10
10
  spec.email = ["cockroach-db@googlegroups.com"]
@@ -218,6 +218,10 @@ module ActiveRecord
218
218
  @crdb_version >= 202
219
219
  end
220
220
 
221
+ def supports_partitioned_indexes?
222
+ false
223
+ end
224
+
221
225
  # This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
222
226
  # migration from PostgreSQL to CockroachDB. In practice, this limitation
223
227
  # is arbitrary since CockroachDB supports index name lengths and table alias
@@ -399,6 +403,100 @@ module ActiveRecord
399
403
  return "{}"
400
404
  end
401
405
 
406
+ # override
407
+ # This method loads info about data types from the database to
408
+ # populate the TypeMap.
409
+ #
410
+ # Currently, querying from the pg_type catalog can be slow due to geo-partitioning
411
+ # so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
412
+ def load_additional_types(oids = nil)
413
+ if @config[:use_follower_reads_for_type_introspection]
414
+ initializer = OID::TypeMapInitializer.new(type_map)
415
+
416
+ query = <<~SQL
417
+ SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
418
+ FROM pg_type as t
419
+ LEFT JOIN pg_range as r ON oid = rngtypid AS OF SYSTEM TIME '-10s'
420
+ SQL
421
+
422
+ if oids
423
+ query += "WHERE t.oid IN (%s)" % oids.join(", ")
424
+ else
425
+ query += initializer.query_conditions_for_initial_load
426
+ end
427
+
428
+ execute_and_clear(query, "SCHEMA", []) do |records|
429
+ initializer.run(records)
430
+ end
431
+ else
432
+ super
433
+ end
434
+ rescue ActiveRecord::StatementInvalid => e
435
+ raise e unless e.cause.is_a? PG::InvalidCatalogName
436
+ # use original if database is younger than 10s
437
+ super
438
+ end
439
+
440
+ # override
441
+ # This method maps data types to their proper decoder.
442
+ #
443
+ # Currently, querying from the pg_type catalog can be slow due to geo-partitioning
444
+ # so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
445
+ def add_pg_decoders
446
+ if @config[:use_follower_reads_for_type_introspection]
447
+ @default_timezone = nil
448
+ @timestamp_decoder = nil
449
+
450
+ coders_by_name = {
451
+ "int2" => PG::TextDecoder::Integer,
452
+ "int4" => PG::TextDecoder::Integer,
453
+ "int8" => PG::TextDecoder::Integer,
454
+ "oid" => PG::TextDecoder::Integer,
455
+ "float4" => PG::TextDecoder::Float,
456
+ "float8" => PG::TextDecoder::Float,
457
+ "numeric" => PG::TextDecoder::Numeric,
458
+ "bool" => PG::TextDecoder::Boolean,
459
+ "timestamp" => PG::TextDecoder::TimestampUtc,
460
+ "timestamptz" => PG::TextDecoder::TimestampWithTimeZone,
461
+ }
462
+
463
+ known_coder_types = coders_by_name.keys.map { |n| quote(n) }
464
+ query = <<~SQL % known_coder_types.join(", ")
465
+ SELECT t.oid, t.typname
466
+ FROM pg_type as t AS OF SYSTEM TIME '-10s'
467
+ WHERE t.typname IN (%s)
468
+ SQL
469
+
470
+ coders = execute_and_clear(query, "SCHEMA", []) do |result|
471
+ result
472
+ .map { |row| construct_coder(row, coders_by_name[row["typname"]]) }
473
+ .compact
474
+ end
475
+
476
+ map = PG::TypeMapByOid.new
477
+ coders.each { |coder| map.add_coder(coder) }
478
+ @connection.type_map_for_results = map
479
+
480
+ @type_map_for_results = PG::TypeMapByOid.new
481
+ @type_map_for_results.default_type_map = map
482
+ @type_map_for_results.add_coder(PG::TextDecoder::Bytea.new(oid: 17, name: "bytea"))
483
+
484
+ # extract timestamp decoder for use in update_typemap_for_default_timezone
485
+ @timestamp_decoder = coders.find { |coder| coder.name == "timestamp" }
486
+ update_typemap_for_default_timezone
487
+ else
488
+ super
489
+ end
490
+ rescue ActiveRecord::StatementInvalid => e
491
+ raise e unless e.cause.is_a? PG::InvalidCatalogName
492
+ # use original if database is younger than 10s
493
+ super
494
+ end
495
+
496
+ def arel_visitor
497
+ Arel::Visitors::CockroachDB.new(self)
498
+ end
499
+
402
500
  # end private
403
501
  end
404
502
  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.0.0.pre.beta.4
4
+ version: 6.0.0.pre.beta.5
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-03-06 00:00:00.000000000 Z
11
+ date: 2021-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord