Class: Readyset::Explain

Inherits:
Object
  • Object
show all
Defined in:
lib/readyset/explain.rb

Overview

Represents the result of an ‘EXPLAIN CREATE CACHE` invocation on ReadySet.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, text:, supported:) ⇒ Explain

Creates a new ‘Explain` with the given attributes.

Parameters:

  • id (String)

    the ID of the query

  • text (String)

    the query text

  • supported (Symbol)

    the supported status of the query



25
26
27
28
29
# File 'lib/readyset/explain.rb', line 25

def initialize(id:, text:, supported:) # :nodoc:
  @id = id
  @text = text
  @supported = supported
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/readyset/explain.rb', line 4

def id
  @id
end

#supportedObject (readonly)

Returns the value of attribute supported.



4
5
6
# File 'lib/readyset/explain.rb', line 4

def supported
  @supported
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'lib/readyset/explain.rb', line 4

def text
  @text
end

Class Method Details

.call(query) ⇒ Explain

Gets information about the given query from ReadySet, including whether it’s supported to be cached, its current status, the rewritten query text, and the query ID.

The information about the given query is retrieved by invoking ‘EXPLAIN CREATE CACHE FROM` on ReadySet.

Parameters:

  • a (String)

    query about which information should be retrieved

Returns:



14
15
16
17
# File 'lib/readyset/explain.rb', line 14

def self.call(query)
  raw_results = Readyset.raw_query("EXPLAIN CREATE CACHE FROM #{query}")
  from_readyset_results(**raw_results.first.to_h.symbolize_keys)
end

Instance Method Details

#==(other) ⇒ Boolean

Compares ‘self` with another `Explain` by comparing them attribute-wise.

Parameters:

  • other (Explain)

    the ‘Explain` to which `self` should be compared

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/readyset/explain.rb', line 35

def ==(other)
  id == other.id &&
    text == other.text &&
    supported == other.supported
end

#unsupported?Boolean

Returns true if the explain information returned by ReadySet indicates that the query is unsupported.

Returns:

  • (Boolean)


45
46
47
# File 'lib/readyset/explain.rb', line 45

def unsupported?
  supported == :unsupported
end