Skip to content

Commit

Permalink
初始化sqladvisor
Browse files Browse the repository at this point in the history
  • Loading branch information
longxuegang committed Mar 6, 2017
0 parents commit 49e4501
Show file tree
Hide file tree
Showing 1,359 changed files with 692,472 additions and 0 deletions.
534 changes: 534 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

339 changes: 339 additions & 0 deletions COPYING

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### 一、简介

SQLAdvisor是由美团点评公司技术工程部DBA团队(北京)开发维护的一个分析SQL给出索引优化建议的工具。它基于MySQL原生态词法解析,结合分析SQL中的where条件、聚合条件、多表Join关系 给出索引优化建议。**目前SQLAdvisor在美团点评广泛应用,包括美团支付、酒店旅游、外卖、团购等产品线,公司内部对SQLAdvisor的开发全面转到github上,开源和内部使用保持一致**

**主要功能:输出SQL索引优化建议**

### 二、SQLAdvisor详细说明

1. [SQLAdvisor快速入门教程](./doc/QUICK_START.md)
2. [SQLAdvisor用户使用手册](./doc/USER_GUIDE.md)
3. [SQLAdvisor架构和实践](./doc/THEORY_PRACTICES.md)
4. [SQLAdvisor release notes](./doc/RELEASE_NOTES.md)
5. [SQLAdvisor开发规范](./doc/DEVELOPMENT_NORM.md)
6. [FAQ](./doc/FAQ.md)

### 三、SQLAdvisor的需求及Bug反馈方式

如果用户在实际的应用场景中对SQLAdvisor有新的功能需求,或者在使用SQLAdvisor的过程中发现了bug,在github上进行交流或是PullRequest,也可以在讨论组/群进行反馈,我们会及时维护。

![QQ](./doc/img/qq.png)
4 changes: 4 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MYSQL_VERSION_MAJOR=5
MYSQL_VERSION_MINOR=6
MYSQL_VERSION_PATCH=23
MYSQL_VERSION_EXTRA=-72.1
219 changes: 219 additions & 0 deletions client/get_password.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

/*
** Ask for a password from tty
** This is an own file to avoid conflicts with curses
*/
#include <my_global.h>
#include <my_sys.h>
#include "mysql.h"
#include <m_string.h>
#include <m_ctype.h>
#include <mysql/get_password.h>

#if defined(HAVE_BROKEN_GETPASS) && !defined(HAVE_GETPASSPHRASE)
#undef HAVE_GETPASS
#endif

#ifdef HAVE_GETPASS
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif /* HAVE_PWD_H */
#else /* ! HAVE_GETPASS */
#ifndef __WIN__
#include <sys/ioctl.h>
#ifdef HAVE_TERMIOS_H /* For tty-password */
#include <termios.h>
#define TERMIO struct termios
#else
#ifdef HAVE_TERMIO_H /* For tty-password */
#include <termio.h>
#define TERMIO struct termio
#else
#include <sgtty.h>
#define TERMIO struct sgttyb
#endif
#endif
#ifdef alpha_linux_port
#include <asm/ioctls.h> /* QQ; Fix this in configure */
#include <asm/termiobits.h>
#endif
#else
#include <conio.h>
#endif /* __WIN__ */
#endif /* HAVE_GETPASS */

#ifdef HAVE_GETPASSPHRASE /* For Solaris */
#define getpass(A) getpassphrase(A)
#endif

#ifdef __WIN__
/* were just going to fake it here and get input from
the keyboard */

char *get_tty_password_ext(const char *opt_message,
strdup_handler_t strdup_function)
{
char to[80];
char *pos=to,*end=to+sizeof(to)-1;
int i=0;
DBUG_ENTER("get_tty_password_ext");
_cputs(opt_message ? opt_message : "Enter password: ");
for (;;)
{
char tmp;
tmp=_getch();
if (tmp == '\b' || (int) tmp == 127)
{
if (pos != to)
{
_cputs("\b \b");
pos--;
continue;
}
}
if (tmp == '\n' || tmp == '\r' || tmp == 3)
break;
if (iscntrl(tmp) || pos == end)
continue;
_cputs("*");
*(pos++) = tmp;
}
while (pos != to && isspace(pos[-1]) == ' ')
pos--; /* Allow dummy space at end */
*pos=0;
_cputs("\n");
DBUG_RETURN(strdup_function(to,MYF(MY_FAE)));
}

#else


#ifndef HAVE_GETPASS
/*
** Can't use fgets, because readline will get confused
** length is max number of chars in to, not counting \0
* to will not include the eol characters.
*/

static void get_password(char *to,uint length,int fd, my_bool echo)
{
char *pos=to,*end=to+length;

for (;;)
{
char tmp;
if (my_read(fd,&tmp,1,MYF(0)) != 1)
break;
if (tmp == '\b' || (int) tmp == 127)
{
if (pos != to)
{
if (echo)
{
fputs("\b \b",stderr);
fflush(stderr);
}
pos--;
continue;
}
}
if (tmp == '\n' || tmp == '\r' || tmp == 3)
break;
if (iscntrl(tmp) || pos == end)
continue;
if (echo)
{
fputc('*',stderr);
fflush(stderr);
}
*(pos++) = tmp;
}
while (pos != to && isspace(pos[-1]) == ' ')
pos--; /* Allow dummy space at end */
*pos=0;
return;
}

#endif /* ! HAVE_GETPASS */


char *get_tty_password_ext(const char *opt_message,
strdup_handler_t strdup_function)
{
#ifdef HAVE_GETPASS
char *passbuff;
#else /* ! HAVE_GETPASS */
TERMIO org,tmp;
#endif /* HAVE_GETPASS */
char buff[80];

DBUG_ENTER("get_tty_password_ext");

#ifdef HAVE_GETPASS
passbuff = getpass(opt_message ? opt_message : "Enter password: ");

/* copy the password to buff and clear original (static) buffer */
strnmov(buff, passbuff, sizeof(buff) - 1);
#ifdef _PASSWORD_LEN
memset(passbuff, 0, _PASSWORD_LEN);
#endif
#else
if (isatty(fileno(stderr)))
{
fputs(opt_message ? opt_message : "Enter password: ",stderr);
fflush(stderr);
}
#if defined(HAVE_TERMIOS_H)
tcgetattr(fileno(stdin), &org);
tmp = org;
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
tmp.c_cc[VMIN] = 1;
tmp.c_cc[VTIME] = 0;
tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stderr)));
tcsetattr(fileno(stdin), TCSADRAIN, &org);
#elif defined(HAVE_TERMIO_H)
ioctl(fileno(stdin), (int) TCGETA, &org);
tmp=org;
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
tmp.c_cc[VMIN] = 1;
tmp.c_cc[VTIME]= 0;
ioctl(fileno(stdin),(int) TCSETA, &tmp);
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr)));
ioctl(fileno(stdin),(int) TCSETA, &org);
#else
gtty(fileno(stdin), &org);
tmp=org;
tmp.sg_flags &= ~ECHO;
tmp.sg_flags |= RAW;
stty(fileno(stdin), &tmp);
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr)));
stty(fileno(stdin), &org);
#endif
if (isatty(fileno(stderr)))
fputc('\n',stderr);
#endif /* HAVE_GETPASS */

DBUG_RETURN(strdup_function(buff,MYF(MY_FAE)));
}

#endif /*__WIN__*/

char *get_tty_password(const char *opt_message)
{
return get_tty_password_ext(opt_message, my_strdup);
}
69 changes: 69 additions & 0 deletions cmake/abi_check.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#
# Headers which need to be checked for abi/api compatibility are in
# API_PREPROCESSOR_HEADER. plugin.h is tested implicitly via
# plugin_audit.h and plugin_ftparser.h.
#
# We use gcc specific preprocessing command and sed/diff, so it will
# only be run on Unix and only if gcc is used. On some Unixes,
# (Solaris) sed or diff might act differently from GNU, so we run only
# on systems we can trust.
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(RUN_ABI_CHECK 1)
ELSE()
SET(RUN_ABI_CHECK 0)
ENDIF()

