Class: Innodb::Index::IndexCursor
- Inherits:
-
Object
- Object
- Innodb::Index::IndexCursor
- Defined in:
- lib/innodb/index.rb
Overview
A cursor to walk the index (cursor) forwards or backward starting with a given record, or the minimum (:min) or maximum (:max) record in the index.
Instance Method Summary collapse
-
#each_record ⇒ Object
Iterate through all records in the cursor.
-
#initialize(index, record, direction) ⇒ IndexCursor
constructor
A new instance of IndexCursor.
-
#record ⇒ Object
Return the next record in the order defined when the cursor was created.
Constructor Details
#initialize(index, record, direction) ⇒ IndexCursor
Returns a new instance of IndexCursor.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/innodb/index.rb', line 243 def initialize(index, record, direction) Innodb::Stats.increment :index_cursor_create @index = index @direction = direction case record when :min # Start at the minimum record on the minimum page in the index. @page = index.min_page_at_level(0) @page_cursor = @page.record_cursor(:min, direction) when :max # Start at the maximum record on the maximum page in the index. @page = index.max_page_at_level(0) @page_cursor = @page.record_cursor(:max, direction) else # Start at the record provided. @page = record.page @page_cursor = @page.record_cursor(record.offset, direction) end end |
Instance Method Details
#each_record ⇒ Object
Iterate through all records in the cursor.
278 279 280 281 282 283 284 |
# File 'lib/innodb/index.rb', line 278 def each_record return enum_for(:each_record) unless block_given? while (rec = record) yield rec end end |
#record ⇒ Object
Return the next record in the order defined when the cursor was created.
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/innodb/index.rb', line 264 def record if (rec = @page_cursor.record) return rec end case @direction when :forward next_record when :backward prev_record end end |