forked from TsinghuaDatabaseGroup/DB-GPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.py
81 lines (59 loc) · 2.54 KB
/
configs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import json
from .index_selection.selection_algorithms.extend_algorithm import ExtendAlgorithm
from .index_selection.selection_algorithms.db2advis_algorithm import DB2AdvisAlgorithm
from .index_selection.selection_utils.workload import Workload
from .index_selection.selection_utils import selec_com
import time
import pdb
INDEX_SELECTION_ALGORITHMS = {
"extend": ExtendAlgorithm,
"db2advis": DB2AdvisAlgorithm
}
def get_index_result(algo, work_list, connector, columns, column_sampled_values,
sel_params="parameters", process=False, overhead=False):
script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
exp_conf_file = script_dir + \
f"/index_selection/selection_data/algo_conf/{algo}_config.json"
with open(exp_conf_file, "r") as rf:
exp_config = json.load(rf)
config = selec_com.find_parameter_list(exp_config["algorithms"][0],
params=sel_params)[0]
queries = selec_com.read_row_query(work_list, exp_config,
columns, column_sampled_values, _type="")
workload = Workload(queries)
connector.enable_simulation()
time.sleep(.1)
connector.drop_hypo_indexes()
algorithm = INDEX_SELECTION_ALGORITHMS[algo](
connector, config["parameters"], process)
indexes = algorithm.calculate_best_indexes(workload, overhead=overhead)
indexes = indexes[0]
if indexes == []:
return [], -1, -1
# if indexes are of string type
if not isinstance(indexes, list):
indexes = [str(indexes)]
else:
indexes = [str(ind) for ind in indexes]
cols = [ind.split(",") for ind in indexes]
cols = [list(map(lambda x: x.split(".")[-1], col)) for col in cols]
indexes = [
f"{ind.split('.')[0]}#{','.join(col)}" for ind,
col in zip(
indexes,
cols)]
no_cost, ind_cost = list(), list()
total_no_cost, total_ind_cost = 0, 0
for query in queries:
if '$' not in query.text:
no_cost_ = connector.get_ind_cost(query.text, "")
total_no_cost += round(no_cost_, 2)
# total_no_cost += round(no_cost_*sql['frequency'], 2)
no_cost.append(no_cost_)
ind_cost_ = connector.get_ind_cost(query.text, indexes)
total_ind_cost += round(ind_cost_, 2)
# total_ind_cost += round(ind_cost_*sql['frequency'], 2)
ind_cost.append(ind_cost_)
return indexes, total_no_cost, total_ind_cost