IF(CMAKE_COMPILER_IS_GNUCC AND RUN_ABI_CHECK)
IF(CMAKE_C_COMPILER MATCHES "ccache$")
SET(COMPILER ${CMAKE_C_COMPILER_ARG1})
STRING(REGEX REPLACE "^ " "" COMPILER ${COMPILER})
ELSE()
SET(COMPILER ${CMAKE_C_COMPILER})
ENDIF()
SET(API_PREPROCESSOR_HEADER
${CMAKE_SOURCE_DIR}/include/mysql/plugin_audit.h
${CMAKE_SOURCE_DIR}/include/mysql/plugin_ftparser.h
${CMAKE_SOURCE_DIR}/include/mysql.h
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v0.h
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v1.h
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v2.h
${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h
${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h
)

ADD_CUSTOM_TARGET(abi_check ALL
COMMAND ${CMAKE_COMMAND}
-DCOMPILER=${COMPILER}
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
-DBINARY_DIR=${CMAKE_BINARY_DIR}
"-DABI_HEADERS=${API_PREPROCESSOR_HEADER}"
-P ${CMAKE_SOURCE_DIR}/cmake/do_abi_check.cmake
VERBATIM
)

ADD_CUSTOM_TARGET(abi_check_all
COMMAND ${CMAKE_COMMAND}
-DCOMPILER=${COMPILER}
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
-DBINARY_DIR=${CMAKE_BINARY_DIR}
"-DABI_HEADERS=${API_PREPROCESSOR_HEADER}"
-P ${CMAKE_SOURCE_DIR}/cmake/do_abi_check.cmake
VERBATIM
)
ENDIF()

81 changes: 81 additions & 0 deletions cmake/bison.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) 2009 Sun Microsystems, Inc.
# Use is subject to license terms.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
# On Solaris, /opt/csw often contains a newer bison
IF(NOT BISON_EXECUTABLE AND EXISTS /opt/csw/bin/bison)
SET(BISON_EXECUTABLE /opt/csw/bin/bison)
ENDIF()
ENDIF()
FIND_PROGRAM(BISON_EXECUTABLE bison DOC "path to the bison executable")
MARK_AS_ADVANCED(BISON_EXECUTABLE "")
IF(NOT BISON_EXECUTABLE)
MESSAGE("Warning: Bison executable not found in PATH")
ELSEIF(BISON_EXECUTABLE AND NOT BISON_USABLE)
# Check version as well
EXEC_PROGRAM(${BISON_EXECUTABLE} ARGS --version OUTPUT_VARIABLE BISON_VERSION_STR)
# Get first line in case it's multiline
STRING(REGEX REPLACE "([^\n]+).*" "\\1" FIRST_LINE "${BISON_VERSION_STR}")
# get version information
STRING(REGEX REPLACE ".* ([0-9]+)\\.([0-9]+)" "\\1" BISON_VERSION_MAJOR "${FIRST_LINE}")
STRING(REGEX REPLACE ".* ([0-9]+)\\.([0-9]+)" "\\2" BISON_VERSION_MINOR "${FIRST_LINE}")
IF (BISON_VERSION_MAJOR LESS 2)
MESSAGE("Warning: bison version is old. please update to version 2")
ELSE()
SET(BISON_USABLE 1 CACHE INTERNAL "Bison version 2 or higher")
ENDIF()
ENDIF()

# Use bison to generate C++ and header file
MACRO (RUN_BISON input_yy output_cc output_h)
IF(BISON_TOO_OLD)
IF(EXISTS ${output_cc} AND EXISTS ${output_h})
SET(BISON_USABLE FALSE)
ENDIF()
ENDIF()
IF(BISON_USABLE)
ADD_CUSTOM_COMMAND(
OUTPUT ${output_cc}
${output_h}
COMMAND ${BISON_EXECUTABLE} -y -p MYSQL
--output=${output_cc}
--defines=${output_h}
${input_yy}
DEPENDS ${input_yy}
)
ELSE()
# Bison is missing or not usable, e.g too old
IF(EXISTS ${output_cc} AND EXISTS ${output_h})
IF(${input_yy} IS_NEWER_THAN ${output_cc} OR ${input_yy} IS_NEWER_THAN ${output_h})
# Possibly timestamps are messed up in source distribution.
MESSAGE("Warning: no usable bison found, ${input_yy} will not be rebuilt.")
ENDIF()
ELSE()
# Output files are missing, bail out.
SET(ERRMSG
"Bison (GNU parser generator) is required to build MySQL."
"Please install bison."
)
IF(WIN32)
SET(ERRMSG ${ERRMSG}
"You can download bison from http://gnuwin32.sourceforge.net/packages/bison.htm "
"Choose 'Complete package, except sources' installation. We recommend to "
"install bison into a directory without spaces, e.g C:\\GnuWin32.")
ENDIF()
MESSAGE(FATAL_ERROR ${ERRMSG})
ENDIF()
ENDIF()
ENDMACRO()
Loading

0 comments on commit 49e4501

Please sign in to comment.