# Query Optimization in Distributed Database Based on Improved Artificial Bee Colony Algorithm
## 2 Proposed Method  
Distributed databases usually include a coordinator site and multiple data sites. The data are sliced and distributed to different sites according to certain rules, usually using the consistent hashing method according to the keyword of tuples to balance the data storage capacity of each site. The query execution plan determines the selection and join order of sites. In a distributed database, the query execution cost mainly consists of the resource cost of the site's local disk data scanning and the network communication expense of data transmission between different sites. Due to the current limitations of the network bandwidth, the data transmission communication expense between sites is much larger than the resource expense of the local data scanning, so the optimal query execution plan \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Mechanism** & **Approach** & **Advantages** & **Weaknesses** \\ \hline \multirow{3}{*}{[PERSON] et al. [27]} & Proposed a discrete artificial bee colony algorithm based on a novel heuristic approach. & \(\bullet\)Performing well with a small number of relations & \(\bullet\)Terrible performance for a large query \\ \hline \multirow{3}{*}{[PERSON] et al. [28]} & Proposed an ant colony algorithm optimization for query optimization. & \(\bullet\)Improving the average \(\bullet\)Quality of query plan & \(\bullet\)High overhead \(\bullet\)High response time \\ \hline \multirow{3}{*}{[PERSON] et al. [29]} & Proposed a multi-ant colony genetic algorithm. & \(\bullet\)Increasing the convergence speed \(\bullet\)Low execution time & \(\bullet\)Low variety population \(\bullet\)Drop to local optima \\ \hline \multirow{3}{*}{[PERSON] et al. [30]} & Designed a quantum-inspired ant colony-based algorithm. & \(\bullet\)High convergence speed \(\bullet\)High effectiveness & \(\bullet\)Terrible performance for a smaller query \(\bullet\)Easy to precocity \\ \hline \multirow{3}{*}{[PERSON] et al. [31]} & Proposed an adaptive genetic algorithm based on double entropy. & \(\bullet\)High population diversity \(\bullet\)Avoiding getting stuck in local minima & \(\bullet\)Low convergence speed \(\bullet\)Suffers from long execution time \\ \hline \multirow{2}{*}{[PERSON] et al. [32]} & Proposed a hybrid fuzzy ant colony optimization algorithm. & \(\bullet\)Decreasing the time \(\bullet\)High efficiency & \(\bullet\)Easily falls into local optimum for large join query \\ \hline \hline \end{tabular}
\end{table} 
Table 1: A side-by-side comparison of the discussed join query optimization mechanisms. for a distributed database is that which has the minimum communication cost. The four main phases of query optimization applied to distributed databases are shown in Figure 1.  
The first stage is query decomposition: receive query requests submitted by users and parse the query, then recognize the syntactic structure and semantics of the query. Then, transform the query statement (e.g., SQL statements) into a corresponding parse tree. The second stage is data retrieval: determine the data tables involved in the query by analyzing the parse tree, retrieve the location of the sites where the required data are located via a metadata table, and construct a storage site matrix. The third stage is global optimization: the query optimizer generates the query execution plan from the parse tree as well as the data storage matrix. Since a statement can have multiple equivalent execution plans, a cost function is needed to find the least costly query execution plan. The cost of the query plan is calculated using the cost function (CPU cost + I/O cost + communication cost), and the optimal order of query operations is calculated based on the calculation. If it is in a wide-area network, the communication cost will be large and is called the trade-off factor. Then, the query is decomposed into multiple subqueries based on the query-optimized execution plan and distributes the decomposed subqueries to various distributed sites for execution.