mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
LibSQL: BTree index, Heap, and Meta objects for SQL Storage layer
Unfortunately this patch is quite large. The main functionality included are a BTree index implementation and the Heap class which manages persistent storage. Also included are a Key subclass of the Tuple class, which is a specialization for index key tuples. This "dragged in" the Meta layer, which has classes defining SQL objects like tables and indexes.
This commit is contained in:
parent
2a46529170
commit
224804b424
15 changed files with 2153 additions and 0 deletions
46
Userland/Libraries/LibSQL/Index.cpp
Normal file
46
Userland/Libraries/LibSQL/Index.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibSQL/Heap.h>
|
||||
#include <LibSQL/Index.h>
|
||||
#include <LibSQL/Meta.h>
|
||||
|
||||
namespace SQL {
|
||||
|
||||
Index::Index(Heap& heap, TupleDescriptor const& descriptor, bool unique, u32 pointer)
|
||||
: m_heap(heap)
|
||||
, m_descriptor(descriptor)
|
||||
, m_unique(unique)
|
||||
, m_pointer(pointer)
|
||||
{
|
||||
}
|
||||
|
||||
Index::Index(Heap& heap, TupleDescriptor const& descriptor, u32 pointer)
|
||||
: m_heap(heap)
|
||||
, m_descriptor(descriptor)
|
||||
, m_pointer(pointer)
|
||||
{
|
||||
}
|
||||
|
||||
ByteBuffer Index::read_block(u32 block)
|
||||
{
|
||||
auto ret = m_heap.read_block(block);
|
||||
if (ret.is_error()) {
|
||||
warnln("Error reading block {}: {}", block, ret.error());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
return ret.value();
|
||||
}
|
||||
|
||||
void Index::add_to_write_ahead_log(IndexNode* node)
|
||||
{
|
||||
VERIFY(node->pointer());
|
||||
ByteBuffer buffer;
|
||||
node->serialize(buffer);
|
||||
m_heap.add_to_wal(node->pointer(), buffer);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue