!1513 mcts算法增加推荐索引个数约束

Merge pull request !1513 from liuly/master
This commit is contained in:
opengauss-bot
2022-02-16 01:54:00 +00:00
committed by Gitee
2 changed files with 7 additions and 4 deletions

View File

@ -690,7 +690,8 @@ def complex_index_advisor(input_path, integrate_indexes, db):
if DRIVER:
db.close_conn()
if MAX_INDEX_STORAGE:
opt_config = MCTS(workload, atomic_config_total, candidate_indexes, MAX_INDEX_STORAGE)
opt_config = MCTS(workload, atomic_config_total, candidate_indexes,
MAX_INDEX_STORAGE, MAX_INDEX_NUM)
else:
opt_config = greedy_determine_opt_config(workload, atomic_config_total,
candidate_indexes, index_cost_total[0])

View File

@ -4,6 +4,7 @@ import random
import copy
MAX_INDEX_NUM = 0
STORAGE_THRESHOLD = 0
AVAILABLE_CHOICES = []
ATOMIC_CHOICES = []
@ -111,7 +112,7 @@ class State(object):
def is_terminal(self):
# the current node is a leaf node
return len(self.accumulation_choices) == len(AVAILABLE_CHOICES)
return len(self.accumulation_choices) == MAX_INDEX_NUM
def compute_benefit(self):
return self.current_benefit
@ -367,12 +368,13 @@ def monte_carlo_tree_search(node):
return best_next_node
def MCTS(workload_info, atomic_choices, available_choices, storage_threshold):
global ATOMIC_CHOICES, STORAGE_THRESHOLD, WORKLOAD_INFO, AVAILABLE_CHOICES
def MCTS(workload_info, atomic_choices, available_choices, storage_threshold, max_index_num):
global ATOMIC_CHOICES, STORAGE_THRESHOLD, WORKLOAD_INFO, AVAILABLE_CHOICES, MAX_INDEX_NUM
WORKLOAD_INFO = workload_info
AVAILABLE_CHOICES = available_choices
ATOMIC_CHOICES = atomic_choices
STORAGE_THRESHOLD = storage_threshold
MAX_INDEX_NUM = max_index_num if max_index_num else len(available_choices)
# create the initialized state and initialized node
init_state = State()