Class: Innodb::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, record) ⇒ Record

Returns a new instance of Record.



7
8
9
10
# File 'lib/innodb/record.rb', line 7

def initialize(page, record)
  @page = page
  @record = record
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/innodb/record.rb', line 4

def page
  @page
end

#recordObject

Returns the value of attribute record.



5
6
7
# File 'lib/innodb/record.rb', line 5

def record
  @record
end

Instance Method Details

#child_page_numberObject



77
78
79
# File 'lib/innodb/record.rb', line 77

def child_page_number
  record[:child_page_number]
end

#compare_key(other_key) ⇒ Object

Compare two arrays of fields to determine if they are equal. This follows the same comparison rules as strcmp and others:

0 = a is equal to b
-1 = a is less than b
+1 = a is greater than b


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/innodb/record.rb', line 110

def compare_key(other_key)
  Innodb::Stats.increment :compare_key

  return 0 if other_key.nil? && key.nil?
  return -1 if other_key.nil? || (!key.nil? && other_key.size < key.size)
  return +1 if key.nil? || (!other_key.nil? && other_key.size > key.size)

  key.each_index do |i|
    Innodb::Stats.increment :compare_key_field_comparison
    return -1 if other_key[i] < key[i][:value]
    return +1 if other_key[i] > key[i][:value]
  end

  return 0
end

#each_undo_recordObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/innodb/record.rb', line 63

def each_undo_record
  unless block_given?
    return enum_for(:each_undo_record)
  end

  undo_record = undo
  while undo_record
    yield undo_record
    undo_record = undo_record.prev_by_history
  end

  nil
end

#fieldsObject



101
102
103
# File 'lib/innodb/record.rb', line 101

def fields
  @fields ||= uncached_fields
end

#headerObject



12
13
14
# File 'lib/innodb/record.rb', line 12

def header
  record[:header]
end

#keyObject



28
29
30
# File 'lib/innodb/record.rb', line 28

def key
  record[:key]
end

#key_stringObject



32
33
34
# File 'lib/innodb/record.rb', line 32

def key_string
  key && key.map { |r| "%s=%s" % [r[:name], r[:value].inspect] }.join(", ")
end

#lengthObject



20
21
22
# File 'lib/innodb/record.rb', line 20

def length
  record[:length]
end

#nextObject



24
25
26
# File 'lib/innodb/record.rb', line 24

def next
  record[:next]
end

#offsetObject



16
17
18
# File 'lib/innodb/record.rb', line 16

def offset
  record[:offset]
end

#roll_pointerObject



48
49
50
# File 'lib/innodb/record.rb', line 48

def roll_pointer
  record[:roll_pointer]
end

#rowObject



36
37
38
# File 'lib/innodb/record.rb', line 36

def row
  record[:row]
end

#row_stringObject



40
41
42
# File 'lib/innodb/record.rb', line 40

def row_string
  row && row.map { |r| "%s=%s" % [r[:name], r[:value].inspect] }.join(", ")
end

#stringObject



81
82
83
84
85
86
87
# File 'lib/innodb/record.rb', line 81

def string
  if child_page_number
    "(%s) → #%s" % [key_string, child_page_number]
  else
    "(%s) → (%s)" % [key_string, row_string]
  end
end

#transaction_idObject



44
45
46
# File 'lib/innodb/record.rb', line 44

def transaction_id
  record[:transaction_id]
end

#uncached_fieldsObject



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/innodb/record.rb', line 89

def uncached_fields
  fields_hash = {}
  [:key, :row].each do |group|
    if record[group]
      record[group].each do |column|
        fields_hash[column[:name]] = column[:value]
      end
    end
  end
  fields_hash
end

#undoObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/innodb/record.rb', line 52

def undo
  if innodb_system = @page.space.innodb_system
    undo_space = innodb_system.system_space
    if undo_page = undo_space.page(roll_pointer[:undo_log][:page])
      new_undo_record = Innodb::UndoRecord.new(undo_page, roll_pointer[:undo_log][:offset])
      new_undo_record.index_page = page
      new_undo_record
    end
  end
end