Coder Social home page Coder Social logo

Comments (4)

jeremycole avatar jeremycole commented on June 13, 2024

Hi. Could you try the search again with index.debug = true? Also, could you provide a more complete sample of what you're trying to do, especially e.g. how you initialized "index"? It looks like somewhere it's trying to use page 0 as an index page, which it is not.

from innodb_ruby.

kormoc avatar kormoc commented on June 13, 2024

I'm following the examples at http://blog.jcole.us/2013/01/14/efficiently-traversing-innodb-btrees-with-the-page-directory/

Bender:test root# irb -rrubygems -rinnodb
>> space = Innodb::Space.new("mytable.ibd")
=> #<Innodb::Space:0x1024f94c8 @file=#<File:mytable.ibd>, @record_describer=nil, @pages=10752, @size=176160768, @page_size=16384, @fsp={:space_id=>1, :free_inodes=>#<Innodb::List::Inode:0x1024de858 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>1, :first=>{:offset=>38, :page=>2}, :last=>{:offset=>38, :page=>2}}>, :unused=>0, :free_frag=>#<Innodb::List::Xdes:0x1024e4870 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>1, :first=>{:offset=>198, :page=>0}, :last=>{:offset=>198, :page=>0}}>, :free_limit=>10304, :full_frag=>#<Innodb::List::Xdes:0x1024e2ef8 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>1, :first=>{:offset=>158, :page=>0}, :last=>{:offset=>158, :page=>0}}>, :frag_n_used=>40, :size=>10752, :first_unused_seg=>5, :free=>#<Innodb::List::Xdes:0x1024e8308 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>2, :first=>{:offset=>6518, :page=>0}, :last=>{:offset=>6558, :page=>0}}>, :full_inodes=>#<Innodb::List::Inode:0x1024e1b20 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>0, :first=>nil, :last=>nil}>, :flags=>{:page_size=>16384, :compressed=>false, :value=>0}}, @compressed=false>
>> index = space.index(3)
=> #<Innodb::Index:0x1024d5a00 @root=#<Innodb::Page::Index: size=16384, space_id=1, offset=3, type=INDEX, prev=nil, next=nil>, @stats={}, @space=#<Innodb::Space:0x1024f94c8 @file=#<File:mytable.ibd>, @record_describer=nil, @pages=10752, @size=176160768, @page_size=16384, @fsp={:space_id=>1, :free_inodes=>#<Innodb::List::Inode:0x1024de858 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>1, :first=>{:offset=>38, :page=>2}, :last=>{:offset=>38, :page=>2}}>, :unused=>0, :free_frag=>#<Innodb::List::Xdes:0x1024e4870 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>1, :first=>{:offset=>198, :page=>0}, :last=>{:offset=>198, :page=>0}}>, :free_limit=>10304, :full_frag=>#<Innodb::List::Xdes:0x1024e2ef8 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>1, :first=>{:offset=>158, :page=>0}, :last=>{:offset=>158, :page=>0}}>, :frag_n_used=>40, :size=>10752, :first_unused_seg=>5, :free=>#<Innodb::List::Xdes:0x1024e8308 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>2, :first=>{:offset=>6518, :page=>0}, :last=>{:offset=>6558, :page=>0}}>, :full_inodes=>#<Innodb::List::Inode:0x1024e1b20 @space=#<Innodb::Space:0x1024f94c8 ...>, @base={:length=>0, :first=>nil, :last=>nil}>, :flags=>{:page_size=>16384, :compressed=>false, :value=>0}}, @compressed=false>, @debug=false>
>> index.debug = true
=> true
>> index.binary_search([10000])
binary_search: root=3, level=2, key=(10000)
binary_search_by_directory: page=3, level=2, dir.size=1, dir[0]=()
NoMethodError: undefined method `join' for nil:NilClass
    from /Library/Ruby/Gems/1.8/gems/innodb_ruby-0.7.11/lib/innodb/index.rb:193:in `linear_search_from_cursor'
    from /Library/Ruby/Gems/1.8/gems/innodb_ruby-0.7.11/lib/innodb/index.rb:264:in `binary_search_by_directory'
    from /Library/Ruby/Gems/1.8/gems/innodb_ruby-0.7.11/lib/innodb/index.rb:366:in `binary_search'
    from (irb):4
>> 

And here's the create table

mysql> SHOW CREATE TABLE mytable\G
*************************** 1. row ***************************
       Table: mytable
Create Table: CREATE TABLE `mytable` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `words` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `words` (`words`)
) ENGINE=InnoDB AUTO_INCREMENT=721353 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

from innodb_ruby.

jeremycole avatar jeremycole commented on June 13, 2024

Ah, you are missing a record_describer. You will need to create a Ruby class that describes how to parse records. Unfortunately the binary_search method does not check that a record describer exists, so it aborts in a kind of weird place. I'll fix that up to be more friendly.

This post has an example of a record describer, but unfortunately they are not really documented:

http://blog.jcole.us/2013/01/10/btree-index-structures-in-innodb/

This describer will probably work for the PRIMARY KEY of your table:

class Innodb::RecordDescriber::MyTable < Innodb::RecordDescriber
  def self.cursor_sendable_description(page)
    {
      :type => :clustered,
      :key => [
        [:INT, :UNSIGNED, :NOT_NULL],
      ],
      :row => [
        ["CHAR(255)", :NOT_NULL],
      ],
    }
  end
end

from innodb_ruby.

kormoc avatar kormoc commented on June 13, 2024

That did the trick. Thanks much!

from innodb_ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.