from template.db import Database from template.query import Query from time import process_time from random import choice, randrange # Student Id and 4 grades db = Database() grades_table = db.create_table('Grades', 0, 5) query = Query(grades_table) keys = [] insert_time_0 = process_time() for i in range(0, 10000): query.insert(906659671 + i, 93, 0, 0, 0) keys.append(906659671 + i) insert_time_1 = process_time() print("Inserting 10k records took: \t\t\t", insert_time_1 - insert_time_0) # Measuring update Performance update_cols = [ [randrange(0, 100), None, None, None, None], [None, randrange(0, 100), None, None, None], [None, None, randrange(0, 100), None, None], [None, None, None, randrange(0, 100), None], [None, None, None, None, randrange(0, 100)], ] update_time_0 = process_time() for i in range(0, 10000): query.update(choice(keys), *(choice(update_cols)))
db.open('ECS165') grades_table = db.create_table('Grades', 5, 0) keys = [] records = {} seed(3562901) num_threads = 8 # Generate random records for i in range(0, 10000): key = 92106429 + i keys.append(key) records[key] = [key, 0, 0, 0, 0] q = Query(grades_table) q.insert(*records[key]) # Create transactions and assign them to workers transactions = [] transaction_workers = [] for i in range(num_threads): transaction_workers.append(TransactionWorker()) for i in range(10000): key = choice(keys) record = records[key] c = record[1] transaction = Transaction() for i in range(5): c += 1 q = Query(grades_table)
Before using this demo, be sure that the Tail_Const is set to a value high enough to guaranteed that all updates are contained within the same block. config.py -> TAIL_CONST = 4 This program is meant to run sequentially through all parts starting with an empty ECS165 directory. ''' db = Database() db.open('ECS165') print("Creating tables: 'Grades'") grades_table = db.create_table('Grades', 5, 0) query = Query(grades_table) keys = [] # Measuring Insert Performance print("Inserting two records, Keys= 92106429, 2106430") query.insert(92106429, 93, 5, 7, 0) query.insert(92106430, 8, 7, 6, 5) rec = query.select(92106429, 0, [1, 1, 1, 1, 1])[0] rec2 = query.select(92106430, 0, [1, 1, 1, 1, 1])[0] print("Printing record data contents") print(rec) print(rec2) rec = query.selectFull(92106429, 0) rec2 = query.selectFull(92106430, 0) print("Printing full record contents") print(rec) print(rec2) db.close()
records = {} seed(3562901) for i in range(0, 10): key = 92106429 + randint(0, 9000) while key in records: key = 92106429 + randint(0, 9000) records[key] = [ key, randint(0, 20), randint(0, 20), randint(0, 20), randint(0, 20) ] query.insert(*records[key]) print('inserted', records[key]) grades_table.index.print_trees() for key in records: record = query.select(key, 0, [1, 1, 1, 1, 1])[0] error = False for i, column in enumerate(record.columns): if column != records[key][i]: error = True if error: print('select error on', key, ':', record, ', correct:', records[key]) else: print('select on', key, ':', record) for key in records:
from template.db import Database from template.query import Query from template.index import * import time db = Database() db.open("./ECS165") grades_table = db.create_table('QueryTester', 5, 0) #index = Index(grades_table) query = Query(grades_table) # print("Inserting 1M items") for i in range(1_001): query.insert(*[i, i, i + 1, i + 2, i + 3]) for record in query.select_range(500, 525, 0, [1, 1, 1, 1, 1]): print(record.columns) #query.insert(*[1, 2, 3, 4, 5]) # <- #query.insert(*[1, 3, 4, 5, 6]) #query.insert(*[2, 1, 3, 3, 4]) # query.select(2, 1, [None, None, None, None, 1])[0].columns #index.drop_index(1) #print(query.select(2, 1, [1, 1, 1, 1, 1])[0].columns) #print(query.select(4, 2, [1, None, None, None, None])[0].columns[0]) """print(query.delete(1)) print(query.select(2, 1, [None, None, None, None, 1])) print(query.select(3, 1, [None, None, None, None, 1])) print(query.select(2,0,[None, None, None, None, 1]))""" query.insert(*[42, 42, 3, 4, 5])