Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49e4501

Browse files
committed
初始化sqladvisor
0 parents  commit 49e4501

File tree

1,359 files changed

+692472
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,359 files changed

+692472
-0
lines changed

CMakeLists.txt

Lines changed: 534 additions & 0 deletions
Large diffs are not rendered by default.

COPYING

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### 一、简介
2+
3+
SQLAdvisor是由美团点评公司技术工程部DBA团队(北京)开发维护的一个分析SQL给出索引优化建议的工具。它基于MySQL原生态词法解析,结合分析SQL中的where条件、聚合条件、多表Join关系 给出索引优化建议。**目前SQLAdvisor在美团点评广泛应用,包括美团支付、酒店旅游、外卖、团购等产品线,公司内部对SQLAdvisor的开发全面转到github上,开源和内部使用保持一致**
4+
5+
**主要功能:输出SQL索引优化建议**
6+
7+
### 二、SQLAdvisor详细说明
8+
9+
1. [SQLAdvisor快速入门教程](./doc/QUICK_START.md)
10+
2. [SQLAdvisor用户使用手册](./doc/USER_GUIDE.md)
11+
3. [SQLAdvisor架构和实践](./doc/THEORY_PRACTICES.md)
12+
4. [SQLAdvisor release notes](./doc/RELEASE_NOTES.md)
13+
5. [SQLAdvisor开发规范](./doc/DEVELOPMENT_NORM.md)
14+
6. [FAQ](./doc/FAQ.md)
15+
16+
### 三、SQLAdvisor的需求及Bug反馈方式
17+
18+
如果用户在实际的应用场景中对SQLAdvisor有新的功能需求,或者在使用SQLAdvisor的过程中发现了bug,在github上进行交流或是PullRequest,也可以在讨论组/群进行反馈,我们会及时维护。
19+
20+
![QQ](./doc/img/qq.png)

VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MYSQL_VERSION_MAJOR=5
2+
MYSQL_VERSION_MINOR=6
3+
MYSQL_VERSION_PATCH=23
4+
MYSQL_VERSION_EXTRA=-72.1

