def create_index(self, column_number): if column_number in self.col_btree: return print("Create index", column_number) zeros = [None] * self.table.num_columns mask = Bits("") mask.build_from_list(zeros[:column_number] + [1] + zeros[column_number:]) tree = OOBTreePy() ks = {} for rid in self.table.page_directory: _m = self.table.page_directory[rid] if _m.indirection == 0 or _m.indirection > rid: #print("ADDING INDEX:",rid) r = self.table.get(rid, mask) #ks[rid] = r.columns[0] ks[r[0]] = [rid] tree.update(ks) self.col_btree[column_number] = tree return True
class Index: def __init__(self, table): self.tree = None """ # returns the location of all records with the given value """ def locate(self, value): return self.tree.values(value) """ # optional: Create index on specific column """ def create_index(self, table, column_number): zeros = [None] * table.num_columns mask = Bits("") mask.build_from_list(zeros[:column_number] + [1] + zeros[column_number:]) self.tree = OOBTreePy() ks = {} for rid in table.page_directory: r = table.get(rid, mask) ks[rid] = r.columns[0] self.tree.update(ks) """ # optional: Drop index of specific column """ def drop_index(self, table, column_number): self.tree = None def get_range(self, l, r): return self.tree.values(min=l, max=r)