# MySQL LEFT/RIGHT JOIN算法效率分析

 FOR each row t1 in T1 such that C1(t1) { BOOL f1:=FALSE; FOR each row t2 in T2 such that P1(t1,t2) AND (f1?C2(t2):TRUE) { BOOL f2:=FALSE; FOR each row t3 in T3 such that P2(t2,t3) AND (f1&&f2?C3(t3):TRUE) { IF (f1&&f2?TRUE:(C2(t2) AND C3(t3))) { t:=t1||t2||t3; OUTPUT t; } f2=TRUE; f1=TRUE; } IF (!f2) { IF (f1?TRUE:C2(t2) && P(t1,t2,NULL)) { t:=t1||t2||NULL; OUTPUT t; } f1=TRUE; } } IF (!f1 && P(t1,NULL,NULL)) { t:=t1||NULL||NULL; OUTPUT t; } }

 #include #include #include #define MAXN 10000 #define LIMIT 500   using namespace std;   //计时器 class Timer { public : //构造函数 Timer (); //析构函数 ~Timer (); //开始计时 void begin(); //计时结束 void end(); //获取时间 double get_time(); private : clock_t start, finish; double time; };   Timer::Timer () { start = 0; finish = 0; }   Timer::~Timer () { start = 0; finish = 0; }   void Timer::begin () { start = clock(); }   void Timer::end () { finish = clock(); }   double Timer::get_time() { time = (double)(finish-start)/CLOCKS_PER_SEC; return time; }   int a[MAXN]; int b[MAXN]; int c[MAXN]; int d[MAXN]; int p[4][2];   //初始化测试数据 void init () { srand(time(0)); //参与关键查询的数据 //cout << "a\tb\tc\td" << endl; for(int i=0; ip[0][0] && a[i]p[1][0] && b[j]p[2][0] && c[k]p[0][0] && a[i]p[1][0] && b[j]p[2][0] && c[k]p[0][0] && a[i]p[1][0] && b[j]p[2][0] && c[k]p[0][0] && a[i]p[1][0] && b[j]p[0][0] && a[i]p[0][0] && a[i]p[1][0] && b[j]p[2][0] && c[k]p[0][0] && a[i]p[1][0] && b[j]p[2][0] && c[k] " << count2 << " <> " << count3 << endl; }   return ; }   int main() { init(); innerJoin(); leftJoin(); return 0; }

#### mysql sql left right inner join区别及效率比较

2017-10-20 15:51:51

#### Mysql left join,right join,inner join的效率比较

2017-04-13 15:00:16

#### mysql left join,right join,inner join超详细用法分析

2016-11-26 14:07:56

#### 数据库优化<三>SQL优化之SELECT优化 ——JOIN和LEFT JOIN 和 RIGHT JOIN

2013-12-05 10:48:27

#### mysql left join right join区别以及优化收集

2015-08-13 14:15:58

#### mysql left join,right join,inner join的区别

2017-12-19 17:54:31

#### mysql中left join,right join,inner join,outer join的用法详解【转】

2010-01-12 20:06:00

#### mysql中left join,right join,inner join,outer join 用法详解

2016-12-09 14:46:06

#### MySQL多表连接查询Left Join,Right Join(讲的一般般)

2015-08-18 11:04:58

#### 系统设计时应尽量避免出现left outer join, right outer join

2012-01-10 14:01:35