# Join Order Adjustment


![left](./student-guide/diagram/16-Connection-adjustment-01-01.png)

------------------------------------------------------------
The base table is scraped by extracting the input operator of the parameter concatenation in the abstract syntax tree. After calculating the statistics for each operator, including column statistics, histograms, and data column NDV values, you can get the basic data for the join operation. If the amount of data is small, use dynamic planning to solve the optimal Join Order for small-scale connections; if the amount of data is large, then use a greedy algorithm to solve the sub-optimal Join Order for large-scale connections. There are two algorithms mentioned here: 
  - Greedy algorithm: join the table with the smallest number of rows and other tables to evaluate and choose the one with the least cost.
  - Dynamic planning: calculate the optimal solution for each layer separately from the bottom up, and then select the divided optimal solution based on exhaustion and calculation of the intermediate result set.

We abstract t1, t2, t3 into three layers of computation
The first layer: t1, t2, and t3 respectively find the optimal solution;
Level 2: The optimal solution is found for every 2 table joins of the participating tables;
Third layer: Use the second and first layers to find the optimal solution, calculate the intermediate result set exhaustively, and select the optimal join method.
