23#include "common/types.h"
24#include "common/log/log.h"
25#include "storage/index/index_meta.h"
26#include "storage/field/field_meta.h"
40 RID(
const PageNum _page_num,
const SlotNum _slot_num) : page_num(_page_num), slot_num(_slot_num) {}
42 const std::string to_string()
const
45 ss <<
"PageNum:" << page_num <<
", SlotNum:" << slot_num;
49 bool operator==(
const RID &other)
const {
return page_num == other.page_num && slot_num == other.slot_num; }
51 bool operator!=(
const RID &other)
const {
return !(*
this == other); }
53 static int compare(
const RID *rid1,
const RID *rid2)
55 int page_diff = rid1->page_num - rid2->page_num;
59 return rid1->slot_num - rid2->slot_num;
80 static RID rid{std::numeric_limits<PageNum>::max(), std::numeric_limits<SlotNum>::max()};
97 if (
owner_ && data_ !=
nullptr) {
111 char *tmp = (
char *)malloc(other.len_);
112 ASSERT(
nullptr != tmp,
"failed to allocate memory. size=%d", other.len_);
113 memcpy(tmp, other.data_, other.len_);
120 if (
this == &other) {
129 void set_data(
char *data,
int len = 0)
134 void set_data_owner(
char *data,
int len)
136 ASSERT(len != 0,
"the len of data should not be 0");
144 char *data() {
return this->data_; }
145 const char *data()
const {
return this->data_; }
146 int len()
const {
return this->len_; }
148 void set_rid(
const RID &rid) { this->rid_ = rid; }
149 void set_rid(
const PageNum page_num,
const SlotNum slot_num)
151 this->rid_.page_num = page_num;
152 this->rid_.slot_num = slot_num;
154 RID &rid() {
return rid_; }
155 const RID &rid()
const {
return rid_; }
160 char *data_ =
nullptr;
表示一个记录 当前的记录都是连续存放的空间(内存或磁盘上)。 为了提高访问的效率,record通常直接记录指向页面上的内存,但是需要保证访问这种数据时,拿着锁资源。 为了方便,也提供了复制内存的方法。可...
Definition: record.h:92
bool owner_
如果不是record自己来管理内存,这个字段可能是无效的
Definition: record.h:162
标识一个记录的位置 一个记录是放在某个文件的某个页面的某个槽位。这里不记录文件信息,记录页面和槽位信息
Definition: record.h:35
static RID * min()
Definition: record.h:68
static RID * max()
返回一个“最大的”RID 我们假设page num和slot num都不会使用对应数值类型的最大值
Definition: record.h:78