OceanBase database competition: insert multiple pieces of data at one time (Draft)

The following is the recording process, you can not see it.

Shared information:

  • Automatic test:



  • Competition Title: https://github.com/OceanBase-Partner/lectures-on-dbms-implementation/blob/main/miniob-topics.md
  • mimiob code


  • Registration address


Minimum knowledge

  1. Part II: lex and yacc learning of compilation principles
  • https://courses.cs.washington.edu/courses/cse322/07au/slides/lec25.pdf
  • http://dinosaur.compilertools.net/
  • http://dinosaur.compilertools.net/bison/bison_6.html#SEC42


Train of thought analysis

Title: insert multiple pieces of data at one time

Question: how to insert a record and submit it twice. It feels so complicated 1 for the first time: the record has been inserted_ handler_-> insert_ Record() is inserted into DiskBufferPool.

  1. The second time: in the transaction submission phase: record the transaction number
  • current_trx->commit();
  1. May roll (not written) void end_trx_if_need(Session *session, Trx *trx, bool all_right)

Q4: Topic: insert multiple pieces of data at one time.

Q: How did you yyac say it was modified? I wrote this: multiple () values. Why do you think it is a () value?

What's wrong with this recursive definition?


Instead of direct modification, the error was delayed by 2 days.

  • Write your own code, but the test is wrong? parse_defs.h can be tracked.
  • How to determine to insert multiple records?
  1. After self analysis, uncertainty is generated according to number, and there is no progress in 30 minutes.
  • You can input multiple values according to the topic, which makes you feel difficult to implement

Difficulty: reduce it to support 2 values, and then look at the test results

  • How to add a new structure


  1. Has anyone ever debugged yacc? Insert multiple pieces of data at a time

The content is stored in a two-dimensional matrix. Although row+1 is + 1 for each values content, it does not work when parsing? Finally, the first line is parsed.

Code reading

Code implementation:

  • LOG_ERROR("insert_record rc=%d:%s", rc, strrc(rc));

Insert multiple records at a time, insert submit

char *record_data; RC rc = make_record(value_num, values, record_data);

  • current_trx->commit();

case Operation::Type::INSERT:

RC Table::commit_insert(Trx *trx, const RID &rid)

Answer 4:

#### select_attr -->  attr_list
    | ID attr_list {
   RelAttr attr;
   relation_attr_init(&attr, NULL, $1);
   selects_append_attribute(&CONTEXT->ssql->sstr.selection, &attr);
    /* empty */
    | COMMA ID attr_list {
   RelAttr attr;
   relation_attr_init(&attr, NULL, $2);
   selects_append_attribute(&CONTEXT->ssql->sstr.selection, &attr);
        // CONTEXT->ssql->sstr.selection.attributes[CONTEXT->select_length].relation_name = NULL;
        // CONTEXT->ssql->sstr.selection.attributes[CONTEXT->select_length++].attribute_name=$2;
  • Default code
  • Semicolor is a SEMICOLON.
  • Lbrace value_list rbrace inserts a value
typedef struct ParserContext {
  Query * ssql;
  size_t select_length;
  size_t condition_length;
  size_t from_length;
  size_t value_length;
  Value values[MAX_NUM];
  Condition conditions[MAX_NUM];
  CompOp comp;
 char id[MAX_NUM];
} ParserContext;


  • If there are more than one [content of this topic]
  • No, it depends on where
  1. Others are adding operations to the same object. What should I do with different objects

Insert a row of records

const Inserts &inserts = sql->sstr.insertion;
// struct of insert
typedef struct {
char *relation_name;    // Relation to insert into
size_t value_num;       // Length of values
Value values[MAX_NUM];  // values to insert
} Inserts;
//I don't dare to modify Inserts to set structure
//I added the same structure
typedef struct {
char *relation_name;    // Relation to insert into
size_t value_num;       // Length of values
Value values[MAX_NUM];  // values to insert
} InsertLeft;
  • This topic is a little too fast to do. I want to give up. I watch book for 15 minutes.)
  • case SCF_INSERT:

Refer to update implementation

// struct of craete_table
typedef struct {
  char *relation_name;           // Relation name
  size_t attribute_count;        // Length of attribute
  AttrInfo attributes[MAX_NUM];  // attributes
} CreateTable;


 void create_table_append_attribute(CreateTable *create_table, AttrInfo *attr_info)
    create_table->attributes[create_table->attribute_count++] = *attr_info;
create_table_append_attribute(&CONTEXT->ssql->sstr.create_table, &attribute);

union Queries {
  Selects selection;
  Inserts insertion;
  Deletes deletion;
  Updates update;
  CreateTable create_table;
  DropTable drop_table;
  CreateIndex create_index;
  DropIndex drop_index;
  DescTable desc_table;
  LoadData load_data;
  char *errors;

 | MIN LBRACE ID RBRACE attr_list {
   RelAttr attr;
   relation_attr_init(&attr, NULL,$3);
   selects_append_attribute(&CONTEXT->ssql->sstr.selection, &attr);
4 reference selections_ append_ Attribute implementation
 void selects_append_attribute(Selects *selects, RelAttr *rel_attr)
    selects->attributes[selects->attr_num++] = *rel_attr;


  • insert.sh
drop table t;
drop index unique_index_01 on t;
create table t(id int, age int,name char,birthday date,money float);
create unique index unique_index_01 on t(id);
## test
insert into t values(1,11, "a","2021-3-1",1.2),(2,22, "c","2021-3-2",2.2);
insert into t values(3,33, "c","2021-3-3",3.2);


echo -n "$sqls" | while read line
echo "$line"
echo -n "$line" | ../obclient | sed -e "s/miniob > //"
echo "------------------------------"
done >>test.tmp

  • gdb
flex lex_sql.l

bison -d -b yacc_sql yacc_sql.y

breakpoint set --file default_storage_stage.cpp --line 180

breakpoint set --file parse.cpp --line 259

Test log

  1. Insert 10 columns, why become 10 columns? There is a problem with the parsing script inserts_init_appends rows=0,left_num=2,type=3,value_num=10
  2. view watchpoints insert
insert: result file difference(`-` is yours and `+` is base)
 INSERT INTO INSERT_TABLE VALUES (4,'N4',1,1),(1,1,1,1);

Posted by plusnplus on Wed, 17 Nov 2021 22:43:04 -0800