client/get_password.c

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
/*
17+
** Ask for a password from tty
18+
** This is an own file to avoid conflicts with curses
19+
*/
20+
#include <my_global.h>
21+
#include <my_sys.h>
22+
#include "mysql.h"
23+
#include <m_string.h>
24+
#include <m_ctype.h>
25+
#include <mysql/get_password.h>
26+
27+
#if defined(HAVE_BROKEN_GETPASS) && !defined(HAVE_GETPASSPHRASE)
28+
#undef HAVE_GETPASS
29+
#endif
30+
31+
#ifdef HAVE_GETPASS
32+
#ifdef HAVE_PWD_H
33+
#include <pwd.h>
34+
#endif /* HAVE_PWD_H */
35+
#else /* ! HAVE_GETPASS */
36+
#ifndef __WIN__
37+
#include <sys/ioctl.h>
38+
#ifdef HAVE_TERMIOS_H /* For tty-password */
39+
#include <termios.h>
40+
#define TERMIO struct termios
41+
#else
42+
#ifdef HAVE_TERMIO_H /* For tty-password */
43+
#include <termio.h>
44+
#define TERMIO struct termio
45+
#else
46+
#include <sgtty.h>
47+
#define TERMIO struct sgttyb
48+
#endif
49+
#endif
50+
#ifdef alpha_linux_port
51+
#include <asm/ioctls.h> /* QQ; Fix this in configure */
52+
#include <asm/termiobits.h>
53+
#endif
54+
#else
55+
#include <conio.h>
56+
#endif /* __WIN__ */
57+
#endif /* HAVE_GETPASS */
58+
59+
#ifdef HAVE_GETPASSPHRASE /* For Solaris */
60+
#define getpass(A) getpassphrase(A)
61+
#endif
62+
63+
#ifdef __WIN__
64+
/* were just going to fake it here and get input from
65+
the keyboard */
66+
67+
char *get_tty_password_ext(const char *opt_message,
68+
strdup_handler_t strdup_function)
69+
{
70+
char to[80];
71+
char *pos=to,*end=to+sizeof(to)-1;
72+
int i=0;
73+
DBUG_ENTER("get_tty_password_ext");
74+
_cputs(opt_message ? opt_message : "Enter password: ");
75+
for (;;)
76+
{
77+
char tmp;
78+
tmp=_getch();
79+
if (tmp == '\b' || (int) tmp == 127)
80+
{
81+
if (pos != to)
82+
{
83+
_cputs("\b \b");
84+
pos--;
85+
continue;
86+
}
87+
}
88+
if (tmp == '\n' || tmp == '\r' || tmp == 3)
89+
break;
90+
if (iscntrl(tmp) || pos == end)
91+
continue;
92+
_cputs("*");
93+
*(pos++) = tmp;
94+
}
95+
while (pos != to && isspace(pos[-1]) == ' ')
96+
pos--; /* Allow dummy space at end */
97+
*pos=0;
98+
_cputs("\n");
99+
DBUG_RETURN(strdup_function(to,MYF(MY_FAE)));
100+
}
101+
102+
#else
103+
104+
105+
#ifndef HAVE_GETPASS
106+
/*
107+
** Can't use fgets, because readline will get confused
108+
** length is max number of chars in to, not counting \0
109+
* to will not include the eol characters.
110+
*/
111+
112+
static void get_password(char *to,uint length,int fd, my_bool echo)
113+
{
114+
char *pos=to,*end=to+length;
115+
116+
for (;;)
117+
{
118+
char tmp;
119+
if (my_read(fd,&tmp,1,MYF(0)) != 1)
120+
break;
121+
if (tmp == '\b' || (int) tmp == 127)
122+
{
123+
if (pos != to)
124+
{
125+
if (echo)
126+
{
127+
fputs("\b \b",stderr);
128+
fflush(stderr);
129+
}
130+
pos--;
131+
continue;
132+
}
133+
}
134+
if (tmp == '\n' || tmp == '\r' || tmp == 3)
135+
break;
136+
if (iscntrl(tmp) || pos == end)
137+
continue;
138+
if (echo)
139+
{
140+
fputc('*',stderr);
141+
fflush(stderr);
142+
}
143+
*(pos++) = tmp;
144+
}
145+
while (pos != to && isspace(pos[-1]) == ' ')
146+
pos--; /* Allow dummy space at end */
147+
*pos=0;
148+
return;
149+
}
150+
151+
#endif /* ! HAVE_GETPASS */
152+
153+
154+
char *get_tty_password_ext(const char *opt_message,
155+
strdup_handler_t strdup_function)
156+
{
157+
#ifdef HAVE_GETPASS
158+
char *passbuff;
159+
#else /* ! HAVE_GETPASS */
160+
TERMIO org,tmp;
161+
#endif /* HAVE_GETPASS */
162+
char buff[80];
163+
164+
DBUG_ENTER("get_tty_password_ext");
165+
166+
#ifdef HAVE_GETPASS
167+
passbuff = getpass(opt_message ? opt_message : "Enter password: ");
168+
169+
/* copy the password to buff and clear original (static) buffer */
170+
strnmov(buff, passbuff, sizeof(buff) - 1);
171+
#ifdef _PASSWORD_LEN
172+
memset(passbuff, 0, _PASSWORD_LEN);
173+
#endif
174+
#else
175+
if (isatty(fileno(stderr)))
176+
{
177+
fputs(opt_message ? opt_message : "Enter password: ",stderr);
178+
fflush(stderr);
179+
}
180+
#if defined(HAVE_TERMIOS_H)
181+
tcgetattr(fileno(stdin), &org);
182+
tmp = org;
183+
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
184+
tmp.c_cc[VMIN] = 1;
185+
tmp.c_cc[VTIME] = 0;
186+
tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
187+
get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stderr)));
188+
tcsetattr(fileno(stdin), TCSADRAIN, &org);
189+
#elif defined(HAVE_TERMIO_H)
190+
ioctl(fileno(stdin), (int) TCGETA, &org);
191+
tmp=org;
192+
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
193+
tmp.c_cc[VMIN] = 1;
194+
tmp.c_cc[VTIME]= 0;
195+
ioctl(fileno(stdin),(int) TCSETA, &tmp);
196+
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr)));
197+
ioctl(fileno(stdin),(int) TCSETA, &org);
198+
#else
199+
gtty(fileno(stdin), &org);
200+
tmp=org;
201+
tmp.sg_flags &= ~ECHO;
202+
tmp.sg_flags |= RAW;
203+
stty(fileno(stdin), &tmp);
204+
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr)));
205+
stty(fileno(stdin), &org);
206+
#endif
207+
if (isatty(fileno(stderr)))
208+
fputc('\n',stderr);
209+
#endif /* HAVE_GETPASS */
210+
211+
DBUG_RETURN(strdup_function(buff,MYF(MY_FAE)));
212+
}
213+
214+
#endif /*__WIN__*/
215+
216+
char *get_tty_password(const char *opt_message)
217+
{
218+
return get_tty_password_ext(opt_message, my_strdup);
219+
}

