innodb_ruby 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/innodb_space +4 -4
- data/lib/innodb/index.rb +21 -21
- data/lib/innodb/record.rb +8 -0
- data/lib/innodb/version.rb +1 -1
- metadata +1 -1
data/bin/innodb_space
CHANGED
@@ -388,7 +388,7 @@ def page_directory_summary(page)
|
|
388
388
|
record = page.record(offset)
|
389
389
|
key = if [:conventional, :node_pointer].include? record.header[:type]
|
390
390
|
if record.key
|
391
|
-
"(%s)" % record.
|
391
|
+
"(%s)" % record.key_string,
|
392
392
|
end
|
393
393
|
end
|
394
394
|
puts "%-8i%-8i%-14s%-8i%s" % [
|
@@ -443,8 +443,8 @@ def index_recurse(index)
|
|
443
443
|
page.each_record do |record|
|
444
444
|
puts "%sRECORD: (%s) -> (%s)" % [
|
445
445
|
" " * (depth+1),
|
446
|
-
record.
|
447
|
-
record.
|
446
|
+
record.key_string,
|
447
|
+
record.row_string,
|
448
448
|
]
|
449
449
|
end
|
450
450
|
end
|
@@ -533,7 +533,7 @@ def index_level_summary(index, levels)
|
|
533
533
|
page.record_space,
|
534
534
|
page.free_space,
|
535
535
|
page.records,
|
536
|
-
page.first_record.
|
536
|
+
page.first_record.key_string,
|
537
537
|
]
|
538
538
|
end
|
539
539
|
end
|
data/lib/innodb/index.rb
CHANGED
@@ -87,7 +87,7 @@ class Innodb::Index
|
|
87
87
|
page = @root
|
88
88
|
record = @root.first_record
|
89
89
|
while record && page.level > level
|
90
|
-
page = page(record
|
90
|
+
page = page(record.child_page_number)
|
91
91
|
record = page.first_record
|
92
92
|
end
|
93
93
|
page if page.level == level
|
@@ -185,8 +185,8 @@ class Innodb::Index
|
|
185
185
|
|
186
186
|
a.each_index do |i|
|
187
187
|
@stats[:compare_key_field_comparison] += 1
|
188
|
-
return -1 if a[i] < b[i]
|
189
|
-
return +1 if a[i] > b[i]
|
188
|
+
return -1 if a[i] < b[i][:value]
|
189
|
+
return +1 if a[i] > b[i][:value]
|
190
190
|
end
|
191
191
|
|
192
192
|
return 0
|
@@ -206,7 +206,7 @@ class Innodb::Index
|
|
206
206
|
puts "linear_search_from_cursor: page=%i, level=%i, start=(%s)" % [
|
207
207
|
page.offset,
|
208
208
|
page.level,
|
209
|
-
this_rec && this_rec
|
209
|
+
this_rec && this_rec.key_string,
|
210
210
|
]
|
211
211
|
end
|
212
212
|
|
@@ -219,19 +219,19 @@ class Innodb::Index
|
|
219
219
|
puts "linear_search_from_cursor: page=%i, level=%i, current=(%s)" % [
|
220
220
|
page.offset,
|
221
221
|
page.level,
|
222
|
-
this_rec && this_rec
|
222
|
+
this_rec && this_rec.key_string,
|
223
223
|
]
|
224
224
|
end
|
225
225
|
|
226
226
|
# If we reach supremum, return the last non-system record we got.
|
227
|
-
return this_rec if next_rec
|
227
|
+
return this_rec if next_rec.header[:type] == :supremum
|
228
228
|
|
229
|
-
if compare_key(key, this_rec
|
229
|
+
if compare_key(key, this_rec.key) < 0
|
230
230
|
return this_rec
|
231
231
|
end
|
232
232
|
|
233
|
-
if (compare_key(key, this_rec
|
234
|
-
(compare_key(key, next_rec
|
233
|
+
if (compare_key(key, this_rec.key) >= 0) &&
|
234
|
+
(compare_key(key, next_rec.key) < 0)
|
235
235
|
# The desired key is either an exact match for this_rec or is greater
|
236
236
|
# than it but less than next_rec. If this is a non-leaf page, that
|
237
237
|
# will mean that the record will fall on the leaf page this node
|
@@ -268,7 +268,7 @@ class Innodb::Index
|
|
268
268
|
page.level,
|
269
269
|
dir.size,
|
270
270
|
mid,
|
271
|
-
rec
|
271
|
+
rec.key_string,
|
272
272
|
]
|
273
273
|
end
|
274
274
|
|
@@ -276,12 +276,12 @@ class Innodb::Index
|
|
276
276
|
# compare_key, so we need to just linear scan from here. If the mid-point
|
277
277
|
# is the beginning of the page there can't be many records left to check
|
278
278
|
# anyway.
|
279
|
-
if rec
|
280
|
-
return linear_search_from_cursor(page, page.record_cursor(rec
|
279
|
+
if rec.header[:type] == :infimum
|
280
|
+
return linear_search_from_cursor(page, page.record_cursor(rec.next), key)
|
281
281
|
end
|
282
282
|
|
283
283
|
# Compare the desired key to the mid-point record's key.
|
284
|
-
case compare_key(key, rec
|
284
|
+
case compare_key(key, rec.key)
|
285
285
|
when 0
|
286
286
|
# An exact match for the key was found. Return the record.
|
287
287
|
@stats[:binary_search_by_directory_exact_match] += 1
|
@@ -297,16 +297,16 @@ class Innodb::Index
|
|
297
297
|
binary_search_by_directory(page, dir[mid...dir.size], key)
|
298
298
|
else
|
299
299
|
next_rec = page.record(dir[mid+1])
|
300
|
-
next_key = next_rec && compare_key(key, next_rec
|
300
|
+
next_key = next_rec && compare_key(key, next_rec.key)
|
301
301
|
if dir.size == 1 || next_key == -1 || next_key == 0
|
302
302
|
# This is the last entry remaining from the directory, or our key is
|
303
303
|
# greater than rec and less than rec+1's key. Use linear search to
|
304
304
|
# find the record starting at rec.
|
305
305
|
@stats[:binary_search_by_directory_linear_search] += 1
|
306
|
-
linear_search_from_cursor(page, page.record_cursor(rec
|
306
|
+
linear_search_from_cursor(page, page.record_cursor(rec.offset), key)
|
307
307
|
elsif next_key == +1
|
308
308
|
@stats[:binary_search_by_directory_linear_search] += 1
|
309
|
-
linear_search_from_cursor(page, page.record_cursor(next_rec
|
309
|
+
linear_search_from_cursor(page, page.record_cursor(next_rec.offset), key)
|
310
310
|
else
|
311
311
|
nil
|
312
312
|
end
|
@@ -346,16 +346,16 @@ class Innodb::Index
|
|
346
346
|
end
|
347
347
|
|
348
348
|
while rec =
|
349
|
-
linear_search_from_cursor(page, page.record_cursor(page.infimum
|
349
|
+
linear_search_from_cursor(page, page.record_cursor(page.infimum.next), key)
|
350
350
|
if page.level > 0
|
351
351
|
# If we haven't reached a leaf page yet, move down the tree and search
|
352
352
|
# again using linear search.
|
353
|
-
page = page(rec
|
353
|
+
page = page(rec.child_page_number)
|
354
354
|
else
|
355
355
|
# We're on a leaf page, so return the page and record if there is a
|
356
356
|
# match. If there is no match, break the loop and cause nil to be
|
357
357
|
# returned.
|
358
|
-
return page, rec if compare_key(key, rec
|
358
|
+
return page, rec if compare_key(key, rec.key) == 0
|
359
359
|
break
|
360
360
|
end
|
361
361
|
end
|
@@ -383,12 +383,12 @@ class Innodb::Index
|
|
383
383
|
if page.level > 0
|
384
384
|
# If we haven't reached a leaf page yet, move down the tree and search
|
385
385
|
# again using binary search.
|
386
|
-
page = page(rec
|
386
|
+
page = page(rec.child_page_number)
|
387
387
|
else
|
388
388
|
# We're on a leaf page, so return the page and record if there is a
|
389
389
|
# match. If there is no match, break the loop and cause nil to be
|
390
390
|
# returned.
|
391
|
-
return page, rec if compare_key(key, rec
|
391
|
+
return page, rec if compare_key(key, rec.key) == 0
|
392
392
|
break
|
393
393
|
end
|
394
394
|
end
|
data/lib/innodb/record.rb
CHANGED
@@ -23,10 +23,18 @@ class Innodb::Record
|
|
23
23
|
record[:key]
|
24
24
|
end
|
25
25
|
|
26
|
+
def key_string
|
27
|
+
key && key.map { |r| "%s=%s" % [r[:name], r[:value]] }.join(", ")
|
28
|
+
end
|
29
|
+
|
26
30
|
def row
|
27
31
|
record[:row]
|
28
32
|
end
|
29
33
|
|
34
|
+
def row_string
|
35
|
+
key && key.map { |r| "%s=%s" % [r[:name], r[:value]] }.join(", ")
|
36
|
+
end
|
37
|
+
|
30
38
|
def child_page_number
|
31
39
|
record[:child_page_number]
|
32
40
|
end
|
data/lib/innodb/version.rb
CHANGED