cmake/abi_check.cmake

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
#
17+
# Headers which need to be checked for abi/api compatibility are in
18+
# API_PREPROCESSOR_HEADER. plugin.h is tested implicitly via
19+
# plugin_audit.h and plugin_ftparser.h.
20+
#
21+
# We use gcc specific preprocessing command and sed/diff, so it will
22+
# only be run on Unix and only if gcc is used. On some Unixes,
23+
# (Solaris) sed or diff might act differently from GNU, so we run only
24+
# on systems we can trust.
25+
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux")
26+
SET(RUN_ABI_CHECK 1)
27+
ELSE()
28+
SET(RUN_ABI_CHECK 0)
29+
ENDIF()
30+
31+
IF(CMAKE_COMPILER_IS_GNUCC AND RUN_ABI_CHECK)
32+
IF(CMAKE_C_COMPILER MATCHES "ccache$")
33+
SET(COMPILER ${CMAKE_C_COMPILER_ARG1})
34+
STRING(REGEX REPLACE "^ " "" COMPILER ${COMPILER})
35+
ELSE()
36+
SET(COMPILER ${CMAKE_C_COMPILER})
37+
ENDIF()
38+
SET(API_PREPROCESSOR_HEADER
39+
${CMAKE_SOURCE_DIR}/include/mysql/plugin_audit.h
40+
${CMAKE_SOURCE_DIR}/include/mysql/plugin_ftparser.h
41+
${CMAKE_SOURCE_DIR}/include/mysql.h
42+
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v0.h
43+
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v1.h
44+
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v2.h
45+
${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h
46+
${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h
47+
)
48+
49+
ADD_CUSTOM_TARGET(abi_check ALL
50+
COMMAND ${CMAKE_COMMAND}
51+
-DCOMPILER=${COMPILER}
52+
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
53+
-DBINARY_DIR=${CMAKE_BINARY_DIR}
54+
"-DABI_HEADERS=${API_PREPROCESSOR_HEADER}"
55+
-P ${CMAKE_SOURCE_DIR}/cmake/do_abi_check.cmake
56+
VERBATIM
57+
)
58+
59+
ADD_CUSTOM_TARGET(abi_check_all
60+
COMMAND ${CMAKE_COMMAND}
61+
-DCOMPILER=${COMPILER}
62+
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
63+
-DBINARY_DIR=${CMAKE_BINARY_DIR}
64+
"-DABI_HEADERS=${API_PREPROCESSOR_HEADER}"
65+
-P ${CMAKE_SOURCE_DIR}/cmake/do_abi_check.cmake
66+
VERBATIM
67+
)
68+
ENDIF()
69+

cmake/bison.cmake

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (c) 2009 Sun Microsystems, Inc.
2+
# Use is subject to license terms.
3+
#
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; version 2 of the License.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
18+
# On Solaris, /opt/csw often contains a newer bison
19+
IF(NOT BISON_EXECUTABLE AND EXISTS /opt/csw/bin/bison)
20+
SET(BISON_EXECUTABLE /opt/csw/bin/bison)
21+
ENDIF()
22+
ENDIF()
23+
FIND_PROGRAM(BISON_EXECUTABLE bison DOC "path to the bison executable")
24+
MARK_AS_ADVANCED(BISON_EXECUTABLE "")
25+
IF(NOT BISON_EXECUTABLE)
26+
MESSAGE("Warning: Bison executable not found in PATH")
27+
ELSEIF(BISON_EXECUTABLE AND NOT BISON_USABLE)
28+
# Check version as well
29+
EXEC_PROGRAM(${BISON_EXECUTABLE} ARGS --version OUTPUT_VARIABLE BISON_VERSION_STR)
30+
# Get first line in case it's multiline
31+
STRING(REGEX REPLACE "([^\n]+).*" "\\1" FIRST_LINE "${BISON_VERSION_STR}")
32+
# get version information
33+
STRING(REGEX REPLACE ".* ([0-9]+)\\.([0-9]+)" "\\1" BISON_VERSION_MAJOR "${FIRST_LINE}")
34+
STRING(REGEX REPLACE ".* ([0-9]+)\\.([0-9]+)" "\\2" BISON_VERSION_MINOR "${FIRST_LINE}")
35+
IF (BISON_VERSION_MAJOR LESS 2)
36+
MESSAGE("Warning: bison version is old. please update to version 2")
37+
ELSE()
38+
SET(BISON_USABLE 1 CACHE INTERNAL "Bison version 2 or higher")
39+
ENDIF()
40+
ENDIF()
41+
42+
# Use bison to generate C++ and header file
43+
MACRO (RUN_BISON input_yy output_cc output_h)
44+
IF(BISON_TOO_OLD)
45+
IF(EXISTS ${output_cc} AND EXISTS ${output_h})
46+
SET(BISON_USABLE FALSE)
47+
ENDIF()
48+
ENDIF()
49+
IF(BISON_USABLE)
50+
ADD_CUSTOM_COMMAND(
51+
OUTPUT ${output_cc}
52+
${output_h}
53+
COMMAND ${BISON_EXECUTABLE} -y -p MYSQL
54+
--output=${output_cc}
55+
--defines=${output_h}
56+
${input_yy}
57+
DEPENDS ${input_yy}
58+
)
59+
ELSE()
60+
# Bison is missing or not usable, e.g too old
61+
IF(EXISTS ${output_cc} AND EXISTS ${output_h})
62+
IF(${input_yy} IS_NEWER_THAN ${output_cc} OR ${input_yy} IS_NEWER_THAN ${output_h})
63+
# Possibly timestamps are messed up in source distribution.
64+
MESSAGE("Warning: no usable bison found, ${input_yy} will not be rebuilt.")
65+
ENDIF()
66+
ELSE()
67+
# Output files are missing, bail out.
68+
SET(ERRMSG
69+
"Bison (GNU parser generator) is required to build MySQL."
70+
"Please install bison."
71+
)
72+
IF(WIN32)
73+
SET(ERRMSG ${ERRMSG}
74+
"You can download bison from http://gnuwin32.sourceforge.net/packages/bison.htm "
75+
"Choose 'Complete package, except sources' installation. We recommend to "
76+
"install bison into a directory without spaces, e.g C:\\GnuWin32.")
77+
ENDIF()
78+
MESSAGE(FATAL_ERROR ${ERRMSG})
79+
ENDIF()
80+
ENDIF()
81+
ENDMACRO()

0 commit comments

Comments
 (0)