diff options
378 files changed, 19824 insertions, 4364 deletions
diff --git a/.bzrignore b/.bzrignore index 21383779fa7..8aa10cd116c 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1614,3 +1614,6 @@ vio/viotest-sslconnect.cpp vio/viotest.cpp zlib/*.ds? zlib/*.vcproj +libmysqld/partition_info.cc +storage/ndb/src/common/util/testBitmask.cpp +include/openssl diff --git a/VC++Files/libmysqld/libmysqld.vcproj b/VC++Files/libmysqld/libmysqld.vcproj index 8130a2c95f3..2ca2401826d 100644 --- a/VC++Files/libmysqld/libmysqld.vcproj +++ b/VC++Files/libmysqld/libmysqld.vcproj @@ -157,7 +157,7 @@ InlineFunctionExpansion="1" OptimizeForProcessor="2" AdditionalIncludeDirectories="../include,../libmysqld,../sql,../regex,../extra/yassl/include,../storage/bdb/build_win32,../zlib" - PreprocessorDefinitions="WIN32;_WINDOWS;_MBCS;NDEBUG;DBUG_OFF;USE_SYMDIR;SIGNAL_WITH_VIO_CLOSE;HAVE_DLOPEN;EMBEDDED_LIBRARY;MYSQL_SERVER;HAVE_INNOBASE_DB;WITH_INNOBASE_STORAGE_ENGINE;USE_TLS;__WIN__"/> + PreprocessorDefinitions="WIN32;_WINDOWS;_MBCS;NDEBUG;DBUG_OFF;USE_SYMDIR;SIGNAL_WITH_VIO_CLOSE;HAVE_DLOPEN;EMBEDDED_LIBRARY;MYSQL_SERVER;HAVE_INNOBASE_DB;WITH_INNOBASE_STORAGE_ENGINE;USE_TLS;__WIN__" StringPooling="TRUE" RuntimeLibrary="0" EnableFunctionLevelLinking="TRUE" diff --git a/VC++Files/mysql.sln b/VC++Files/mysql.sln index da6d1bbcc9f..f4204b00bc4 100644 --- a/VC++Files/mysql.sln +++ b/VC++Files/mysql.sln @@ -823,32 +823,21 @@ Global {62E85884-3ACF-4F4C-873B-60B878147890}.TLS_DEBUG.ActiveCfg = Debug|Win32 {62E85884-3ACF-4F4C-873B-60B878147890}.TLS_DEBUG.Build.0 = Debug|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.classic.ActiveCfg = classic|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.classic.Build.0 = classic|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.classic nt.ActiveCfg = classic|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.classic nt.Build.0 = classic|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Debug.ActiveCfg = Debug|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Debug.Build.0 = Debug|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Embedded_Classic.ActiveCfg = classic|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Embedded_Debug.ActiveCfg = Debug|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Embedded_Pro.ActiveCfg = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Embedded_ProGPL.ActiveCfg = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Embedded_Release.ActiveCfg = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Max.ActiveCfg = Release|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Max.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Max nt.ActiveCfg = Release|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Max nt.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.nt.ActiveCfg = Release|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.nt.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro.ActiveCfg = pro|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro.Build.0 = pro|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro gpl.ActiveCfg = Release|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro gpl.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro gpl nt.ActiveCfg = Release|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro gpl nt.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro nt.ActiveCfg = pro|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.pro nt.Build.0 = pro|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Release.ActiveCfg = Release|Win32 - {37D9BA79-302E-4582-A545-CB5FF7982EA3}.Release.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.TLS.ActiveCfg = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.TLS.Build.0 = Release|Win32 {37D9BA79-302E-4582-A545-CB5FF7982EA3}.TLS_DEBUG.ActiveCfg = Debug|Win32 @@ -916,32 +905,26 @@ Global {AD95DAD3-6DB9-4F8B-A345-7A39A83AAD3D}.TLS_DEBUG.ActiveCfg = Debug|Win32 {AD95DAD3-6DB9-4F8B-A345-7A39A83AAD3D}.TLS_DEBUG.Build.0 = Debug|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.classic.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.classic.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.classic nt.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.classic nt.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Debug.ActiveCfg = Debug|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.Debug.Build.0 = Debug|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Classic.ActiveCfg = Release|Win32 + {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Classic.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Debug.ActiveCfg = Debug|Win32 + {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Debug.Build.0 = Debug|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Pro.ActiveCfg = Release|Win32 + {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Pro.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_ProGPL.ActiveCfg = Release|Win32 + {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_ProGPL.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Release.ActiveCfg = Release|Win32 + {94B86159-C581-42CD-825D-C69CBC237E5C}.Embedded_Release.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Max.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.Max.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Max nt.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.Max nt.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.nt.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.nt.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.pro.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.pro.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.pro gpl.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.pro gpl.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.pro gpl nt.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.pro gpl nt.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.pro nt.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.pro nt.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.Release.ActiveCfg = Release|Win32 - {94B86159-C581-42CD-825D-C69CBC237E5C}.Release.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.TLS.ActiveCfg = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.TLS.Build.0 = Release|Win32 {94B86159-C581-42CD-825D-C69CBC237E5C}.TLS_DEBUG.ActiveCfg = Debug|Win32 diff --git a/VC++Files/mysys/mysys.vcproj b/VC++Files/mysys/mysys.vcproj index 46af0b50cef..7e010cd3786 100644 --- a/VC++Files/mysys/mysys.vcproj +++ b/VC++Files/mysys/mysys.vcproj @@ -4444,49 +4444,6 @@ </FileConfiguration> </File> <File - RelativePath="raid.cpp"> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - AdditionalIncludeDirectories="" - PreprocessorDefinitions=""/> - </FileConfiguration> - <FileConfiguration - Name="Max|Win32"> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - AdditionalIncludeDirectories="" - PreprocessorDefinitions=""/> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32"> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - AdditionalIncludeDirectories="" - PreprocessorDefinitions=""/> - </FileConfiguration> - <FileConfiguration - Name="TLS_DEBUG|Win32"> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - AdditionalIncludeDirectories="" - PreprocessorDefinitions=""/> - </FileConfiguration> - <FileConfiguration - Name="TLS|Win32"> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - AdditionalIncludeDirectories="" - PreprocessorDefinitions=""/> - </FileConfiguration> - </File> - <File RelativePath="rijndael.c"> <FileConfiguration Name="Debug|Win32"> diff --git a/VC++Files/sql/gen_lex_hash.dsp b/VC++Files/sql/gen_lex_hash.dsp new file mode 100644 index 00000000000..5cc1f70b488 --- /dev/null +++ b/VC++Files/sql/gen_lex_hash.dsp @@ -0,0 +1,98 @@ +# Microsoft Developer Studio Project File - Name="gen_lex_hash" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=gen_lex_hash - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "gen_lex_hash.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "gen_lex_hash.mak" CFG="gen_lex_hash - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "gen_lex_hash - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "gen_lex_hash - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "gen_lex_hash - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "gen_lex_hash___Win32_Release" +# PROP BASE Intermediate_Dir "gen_lex_hash___Win32_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "gen_lex_hash___Win32_Release" +# PROP Intermediate_Dir "gen_lex_hash___Win32_Release" +# PROP Target_Dir "" +MTL=midl.exe +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x419 /d "NDEBUG" +# ADD RSC /l 0x419 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "gen_lex_hash - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +MTL=midl.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x419 /d "_DEBUG" +# ADD RSC /l 0x419 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "gen_lex_hash - Win32 Release" +# Name "gen_lex_hash - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/VC++Files/sql/gen_lex_hash.vcproj b/VC++Files/sql/gen_lex_hash.vcproj new file mode 100644 index 00000000000..3f600f34cfb --- /dev/null +++ b/VC++Files/sql/gen_lex_hash.vcproj @@ -0,0 +1,158 @@ +<?xml version="1.0" encoding="windows-1251"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="gen_lex_hash" + ProjectGUID="{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}" + SccProjectName="" + SccLocalPath=""> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory=".\Debug" + IntermediateDirectory=".\Debug" + ConfigurationType="1" + UseOfMFC="0" + ATLMinimizesCRunTimeLibraryUsage="FALSE" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../include" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="2" + PrecompiledHeaderFile=".\Debug/gen_lex_hash.pch" + AssemblerListingLocation=".\Debug/" + ObjectFile=".\Debug/" + ProgramDataBaseFileName=".\Debug/" + WarningLevel="3" + SuppressStartupBanner="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="Ws2_32.lib" + OutputFile="../sql/gen_lex_hash.exe" + LinkIncremental="1" + SuppressStartupBanner="TRUE" + AdditionalLibraryDirectories="../lib_release" + GenerateDebugInformation="TRUE" + ProgramDatabaseFile=".\Debug/gen_lex_hash.pdb" + SubSystem="1" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool" + TypeLibraryName=".\Debug/gen_lex_hash.tlb" + HeaderFileName=""/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool" + PreprocessorDefinitions="_DEBUG" + Culture="1049"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory=".\gen_lex_hash___Win32_Release" + IntermediateDirectory=".\gen_lex_hash___Win32_Release" + ConfigurationType="1" + UseOfMFC="0" + ATLMinimizesCRunTimeLibraryUsage="FALSE" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="1" + AdditionalIncludeDirectories="../include" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + StringPooling="TRUE" + RuntimeLibrary="0" + EnableFunctionLevelLinking="TRUE" + UsePrecompiledHeader="2" + PrecompiledHeaderFile=".\gen_lex_hash___Win32_Release/gen_lex_hash.pch" + AssemblerListingLocation=".\gen_lex_hash___Win32_Release/" + ObjectFile=".\gen_lex_hash___Win32_Release/" + ProgramDataBaseFileName=".\gen_lex_hash___Win32_Release/" + WarningLevel="3" + SuppressStartupBanner="TRUE"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="Ws2_32.lib" + OutputFile="../sql/gen_lex_hash.exe" + LinkIncremental="1" + SuppressStartupBanner="TRUE" + AdditionalLibraryDirectories="../lib_release" + ProgramDatabaseFile=".\gen_lex_hash___Win32_Release/gen_lex_hash.pdb" + SubSystem="1" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool" + TypeLibraryName=".\gen_lex_hash___Win32_Release/gen_lex_hash.tlb" + HeaderFileName=""/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool" + PreprocessorDefinitions="NDEBUG" + Culture="1049"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"> + <File + RelativePath=".\gen_lex_hash.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl"> + </Filter> + <Filter + Name="Resource Files" + Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/VC++Files/sql/mysqld.vcproj b/VC++Files/sql/mysqld.vcproj index 94b9f68b2f7..ea617e4f413 100644 --- a/VC++Files/sql/mysqld.vcproj +++ b/VC++Files/sql/mysqld.vcproj @@ -4527,6 +4527,81 @@ </FileConfiguration> </File> <File + RelativePath="partition_info.cpp"> + <FileConfiguration + Name="classic nt|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="Max|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="Max nt|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="nt|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="pro nt|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="pro|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="classic|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + AdditionalIncludeDirectories="" + PreprocessorDefinitions=""/> + </FileConfiguration> + </File> + <File RelativePath="parse_file.cpp"> <FileConfiguration Name="classic nt|Win32"> diff --git a/VC++Files/storage/example/example.vcproj b/VC++Files/storage/example/example.vcproj index 3a2daa55676..257a1e77b71 100644 --- a/VC++Files/storage/example/example.vcproj +++ b/VC++Files/storage/example/example.vcproj @@ -24,7 +24,7 @@ InlineFunctionExpansion="1" OptimizeForProcessor="2" AdditionalIncludeDirectories="../../include,../../regex,../../sql" - PreprocessorDefinitions="DBUG_OFF;_WINDOWS;NDEBUG" + PreprocessorDefinitions="DBUG_OFF;_WINDOWS;NDEBUG;WITH_PARTITION_STORAGE_ENGINE" StringPooling="TRUE" RuntimeLibrary="0" EnableFunctionLevelLinking="TRUE" @@ -73,7 +73,7 @@ Optimization="0" OptimizeForProcessor="2" AdditionalIncludeDirectories="../../include,../../regex,../../sql" - PreprocessorDefinitions="_DEBUG;SAFEMALLOC;SAFE_MUTEX;_WINDOWS;USE_TLS" + PreprocessorDefinitions="_DEBUG;SAFEMALLOC;SAFE_MUTEX;_WINDOWS;USE_TLS;WITH_PARTITION_STORAGE_ENGINE" StringPooling="TRUE" RuntimeLibrary="1" PrecompiledHeaderFile=".\example___Win32_TLS_DEBUG/example.pch" @@ -123,7 +123,7 @@ InlineFunctionExpansion="1" OptimizeForProcessor="2" AdditionalIncludeDirectories="../../include,../../regex,../../sql" - PreprocessorDefinitions="DBUG_OFF;_WINDOWS;NDEBUG;USE_TLS" + PreprocessorDefinitions="DBUG_OFF;_WINDOWS;NDEBUG;USE_TLS;WITH_PARTITION_STORAGE_ENGINE" StringPooling="TRUE" RuntimeLibrary="0" EnableFunctionLevelLinking="TRUE" @@ -172,7 +172,7 @@ Optimization="0" OptimizeForProcessor="2" AdditionalIncludeDirectories="../../include,../../regex,../../sql" - PreprocessorDefinitions="_DEBUG;SAFEMALLOC;SAFE_MUTEX;_WINDOWS" + PreprocessorDefinitions="_DEBUG;SAFEMALLOC;SAFE_MUTEX;_WINDOWS;WITH_PARTITION_STORAGE_ENGINE" StringPooling="TRUE" RuntimeLibrary="1" PrecompiledHeaderFile=".\debug/example.pch" diff --git a/client/Makefile.am b/client/Makefile.am index d95b4e39c6a..af7c3d2a549 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -21,17 +21,21 @@ if HAVE_YASSL else yassl_dummy_link_fix= endif + +if THREAD_SAFE_CLIENT +LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql_r/libmysqlclient_r.la +else +LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql/libmysqlclient.la +endif + #AUTOMAKE_OPTIONS = nostdinc INCLUDES = -I$(top_builddir)/include \ -I$(top_srcdir)/include \ -I$(top_srcdir)/regex \ - $(openssl_includes) $(yassl_includes) + $(openssl_includes) $(yassl_includes) LIBS = @CLIENT_LIBS@ LDADD= @CLIENT_EXTRA_LDFLAGS@ $(CLIENT_THREAD_LIBS) \ - $(top_builddir)/libmysql/libmysqlclient.la -LDADD_R= @CLIENT_EXTRA_LDFLAGS@ \ - $(CLIENT_THREAD_LIBS) \ - $(top_builddir)/libmysql_r/libmysqlclient_r.la + $(top_builddir)/libmysql/libmysqlclient.la bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \ mysqldump mysqlimport mysqltest mysqlbinlog \ mysqltestmanagerc mysqltestmanager-pwgen \ @@ -41,8 +45,8 @@ noinst_HEADERS = sql_string.h completion_hash.h my_readline.h \ mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc mysqladmin_SOURCES = mysqladmin.cc mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS) -mysqltest_SOURCES= mysqltest.c $(top_srcdir)/mysys/my_getsystime.c \ - $(yassl_dummy_link_fix) +mysqltest_SOURCES= mysqltest.c $(top_srcdir)/mysys/my_getsystime.c \ + $(yassl_dummy_link_fix) mysqltest_LDADD = $(top_builddir)/regex/libregex.a $(LDADD) mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c \ $(top_srcdir)/mysys/my_new.cc \ @@ -51,18 +55,22 @@ mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c \ $(top_srcdir)/mysys/my_vle.c \ $(top_srcdir)/mysys/base64.c mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS) -mysqlslap_LDADD = $(CXXLDFLAGS) $(LDADD_R) \ - $(top_builddir)/mysys/libmysys.a -mysqlimport_LDADD = $(CXXLDFLAGS) $(LDADD_R) \ - $(top_builddir)/mysys/libmysys.a -mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c -mysqltestmanagerc_SOURCES= mysqlmanagerc.c $(yassl_dummy_link_fix) -mysqlcheck_SOURCES= mysqlcheck.c $(yassl_dummy_link_fix) -mysqlshow_SOURCES= mysqlshow.c $(yassl_dummy_link_fix) -mysqlslap_SOURCES= mysqlslap.c \ +mysqlslap_LDADD = $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \ + @CLIENT_EXTRA_LDFLAGS@ \ + $(LIBMYSQLCLIENT_LA) \ + $(top_builddir)/mysys/libmysys.a +mysqlimport_LDADD = $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \ + @CLIENT_EXTRA_LDFLAGS@ \ + $(LIBMYSQLCLIENT_LA) \ + $(top_builddir)/mysys/libmysys.a +mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c +mysqltestmanagerc_SOURCES= mysqlmanagerc.c $(yassl_dummy_link_fix) +mysqlcheck_SOURCES= mysqlcheck.c $(yassl_dummy_link_fix) +mysqlshow_SOURCES= mysqlshow.c $(yassl_dummy_link_fix) +mysqlslap_SOURCES= mysqlslap.c \ $(yassl_dummy_link_fix) -mysqldump_SOURCES= mysqldump.c my_user.c $(yassl_dummy_link_fix) -mysqlimport_SOURCES= mysqlimport.c \ +mysqldump_SOURCES= mysqldump.c my_user.c $(yassl_dummy_link_fix) +mysqlimport_SOURCES= mysqlimport.c \ $(yassl_dummy_link_fix) sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc strings_src=decimal.c diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 96792d0ffcb..490a74e6035 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1497,7 +1497,7 @@ int main(int argc, char** argv) the server */ -#ifdef __WIN__ +#if defined(__WIN__) && !defined(USING_CMAKE) #include "my_decimal.h" #include "decimal.c" #include "my_decimal.cpp" diff --git a/client/mysqldump.c b/client/mysqldump.c index 6c8bbca2723..7dccbf95e20 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -860,6 +860,27 @@ static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res, return 0; } +/* + Open a new .sql file to dump the table or view into + + SYNOPSIS + open_sql_file_for_table + name name of the table or view + + RETURN VALUES + 0 Failed to open file + > 0 Handle of the open file +*/ +static FILE* open_sql_file_for_table(const char* table) +{ + FILE* res; + char filename[FN_REFLEN], tmp_path[FN_REFLEN]; + convert_dirname(tmp_path,path,NullS); + res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), + O_WRONLY, MYF(MY_WME)); + return res; +} + static void safe_exit(int error) { @@ -1411,11 +1432,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (path) { - char filename[FN_REFLEN], tmp_path[FN_REFLEN]; - convert_dirname(tmp_path,path,NullS); - sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), - O_WRONLY, MYF(MY_WME)); - if (!sql_file) /* If file couldn't be opened */ + if (!(sql_file= open_sql_file_for_table(table))) { safe_exit(EX_MYSQLERR); DBUG_RETURN(0); @@ -1580,11 +1597,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (path) { - char filename[FN_REFLEN], tmp_path[FN_REFLEN]; - convert_dirname(tmp_path,path,NullS); - sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), - O_WRONLY, MYF(MY_WME)); - if (!sql_file) /* If file couldn't be opened */ + if (!(sql_file= open_sql_file_for_table(table))) { safe_exit(EX_MYSQLERR); DBUG_RETURN(0); @@ -3346,6 +3359,41 @@ cleanup: /* + Replace a substring + + SYNOPSIS + replace + ds_str The string to search and perform the replace in + search_str The string to search for + search_len Length of the string to search for + replace_str The string to replace with + replace_len Length of the string to replace with + + RETURN + 0 String replaced + 1 Could not find search_str in str +*/ + +static int replace(DYNAMIC_STRING *ds_str, + const char *search_str, ulong search_len, + const char *replace_str, ulong replace_len) +{ + DYNAMIC_STRING ds_tmp; + const char *start= strstr(ds_str->str, search_str); + if (!start) + return 1; + init_dynamic_string(&ds_tmp, "", + ds_str->length + replace_len, 256); + dynstr_append_mem(&ds_tmp, ds_str->str, start - ds_str->str); + dynstr_append_mem(&ds_tmp, replace_str, replace_len); + dynstr_append(&ds_tmp, start + search_len); + dynstr_set(ds_str, ds_tmp.str); + dynstr_free(&ds_tmp); + return 0; +} + + +/* Getting VIEW structure SYNOPSIS @@ -3366,11 +3414,11 @@ static my_bool get_view_structure(char *table, char* db) char *result_table, *opt_quoted_table; char table_buff[NAME_LEN*2+3]; char table_buff2[NAME_LEN*2+3]; - char buff[20+FN_REFLEN]; + char query[QUERY_LENGTH]; FILE *sql_file = md_result_file; DBUG_ENTER("get_view_structure"); - if (tFlag) + if (tFlag) /* Don't write table creation info */ DBUG_RETURN(0); if (verbose) @@ -3384,36 +3432,32 @@ static my_bool get_view_structure(char *table, char* db) result_table= quote_name(table, table_buff, 1); opt_quoted_table= quote_name(table, table_buff2, 0); - sprintf(buff,"show create table %s", result_table); - if (mysql_query(sock, buff)) + my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %s", result_table); + if (mysql_query_with_error_report(sock, &table_res, query)) { - fprintf(stderr, "%s: Can't get CREATE TABLE for view %s (%s)\n", - my_progname, result_table, mysql_error(sock)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } + /* Check if this is a view */ + field= mysql_fetch_field_direct(table_res, 0); + if (strcmp(field->name, "View") != 0) + { + if (verbose) + fprintf(stderr, "-- It's base table, skipped\n"); + DBUG_RETURN(0); + } + + /* If requested, open separate .sql file for this view */ if (path) { - char filename[FN_REFLEN], tmp_path[FN_REFLEN]; - convert_dirname(tmp_path,path,NullS); - sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), - O_WRONLY, MYF(MY_WME)); - if (!sql_file) /* If file couldn't be opened */ + if (!(sql_file= open_sql_file_for_table(table))) { safe_exit(EX_MYSQLERR); DBUG_RETURN(1); } write_header(sql_file, db); } - table_res= mysql_store_result(sock); - field= mysql_fetch_field_direct(table_res, 0); - if (strcmp(field->name, "View") != 0) - { - if (verbose) - fprintf(stderr, "-- It's base table, skipped\n"); - DBUG_RETURN(0); - } if (!opt_xml && opt_comments) { @@ -3430,11 +3474,102 @@ static my_bool get_view_structure(char *table, char* db) check_io(sql_file); } - row= mysql_fetch_row(table_res); - fprintf(sql_file, "/*!50001 %s*/;\n", row[1]); - check_io(sql_file); - mysql_free_result(table_res); + my_snprintf(query, sizeof(query), + "SELECT CHECK_OPTION, DEFINER, SECURITY_TYPE " \ + "FROM information_schema.views " \ + "WHERE table_name=\"%s\" AND table_schema=\"%s\"", table, db); + if (mysql_query(sock, query)) + { + /* + Use the raw output from SHOW CREATE TABLE if + information_schema query fails. + */ + row= mysql_fetch_row(table_res); + fprintf(sql_file, "/*!50001 %s */;\n", row[1]); + check_io(sql_file); + mysql_free_result(table_res); + } + else + { + char *ptr; + ulong *lengths; + char search_buf[256], replace_buf[256]; + ulong search_len, replace_len; + DYNAMIC_STRING ds_view; + + /* Save the result of SHOW CREATE TABLE in ds_view */ + row= mysql_fetch_row(table_res); + lengths= mysql_fetch_lengths(table_res); + init_dynamic_string(&ds_view, row[1], lengths[1] + 1, 1024); + mysql_free_result(table_res); + + /* Get the result from "select ... information_schema" */ + if (!(table_res= mysql_store_result(sock))) + { + safe_exit(EX_MYSQLERR); + DBUG_RETURN(1); + } + row= mysql_fetch_row(table_res); + lengths= mysql_fetch_lengths(table_res); + + /* + "WITH %s CHECK OPTION" is available from 5.0.2 + Surround it with !50002 comments + */ + if (strcmp(row[0], "NONE")) + { + + ptr= search_buf; + search_len= (ulong)(strxmov(ptr, "WITH ", row[0], + " CHECK OPTION", NullS) - ptr); + ptr= replace_buf; + replace_len=(ulong)(strxmov(ptr, "*/\n/*!50002 WITH ", row[0], + " CHECK OPTION", NullS) - ptr); + replace(&ds_view, search_buf, search_len, replace_buf, replace_len); + } + + /* + "DEFINER=%s SQL SECURITY %s" is available from 5.0.13 + Surround it with !50013 comments + */ + { + uint user_name_len; + char user_name_str[USERNAME_LENGTH + 1]; + char quoted_user_name_str[USERNAME_LENGTH * 2 + 3]; + uint host_name_len; + char host_name_str[HOSTNAME_LENGTH + 1]; + char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3]; + + parse_user(row[1], lengths[1], user_name_str, &user_name_len, + host_name_str, &host_name_len); + + ptr= search_buf; + search_len= + (ulong)(strxmov(ptr, "DEFINER=", + quote_name(user_name_str, quoted_user_name_str, FALSE), + "@", + quote_name(host_name_str, quoted_host_name_str, FALSE), + " SQL SECURITY ", row[2], NullS) - ptr); + ptr= replace_buf; + replace_len= + (ulong)(strxmov(ptr, "*/\n/*!50013 DEFINER=", + quote_name(user_name_str, quoted_user_name_str, FALSE), + "@", + quote_name(host_name_str, quoted_host_name_str, FALSE), + " SQL SECURITY ", row[2], + " */\n/*!50001", NullS) - ptr); + replace(&ds_view, search_buf, search_len, replace_buf, replace_len); + } + + /* Dump view structure to file */ + fprintf(sql_file, "/*!50001 %s */;\n", ds_view.str); + check_io(sql_file); + mysql_free_result(table_res); + dynstr_free(&ds_view); + } + + /* If a separate .sql file was opened, close it now */ if (sql_file != md_result_file) { fputs("\n", sql_file); diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 81040bed993..42d521a1412 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -29,12 +29,16 @@ #include "client_priv.h" #include "mysql_version.h" +#ifdef HAVE_LIBPTHREAD #include <my_pthread.h> +#endif /* Global Thread counter */ int counter= 0; +#ifdef HAVE_LIBPTHREAD pthread_mutex_t counter_mutex; +#endif static void db_error_with_table(MYSQL *mysql, char *table); static void db_error(MYSQL *mysql); @@ -516,6 +520,7 @@ static char *field_escape(char *to,const char *from,uint length) int exitcode= 0; +#ifdef HAVE_LIBPTHREAD pthread_handler_t worker_thread(void *arg) { int error; @@ -554,6 +559,7 @@ error: return 0; } +#endif int main(int argc, char **argv) @@ -571,6 +577,7 @@ int main(int argc, char **argv) return(1); } +#ifdef HAVE_LIBPTHREAD if (opt_use_threads && !lock_tables) { pthread_t mainthread; /* Thread descriptor */ @@ -621,6 +628,7 @@ loop_label: VOID(pthread_mutex_destroy(&counter_mutex)); } else +#endif { MYSQL *mysql= 0; if (!(mysql= db_connect(current_host,current_db,current_user,opt_password))) diff --git a/client/mysqlslap.c b/client/mysqlslap.c index 44b2d1b5afb..23eba64c332 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -76,7 +76,9 @@ TODO: #define RAND_STRING_SIZE 126 #include "client_priv.h" +#ifdef HAVE_LIBPTHREAD #include <my_pthread.h> +#endif #include <my_sys.h> #include <m_string.h> #include <mysql.h> @@ -987,6 +989,7 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit) exit(0); } +#ifdef HAVE_LIBPTHREAD if (opt_use_threads) { pthread_t mainthread; /* Thread descriptor */ @@ -1008,8 +1011,11 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit) } } } +#endif #ifndef __WIN__ +#ifdef HAVE_LIBPTHREAD else +#endif { fflush(NULL); for (x= 0; x < concur; x++) @@ -1080,6 +1086,9 @@ WAIT: int status, pid; pid= wait(&status); DBUG_PRINT("info", ("Parent: child %d status %d", pid, status)); + if (status != 0) + printf("%s: Child %d died with the status %d\n", + my_progname, pid, status); } } #endif @@ -1116,11 +1125,11 @@ run_task(thread_context *con) DBUG_PRINT("info", ("trying to connect to host %s as user %s", host, user)); lock_file= my_open(lock_file_str, O_RDWR, MYF(0)); my_lock(lock_file, F_RDLCK, 0, F_TO_EOF, MYF(0)); - if (!opt_only_print) + if (!opt_only_print) { - if (!(mysql= mysql_real_connect(NULL, host, user, opt_password, - create_schema_string, - opt_mysql_port, + if (!(mysql= mysql_real_connect(mysql, host, user, opt_password, + create_schema_string, + opt_mysql_port, opt_mysql_unix_port, 0))) { @@ -1130,12 +1139,12 @@ run_task(thread_context *con) } DBUG_PRINT("info", ("connected.")); - queries= 0; + queries= 0; limit_not_met: for (ptr= con->stmt; ptr && ptr->length; ptr= ptr->next) { - if (opt_only_print) + if (opt_only_print) { printf("%.*s;\n", (uint)ptr->length, ptr->string); } diff --git a/client/mysqltest.c b/client/mysqltest.c index 94b5171be6a..46ec59e25c9 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -74,7 +74,6 @@ #define MAX_QUERY (256*1024) #define MAX_VAR_NAME 256 #define MAX_COLUMNS 256 -#define PAD_SIZE 128 #define MAX_CONS 128 #define MAX_INCLUDE_DEPTH 16 #define INIT_Q_LINES 1024 @@ -116,8 +115,8 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD, The list of error codes to --error are stored in an internal array of structs. This struct can hold numeric SQL error codes or SQLSTATE codes as strings. The element next to the last active element in the list is - set to type ERR_EMPTY. When an SQL statement return an error we use - this list to check if this is an expected error. + set to type ERR_EMPTY. When an SQL statement returns an error, we use + this list to check if this is an expected error. */ enum match_err_type @@ -309,18 +308,6 @@ typedef struct char *env_s; } VAR; -#if defined(__NETWARE__) || defined(__WIN__) -/* - Netware doesn't proved environment variable substitution that is done - by the shell in unix environments. We do this in the following function: -*/ - -static char *subst_env_var(const char *cmd); -static FILE *my_popen(const char *cmd, const char *mode); -#undef popen -#define popen(A,B) my_popen((A),(B)) -#endif /* __NETWARE__ */ - VAR var_reg[10]; /*Perl/shell-like variable registers */ HASH var_hash; @@ -393,13 +380,6 @@ const char *command_names[]= "connection", "query", "connect", - /* the difference between sleep and real_sleep is that sleep will use - the delay from command line (--sleep) if there is one. - real_sleep always uses delay from mysqltest's command line argument. - the logic is that sometimes delays are cpu-dependent (and --sleep - can be used to set this delay. real_sleep is used for cpu-independent - delays - */ "sleep", "real_sleep", "inc", @@ -501,20 +481,21 @@ typedef struct st_pointer_array { /* when using array-strings */ struct st_replace; struct st_replace *init_replace(my_string *from, my_string *to, uint count, my_string word_end_chars); -uint replace_strings(struct st_replace *rep, my_string *start, - uint *max_length, const char *from); void free_replace(); static void free_replace_regex(); static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name); +static void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds, + const char *from, int len); void free_pointer_array(POINTER_ARRAY *pa); -static int initialize_replace_buffer(void); -static void do_eval(DYNAMIC_STRING *query_eval, const char *query); +static void do_eval(DYNAMIC_STRING *query_eval, const char *query, + my_bool pass_through_escape_chars); static void str_to_file(const char *fname, char *str, int size); -int do_server_op(struct st_query *q,const char *op); + +#ifdef __WIN__ +static void free_win_path_patterns(); +#endif struct st_replace *glob_replace; -static char *out_buff; -static uint out_length; static int eval_result = 0; /* For column replace */ @@ -539,10 +520,11 @@ static void handle_error(const char *query, struct st_query *q, const char *err_sqlstate, DYNAMIC_STRING *ds); static void handle_no_error(struct st_query *q); -static void do_eval(DYNAMIC_STRING* query_eval, const char *query) +static void do_eval(DYNAMIC_STRING* query_eval, const char *query, + my_bool pass_through_escape_chars) { const char *p; - register char c; + register char c, next_c; register int escaped = 0; VAR* v; DBUG_ENTER("do_eval"); @@ -564,13 +546,25 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query) } break; case '\\': + next_c= *(p+1); if (escaped) { escaped = 0; dynstr_append_mem(query_eval, p, 1); } - else + else if (next_c == '\\' || next_c == '$') + { + /* Set escaped only if next char is \ or $ */ escaped = 1; + + if (pass_through_escape_chars) + { + /* The escape char should be added to the output string. */ + dynstr_append_mem(query_eval, p, 1); + } + } + else + dynstr_append_mem(query_eval, p, 1); break; default: dynstr_append_mem(query_eval, p, 1); @@ -646,6 +640,9 @@ static void free_used_memory() free_defaults(default_argv); mysql_server_end(); free_re(); +#ifdef __WIN__ + free_win_path_patterns(); +#endif DBUG_VOID_RETURN; } @@ -754,7 +751,7 @@ static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) init_dynamic_string(&res_ds, "", 0, 65536); if (eval_result) { - do_eval(&res_ds, tmp); + do_eval(&res_ds, tmp, FALSE); res_ptr = res_ds.str; if ((res_len = res_ds.length) != ds->length) { @@ -1031,17 +1028,7 @@ int do_require_manager(struct st_query *query __attribute__((unused)) ) } #ifndef EMBEDDED_LIBRARY -int do_server_start(struct st_query *q) -{ - return do_server_op(q, "start"); -} - -int do_server_stop(struct st_query *q) -{ - return do_server_op(q, "stop"); -} - -int do_server_op(struct st_query *q, const char *op) +static int do_server_op(struct st_query *q, const char *op) { char *p= q->first_argument; char com_buf[256], *com_p; @@ -1071,6 +1058,17 @@ int do_server_op(struct st_query *q, const char *op) q->last_argument= p; return 0; } + +int do_server_start(struct st_query *q) +{ + return do_server_op(q, "start"); +} + +int do_server_stop(struct st_query *q) +{ + return do_server_op(q, "stop"); +} + #endif @@ -1100,8 +1098,8 @@ int do_source(struct st_query *query) *p++= 0; query->last_argument= p; /* - If this file has already been sourced, dont source it again. - It's already available in the q_lines cache + If this file has already been sourced, don't source it again. + It's already available in the q_lines cache. */ if (parser.current_line < (parser.read_lines - 1)) return 0; @@ -1124,16 +1122,21 @@ int do_source(struct st_query *query) expected error array, previously set with the --error command. It can thus be used to execute a command that shall fail. + NOTE + Although mysqltest is executed from cygwin shell, the command will be + executed in "cmd.exe". Thus commands like "rm" etc can NOT be used, use + system for those commands. */ static void do_exec(struct st_query *query) { int error; - DYNAMIC_STRING *ds= NULL; char buf[1024]; FILE *res_file; char *cmd= query->first_argument; + DYNAMIC_STRING ds_cmd; DBUG_ENTER("do_exec"); + DBUG_PRINT("enter", ("cmd: '%s'", cmd)); while (*cmd && my_isspace(charset_info, *cmd)) cmd++; @@ -1141,24 +1144,28 @@ static void do_exec(struct st_query *query) die("Missing argument in exec"); query->last_argument= query->end; - DBUG_PRINT("info", ("Executing '%s'", cmd)); + init_dynamic_string(&ds_cmd, 0, strlen(cmd)+256, 256); + /* Eval the command, thus replacing all environment variables */ + do_eval(&ds_cmd, cmd, TRUE); + cmd= ds_cmd.str; + + DBUG_PRINT("info", ("Executing '%s' as '%s'", + query->first_argument, cmd)); if (!(res_file= popen(cmd, "r")) && query->abort_on_error) - die("popen(\"%s\", \"r\") failed", cmd); + die("popen(\"%s\", \"r\") failed", query->first_argument); - if (disable_result_log) + while (fgets(buf, sizeof(buf), res_file)) { - while (fgets(buf, sizeof(buf), res_file)) + if (disable_result_log) { buf[strlen(buf)-1]=0; DBUG_PRINT("exec_result",("%s", buf)); } - } - else - { - ds= &ds_res; - while (fgets(buf, sizeof(buf), res_file)) - replace_dynstr_append(ds, buf); + else + { + replace_dynstr_append(&ds_res, buf); + } } error= pclose(res_file); if (error != 0) @@ -1167,7 +1174,7 @@ static void do_exec(struct st_query *query) my_bool ok= 0; if (query->abort_on_error) - die("command \"%s\" failed", cmd); + die("command \"%s\" failed", query->first_argument); DBUG_PRINT("info", ("error: %d, status: %d", error, status)); @@ -1182,19 +1189,19 @@ static void do_exec(struct st_query *query) { ok= 1; DBUG_PRINT("info", ("command \"%s\" failed with expected error: %d", - cmd, status)); + query->first_argument, status)); } } if (!ok) die("command \"%s\" failed with wrong error: %d", - cmd, status); + query->first_argument, status); } else if (query->expected_errno[0].type == ERR_ERRNO && query->expected_errno[0].code.errnum != 0) { /* Error code we wanted was != 0, i.e. not an expected success */ die("command \"%s\" succeeded - should have failed with errno %d...", - cmd, query->expected_errno[0].code.errnum); + query->first_argument, query->expected_errno[0].code.errnum); } free_replace(); @@ -1406,38 +1413,49 @@ int do_modify_var(struct st_query *query, const char *name, } -int do_system(struct st_query *q) +/* + + SYNOPSIS + do_system + command called command + + DESCRIPTION + system <command> + + Eval the query to expand any $variables in the command. + Execute the command with the "system" command. + + NOTE + If mysqltest is executed from cygwin shell, the command will be + executed in cygwin shell. Thus commands like "rm" etc can be used. + */ + +int do_system(struct st_query *command) { - DYNAMIC_STRING *ds; - char *p=q->first_argument; - VAR v; - var_init(&v, 0, 0, 0, 0); - eval_expr(&v, p, 0); /* NULL terminated */ - ds= &ds_res; + DYNAMIC_STRING ds_cmd; + + if (strlen(command->first_argument) == 0) + die("Missing arguments to system, nothing to do!"); - if (v.str_val_len) + init_dynamic_string(&ds_cmd, 0, strlen(command->first_argument) + 64, 256); + + /* Eval the system command, thus replacing all environment variables */ + do_eval(&ds_cmd, command->first_argument, TRUE); + + DBUG_PRINT("info", ("running system command '%s' as '%s'", + command->first_argument, ds_cmd.str)); + if (system(ds_cmd.str)) { - char expr_buf[1024]; - if ((uint)v.str_val_len > sizeof(expr_buf) - 1) - v.str_val_len = sizeof(expr_buf) - 1; - memcpy(expr_buf, v.str_val, v.str_val_len); - expr_buf[v.str_val_len] = 0; - DBUG_PRINT("info", ("running system command '%s'", expr_buf)); - if (system(expr_buf)) - { - if (q->abort_on_error) - die("system command '%s' failed", expr_buf); + if (command->abort_on_error) + die("system command '%s' failed", command->first_argument); - /* If ! abort_on_error, log message and continue */ - dynstr_append(ds, "system command '"); - replace_dynstr_append(ds, expr_buf); - dynstr_append(ds, "' failed\n"); - } + /* If ! abort_on_error, log message and continue */ + dynstr_append(&ds_res, "system command '"); + replace_dynstr_append(&ds_res, command->first_argument); + dynstr_append(&ds_res, "' failed\n"); } - else - die("Missing arguments to system, nothing to do!"); - var_free(&v); - q->last_argument= q->end; + + command->last_argument= command->end; return 0; } @@ -1473,7 +1491,7 @@ int do_echo(struct st_query *command) ds= &ds_res; init_dynamic_string(&ds_echo, "", 256, 256); - do_eval(&ds_echo, command->first_argument); + do_eval(&ds_echo, command->first_argument, FALSE); dynstr_append_mem(ds, ds_echo.str, ds_echo.length); dynstr_append_mem(ds, "\n", 1); dynstr_free(&ds_echo); @@ -1756,11 +1774,19 @@ int do_disable_rpl_parse(struct st_query *query __attribute__((unused))) do_sleep() q called command real_sleep use the value from opt_sleep as number of seconds to sleep + if real_sleep is false DESCRIPTION sleep <seconds> - real_sleep - + real_sleep <seconds> + + The difference between the sleep and real_sleep commands is that sleep + uses the delay from the --sleep command-line option if there is one. + (If the --sleep option is not given, the sleep command uses the delay + specified by its argument.) The real_sleep command always uses the + delay specified by its argument. The logic is that sometimes delays are + cpu-dependent, and --sleep can be used to set this delay. real_sleep is + used for cpu-independent delays. */ int do_sleep(struct st_query *query, my_bool real_sleep) @@ -1769,18 +1795,19 @@ int do_sleep(struct st_query *query, my_bool real_sleep) char *p= query->first_argument; char *sleep_start, *sleep_end= query->end; double sleep_val; + char *cmd = (real_sleep ? "real_sleep" : "sleep"); while (my_isspace(charset_info, *p)) p++; if (!*p) - die("Missing argument to sleep"); + die("Missing argument to %s", cmd); sleep_start= p; /* Check that arg starts with a digit, not handled by my_strtod */ if (!my_isdigit(charset_info, *sleep_start)) - die("Invalid argument to sleep \"%s\"", query->first_argument); + die("Invalid argument to %s \"%s\"", cmd, query->first_argument); sleep_val= my_strtod(sleep_start, &sleep_end, &error); if (error) - die("Invalid argument to sleep \"%s\"", query->first_argument); + die("Invalid argument to %s \"%s\"", cmd, query->first_argument); /* Fixed sleep time selected by --sleep option */ if (opt_sleep && !real_sleep) @@ -2205,8 +2232,7 @@ static void get_replace(struct st_query *q) if (!(glob_replace=init_replace((char**) from_array.typelib.type_names, (char**) to_array.typelib.type_names, (uint) from_array.typelib.count, - word_end_chars)) || - initialize_replace_buffer()) + word_end_chars))) die("Can't initialize replace from '%s'", q->query); free_pointer_array(&from_array); free_pointer_array(&to_array); @@ -2234,7 +2260,6 @@ void free_replace() { my_free((char*) glob_replace,MYF(0)); glob_replace=0; - my_free(out_buff,MYF(MY_WME)); } DBUG_VOID_RETURN; } @@ -2434,7 +2459,7 @@ int safe_connect(MYSQL* mysql, const char *host, const char *user, /* - Connect to a server and handle connection errors in case when they occur. + Connect to a server and handle connection errors in case they occur. SYNOPSIS connect_n_handle_errors() @@ -2804,7 +2829,6 @@ int do_block(enum block_cmd cmd, struct st_query* q) var_free(&v); DBUG_VOID_RETURN; - return 0; } @@ -2871,7 +2895,7 @@ my_bool end_of_query(int c) Normally that means it will read lines until it reaches the "delimiter" that marks end of query. Default delimiter is ';' The function should be smart enough not to detect delimiter's - found inside strings sorrounded with '"' and '\'' escaped strings. + found inside strings surrounded with '"' and '\'' escaped strings. If the first line in a query starts with '#' or '-' this line is treated as a comment. A comment is always terminated when end of line '\n' is @@ -3099,7 +3123,7 @@ int read_query(struct st_query** q_ptr) check_eol_junk(read_query_buf); DBUG_RETURN(1); } - + DBUG_PRINT("info", ("query: %s", read_query_buf)); if (*p == '#') { @@ -3156,6 +3180,9 @@ static struct my_option my_long_options[] = {"compress", 'C', "Use the compressed server/client protocol.", (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"cursor-protocol", OPT_CURSOR_PROTOCOL, "Use cursors for prepared statements.", + (gptr*) &cursor_protocol, (gptr*) &cursor_protocol, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"database", 'D', "Database to use.", (gptr*) &db, (gptr*) &db, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #ifdef DBUG_OFF @@ -3190,15 +3217,6 @@ static struct my_option my_long_options[] = {"ps-protocol", OPT_PS_PROTOCOL, "Use prepared statements protocol for communication", (gptr*) &ps_protocol, (gptr*) &ps_protocol, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select", - (gptr*) &sp_protocol, (gptr*) &sp_protocol, 0, - GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"cursor-protocol", OPT_CURSOR_PROTOCOL, "Use cursors for prepared statment", - (gptr*) &cursor_protocol, (gptr*) &cursor_protocol, 0, - GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select", - (gptr*) &view_protocol, (gptr*) &view_protocol, 0, - GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"quiet", 's', "Suppress all normal output.", (gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"record", 'r', "Record output of test_file into result file.", @@ -3206,7 +3224,7 @@ static struct my_option my_long_options[] = {"result-file", 'R', "Read/Store result from/in this file.", (gptr*) &result_file, (gptr*) &result_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"server-arg", 'A', "Send enbedded server this as a paramenter.", + {"server-arg", 'A', "Send option value to embedded server as a parameter.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"server-file", 'F', "Read embedded server arguments from file.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -3221,6 +3239,9 @@ static struct my_option my_long_options[] = {"socket", 'S', "Socket file to use for connection.", (gptr*) &unix_sock, (gptr*) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select", + (gptr*) &sp_protocol, (gptr*) &sp_protocol, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #include "sslopt-longopts.h" {"test-file", 'x', "Read test from/in this file (default stdin).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -3234,6 +3255,9 @@ static struct my_option my_long_options[] = GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select", + (gptr*) &view_protocol, (gptr*) &view_protocol, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -3624,34 +3648,138 @@ static int reg_replace(char** buf_p, int* buf_len_p, char *pattern, } -/* Append the string to ds, with optional replace */ +#ifdef __WIN__ -static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, - int len) +DYNAMIC_ARRAY patterns; + +/* + init_win_path_patterns + + DESCRIPTION + Setup string patterns that will be used to detect filenames that + needs to be converted from Win to Unix format + +*/ + +static void init_win_path_patterns() { - if (glob_replace) + /* List of string patterns to match in order to find paths */ + const char* paths[] = { "$MYSQL_TEST_DIR", + "$MYSQL_TMP_DIR", + "./test/", 0 }; + int num_paths= 3; + int i; + char* p; + + DBUG_ENTER("init_win_path_patterns"); + + my_init_dynamic_array(&patterns, sizeof(const char*), 16, 16); + + /* Loop through all paths in the array */ + for (i= 0; i < num_paths; i++) { - len=(int) replace_strings(glob_replace, &out_buff, &out_length, val); - if (len == -1) - die("Out of memory in replace"); - val=out_buff; + VAR* v; + if (*(paths[i]) == '$') + { + v= var_get(paths[i], 0, 0, 0); + p= my_strdup(v->str_val, MYF(MY_FAE)); + } + else + p= my_strdup(paths[i], MYF(MY_FAE)); + + if (insert_dynamic(&patterns, (gptr) &p)) + die(NullS); + + DBUG_PRINT("info", ("p: %s", p)); + while (*p) + { + if (*p == '/') + *p='\\'; + p++; + } } - + DBUG_VOID_RETURN; +} + +static void free_win_path_patterns() +{ + int i= 0; + for (i=0 ; i < patterns.elements ; i++) + { + const char** pattern= dynamic_element(&patterns, i, const char**); + my_free((gptr) *pattern, MYF(0)); + } + delete_dynamic(&patterns); +} + +/* + fix_win_paths + + DESCRIPTION + Search the string 'val' for the patterns that are known to be + strings that contain filenames. Convert all \ to / in the + filenames that are found. + + Ex: + val = 'Error "c:\mysql\mysql-test\var\test\t1.frm" didn't exist' + => $MYSQL_TEST_DIR is found by strstr + => all \ from c:\mysql\m... until next space is converted into / +*/ + +static void fix_win_paths(const char* val, int len) +{ + uint i; + char *p; + + DBUG_ENTER("fix_win_paths"); + for (i= 0; i < patterns.elements; i++) + { + const char** pattern= dynamic_element(&patterns, i, const char**); + DBUG_PRINT("info", ("pattern: %s", *pattern)); + /* Search for the path in string */ + while ((p= strstr(val, *pattern))) + { + DBUG_PRINT("info", ("Found %s in val p: %s", *pattern, p)); + + while (*p && !my_isspace(charset_info, *p)) + { + if (*p == '\\') + *p= '/'; + p++; + } + DBUG_PRINT("info", ("Converted \\ to /, p: %s", p)); + } + } + DBUG_PRINT("exit", (" val: %s, len: %d", val, len)); + DBUG_VOID_RETURN; +} +#endif + +/* Append the string to ds, with optional replace */ +static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, + const char *val, int len) +{ +#ifdef __WIN__ + fix_win_paths(val, len); +#endif + if (glob_replace_regex) { - if (!multi_reg_replace(glob_replace_regex,(char*)val)) - { - val= glob_replace_regex->buf; + if (!multi_reg_replace(glob_replace_regex, (char*)val)) + { + val= glob_replace_regex->buf; len= strlen(val); - } + } } - - dynstr_append_mem(ds, val, len); + + if (glob_replace) + replace_strings_append(glob_replace, ds, val, len); + else + dynstr_append_mem(ds, val, len); } /* Append zero-terminated string to ds, with optional replace */ - static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val) { replace_dynstr_append_mem(ds, val, strlen(val)); @@ -4473,7 +4601,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) if (command->type == Q_EVAL) { init_dynamic_string(&eval_query, "", 16384, 65536); - do_eval(&eval_query, command->query); + do_eval(&eval_query, command->query, FALSE); query = eval_query.str; query_len = eval_query.length; } @@ -4770,7 +4898,7 @@ void get_query_type(struct st_query* q) q->type=(enum enum_commands) type; /* Found command */ /* If queries are disabled, only recognize - --enable-queries and --disable-queries + --enable_parsing and --disable_parsing */ if (parsing_disabled && q->type != Q_ENABLE_PARSING && q->type != Q_DISABLE_PARSING) @@ -4967,6 +5095,10 @@ int main(int argc, char **argv) init_var_hash(&cur_con->mysql); +#ifdef __WIN__ + init_win_path_patterns(); +#endif + /* Initialize $mysql_errno with -1, so we can - distinguish it from valid values ( >= 0 ) and @@ -5276,8 +5408,8 @@ int main(int argc, char **argv) /* my_stat() successful on result file. Check if we have not run a single query, but we do have a result file that contains data. - Note that we don't care, if my_stat() fails. For example for - non-existing or non-readable file we assume it's fine to have + Note that we don't care, if my_stat() fails. For example, for a + non-existing or non-readable file, we assume it's fine to have no query output from the test file, e.g. regarded as no error. */ die("No queries executed but result file found!"); @@ -6037,60 +6169,57 @@ static uint replace_len(my_string str) } - /* Replace strings; Return length of result string */ - -uint replace_strings(REPLACE *rep, my_string *start,uint *max_length, - const char *from) +/* Replace strings while appending to ds */ +void replace_strings_append(REPLACE *rep, DYNAMIC_STRING* ds, + const char *str, int len) { reg1 REPLACE *rep_pos; reg2 REPLACE_STRING *rep_str; - my_string to,end,pos,new_str; + const char *start, *from; + DBUG_ENTER("replace_strings_append"); - end=(to= *start) + *max_length-1; + start= from= str; rep_pos=rep+1; for (;;) { + /* Loop through states */ + DBUG_PRINT("info", ("Looping through states")); while (!rep_pos->found) - { - rep_pos= rep_pos->next[(uchar) *from]; - if (to == end) - { - (*max_length)+=8192; - if (!(new_str=my_realloc(*start,*max_length,MYF(MY_WME)))) - return (uint) -1; - to=new_str+(to - *start); - end=(*start=new_str)+ *max_length-1; - } - *to++= *from++; - } + rep_pos= rep_pos->next[(uchar) *from++]; + + /* Does this state contain a string to be replaced */ if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string) - return (uint) (to - *start)-1; - to-=rep_str->to_offset; - for (pos=rep_str->replace_string; *pos ; pos++) { - if (to == end) - { - (*max_length)*=2; - if (!(new_str=my_realloc(*start,*max_length,MYF(MY_WME)))) - return (uint) -1; - to=new_str+(to - *start); - end=(*start=new_str)+ *max_length-1; - } - *to++= *pos; + /* No match found */ + dynstr_append_mem(ds, start, from - start - 1); + DBUG_PRINT("exit", ("Found no more string to replace, appended: %s", start)); + DBUG_VOID_RETURN; } + + /* Found a string that needs to be replaced */ + DBUG_PRINT("info", ("found: %d, to_offset: %d, from_offset: %d, string: %s", + rep_str->found, rep_str->to_offset, + rep_str->from_offset, rep_str->replace_string)); + + /* Append part of original string before replace string */ + dynstr_append_mem(ds, start, (from - rep_str->to_offset) - start); + + /* Append replace string */ + dynstr_append_mem(ds, rep_str->replace_string, + strlen(rep_str->replace_string)); + if (!*(from-=rep_str->from_offset) && rep_pos->found != 2) - return (uint) (to - *start); + { + /* End of from string */ + DBUG_PRINT("exit", ("Found end of from string")); + DBUG_VOID_RETURN; + } + DBUG_ASSERT(from <= str+len); + start= from; rep_pos=rep; } } -static int initialize_replace_buffer(void) -{ - out_length=8192; - if (!(out_buff=my_malloc(out_length,MYF(MY_WME)))) - return(1); - return 0; -} /**************************************************************************** Replace results for a column @@ -6149,105 +6278,6 @@ static void get_replace_column(struct st_query *q) q->last_argument= q->end; } -#if defined(__NETWARE__) || defined(__WIN__) -/* - Substitute environment variables with text. - - SYNOPSIS - subst_env_var() - arg String that should be substitute - - DESCRIPTION - This function takes a string as an input and replaces the - environment variables, that starts with '$' character, with it value. - - NOTES - Return string must be freed with my_free() - - RETURN - String with environment variables replaced. -*/ - -static char *subst_env_var(const char *str) -{ - char *result; - char *pos; - - result= pos= my_malloc(MAX_QUERY, MYF(MY_FAE)); - while (*str) - { - /* - need this only when we want to provide the functionality of - escaping through \ 'backslash' - if ((result == pos && *str=='$') || - (result != pos && *str=='$' && str[-1] !='\\')) - */ - if (*str == '$') - { - char env_var[256], *env_pos= env_var, *subst; - - /* Search for end of environment variable */ - for (str++; - *str && !isspace(*str) && *str != '\\' && *str != '/' && - *str != '$'; - str++) - *env_pos++= *str; - *env_pos= 0; - - if (!(subst= getenv(env_var))) - { - my_free(result, MYF(0)); - die("MYSQLTEST.NLM: Environment variable %s is not defined", - env_var); - } - - /* get the string to be substitued for env_var */ - pos= strmov(pos, subst); - /* Process delimiter in *str again */ - } - else - *pos++= *str++; - } - *pos= 0; - return result; -} - - -/* - popen replacement for Netware - - SYNPOSIS - my_popen() - name Command to execute (with possible env variables) - mode Mode for popen. - - NOTES - Environment variable expansion does not take place for popen function - on NetWare, so we use this function to wrap around popen to do this. - - For the moment we ignore 'mode' and always use 'r0' - - RETURN - # >= 0 File handle - -1 Error -*/ - -#undef popen /* Remove wrapper */ -#ifdef __WIN__ -#define popen _popen /* redefine for windows */ -#endif - -FILE *my_popen(const char *cmd, const char *mode __attribute__((unused))) -{ - char *subst_cmd; - FILE *res_file; - - subst_cmd= subst_env_var(cmd); - res_file= popen(subst_cmd, "r0"); - my_free(subst_cmd, MYF(0)); - return res_file; -} -#endif /* __NETWARE__ or __WIN__*/ diff --git a/config/ac-macros/replication.m4 b/config/ac-macros/replication.m4 index f73b9319b86..3a0c83d6498 100644 --- a/config/ac-macros/replication.m4 +++ b/config/ac-macros/replication.m4 @@ -7,8 +7,8 @@ dnl --------------------------------------------------------------------------- AC_DEFUN([MYSQL_CHECK_REPLICATION], [ AC_ARG_WITH([row-based-replication], - AC_HELP_STRING([--with-row-based-replication], - [Include row-based replication]), + AC_HELP_STRING([--without-row-based-replication], + [Don't include row-based replication]), [row_based="$withval"], [row_based=yes]) AC_MSG_CHECKING([for row-based replication]) diff --git a/configure.in b/configure.in index 2f287ac2fce..f7017e4455c 100644 --- a/configure.in +++ b/configure.in @@ -334,6 +334,9 @@ then # mysqld requires -fno-implicit-templates. # Disable exceptions as they seams to create problems with gcc and threads. # mysqld doesn't use run-time-type-checking, so we disable it. + # We should use -Wno-invalid-offsetof flag to disable some warnings from gcc + # regarding offset() usage in C++ which are done in a safe manner in the + # server CXXFLAGS="$CXXFLAGS -fno-implicit-templates -fno-exceptions -fno-rtti" AC_DEFINE([HAVE_EXPLICIT_TEMPLATE_INSTANTIATION], [1], [Defined by configure. Use explicit template instantiation.]) @@ -589,10 +592,10 @@ AC_ARG_WITH(named-curses-libs, # Make thread safe client AC_ARG_ENABLE(thread-safe-client, - [ --enable-thread-safe-client - Compile the client with threads.], + [ --disable-thread-safe-client + Compile the client without threads.], [ THREAD_SAFE_CLIENT=$enableval ], - [ THREAD_SAFE_CLIENT=no ] + [ THREAD_SAFE_CLIENT=yes ] ) # compile with strings functions in assembler @@ -1564,7 +1567,8 @@ then fi AC_ARG_WITH(debug, - [ --without-debug Build a production version without debugging code], + [ --with-debug Add debug code + --with-debug=full Add debug code (adds memory checker, very slow)], [with_debug=$withval], [with_debug=no]) if test "$with_debug" = "yes" @@ -2472,6 +2476,8 @@ dnl client is just using plain-old libs. sql_client_dirs="strings regex mysys libmysql client" linked_client_targets="linked_libmysql_sources" +AM_CONDITIONAL(THREAD_SAFE_CLIENT, test "$THREAD_SAFE_CLIENT" != "no") + if test "$THREAD_SAFE_CLIENT" != "no" then sql_client_dirs="libmysql_r $sql_client_dirs" diff --git a/dbug/dbug.c b/dbug/dbug.c index f53cb525912..dc5b06a63e2 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -209,7 +209,7 @@ struct settings { static BOOLEAN init_done= FALSE; /* Set to TRUE when initialization done */ static struct settings init_settings; -static char *db_process= 0; /* Pointer to process name; argv[0] */ +static const char *db_process= 0;/* Pointer to process name; argv[0] */ typedef struct _db_code_state_ { const char *process; /* Pointer to process name; usually argv[0] */ diff --git a/include/Makefile.am b/include/Makefile.am index 33e34fb512f..fbd06c6c574 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -18,7 +18,7 @@ BUILT_SOURCES = mysql_version.h m_ctype.h my_config.h pkginclude_HEADERS = my_dbug.h m_string.h my_sys.h my_list.h my_xml.h \ mysql.h mysql_com.h mysql_embed.h \ - my_semaphore.h my_pthread.h my_no_pthread.h raid.h \ + my_semaphore.h my_pthread.h my_no_pthread.h \ errmsg.h my_global.h my_net.h my_alloc.h \ my_getopt.h sslopt-longopts.h my_dir.h typelib.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ diff --git a/include/config-win.h b/include/config-win.h index 4e952f8248d..fb7aeb82e83 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -211,7 +211,7 @@ typedef uint rf_SetTimer; #define my_sigset(A,B) signal((A),(B)) #define finite(A) _finite(A) #define sleep(A) Sleep((A)*1000) -#define popen(A) popen(A,B) _popen((A),(B)) +#define popen(A,B) _popen((A),(B)) #define pclose(A) _pclose(A) #ifndef __BORLANDC__ @@ -427,6 +427,7 @@ inline double ulonglong2double(ulonglong value) #define HAVE_SPATIAL 1 #define HAVE_RTREE_KEYS 1 +#define HAVE_ROW_BASED_REPLICATION 1 /* #undef HAVE_OPENSSL */ /* #undef HAVE_YASSL */ diff --git a/include/my_global.h b/include/my_global.h index 82b0585757c..56aeb84d9ba 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -43,6 +43,15 @@ #define HAVE_ERRNO_AS_DEFINE #endif /* __CYGWIN__ */ +#if defined(__QNXNTO__) && !defined(FD_SETSIZE) +#define FD_SETSIZE 1024 /* Max number of file descriptor bits in + fd_set, used when calling 'select' + Must be defined before including + "sys/select.h" and "sys/time.h" + */ +#endif + + /* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */ #ifdef USE_PRAGMA_IMPLEMENTATION #define USE_PRAGMA_INTERFACE diff --git a/include/my_sys.h b/include/my_sys.h index 00c42fc5935..2df8dbc9e89 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -915,5 +915,4 @@ void netware_reg_user(const char *ip, const char *user, #endif C_MODE_END -#include "raid.h" #endif /* _my_sys_h */ diff --git a/include/myisam.h b/include/myisam.h index 1cc07de1fd9..5116f48eeb5 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -159,8 +159,6 @@ typedef struct st_mi_isaminfo /* Struct from h_info */ uint reflength; ulong record_offset; ulong *rec_per_key; /* for sql optimizing */ - uint raid_type,raid_chunks; - ulong raid_chunksize; } MI_ISAMINFO; @@ -172,8 +170,6 @@ typedef struct st_mi_create_info ulonglong auto_increment; ulonglong data_file_length; ulonglong key_file_length; - uint raid_type,raid_chunks; - ulong raid_chunksize; uint old_options; uint8 language; my_bool with_auto_increment; diff --git a/include/raid.h b/include/raid.h deleted file mode 100644 index c840afcbaab..00000000000 --- a/include/raid.h +++ /dev/null @@ -1,159 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - - 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; either version 2 of the License, or - (at your option) any later version. - - 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* Parser needs these defines always, even if USE_RAID is not defined */ -#define RAID_TYPE_0 1 /* Striping */ -#define RAID_TYPE_x 2 /* Some new modes */ -#define RAID_TYPE_y 3 - -#define RAID_DEFAULT_CHUNKS 4 -#define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */ - -C_MODE_START -#define my_raid_type(raid_type) raid_type_string[(int)(raid_type)] -extern const char *raid_type_string[]; -C_MODE_END - -#ifdef DONT_USE_RAID -#undef USE_RAID -#endif -#if defined(USE_RAID) - -#include "my_dir.h" - -/* Trap all occurences of my_...() in source and use our wrapper around this function */ - -#ifdef MAP_TO_USE_RAID -#define my_read(A,B,C,D) my_raid_read(A,B,C,D) -#define my_write(A,B,C,D) my_raid_write(A,B,C,D) -#define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E) -#define my_pread(A,B,C,D,E) my_raid_pread(A,B,C,D,E) -#define my_chsize(A,B,C,D) my_raid_chsize(A,B,C,D) -#define my_close(A,B) my_raid_close(A,B) -#define my_tell(A,B) my_raid_tell(A,B) -#define my_seek(A,B,C,D) my_raid_seek(A,B,C,D) -#define my_lock(A,B,C,D,E) my_raid_lock(A,B,C,D,E) -#define my_fstat(A,B,C) my_raid_fstat(A,B,C) -#endif /* MAP_TO_USE_RAID */ - -#ifdef __cplusplus -extern "C" { -#endif - - void init_raid(void); - void end_raid(void); - - bool is_raid(File fd); - File my_raid_create(const char *FileName, int CreateFlags, int access_flags, - uint raid_type, uint raid_chunks, ulong raid_chunksize, - myf MyFlags); - File my_raid_open(const char *FileName, int Flags, - uint raid_type, uint raid_chunks, ulong raid_chunksize, - myf MyFlags); - int my_raid_rename(const char *from, const char *to, uint raid_chunks, - myf MyFlags); - int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags); - int my_raid_redel(const char *old_name, const char *new_name, - uint raid_chunks, myf MyFlags); - - my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags); - my_off_t my_raid_tell(File fd, myf MyFlags); - - uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags); - uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags); - - uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, - myf MyFlags); - uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count, - my_off_t offset, myf MyFlags); - - int my_raid_lock(File,int locktype, my_off_t start, my_off_t length, - myf MyFlags); - int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags); - int my_raid_close(File, myf MyFlags); - int my_raid_fstat(int Filedes, struct stat *buf, myf MyFlags); - -#ifdef __cplusplus -} - -#ifdef USE_PRAGMA_INTERFACE -#pragma interface /* gcc class implementation */ -#endif - -class RaidName { - public: - RaidName(const char *FileName); - ~RaidName(); - bool IsRaid(); - int Rename(const char * from, const char * to, myf MyFlags); - private: - uint _raid_type; /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */ - uint _raid_chunks; /* 1..n */ - ulong _raid_chunksize; /* 1..n in bytes */ -}; - -class RaidFd { - public: - RaidFd(uint raid_type, uint raid_chunks , ulong raid_chunksize); - ~RaidFd(); - File Create(const char *FileName, int CreateFlags, int access_flags, - myf MyFlags); - File Open(const char *FileName, int Flags, myf MyFlags); - my_off_t Seek(my_off_t pos,int whence,myf MyFlags); - my_off_t Tell(myf MyFlags); - int Write(const byte *Buffer, uint Count, myf MyFlags); - int Read(const byte *Buffer, uint Count, myf MyFlags); - int Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags); - int Chsize(File fd, my_off_t newlength, int filler, myf MyFlags); - int Fstat(int fd, MY_STAT *stat_area, myf MyFlags ); - int Close(myf MyFlags); - static bool IsRaid(File fd); - static DYNAMIC_ARRAY _raid_map; /* Map of RaidFD* */ - private: - - uint _raid_type; /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */ - uint _raid_chunks; /* 1..n */ - ulong _raid_chunksize; /* 1..n in bytes */ - - ulong _total_block; /* We are operating with block no x (can be 0..many). */ - uint _this_block; /* can be 0.._raid_chunks */ - uint _remaining_bytes; /* Maximum bytes that can be written in this block */ - - my_off_t _position; - my_off_t _size; /* Cached file size for faster seek(SEEK_END) */ - File _fd; - File *_fd_vector; /* Array of File */ - off_t *_seek_vector; /* Array of cached seek positions */ - - inline void Calculate() - { - DBUG_ENTER("RaidFd::_Calculate"); - DBUG_PRINT("info",("_position: %lu _raid_chunksize: %d, _size: %lu", - (ulong) _position, _raid_chunksize, (ulong) _size)); - - _total_block = (ulong) (_position / _raid_chunksize); - _this_block = _total_block % _raid_chunks; /* can be 0.._raid_chunks */ - _remaining_bytes = (uint) (_raid_chunksize - - (_position - _total_block * _raid_chunksize)); - DBUG_PRINT("info", - ("_total_block: %d this_block: %d _remaining_bytes:%d", - _total_block, _this_block, _remaining_bytes)); - DBUG_VOID_RETURN; - } -}; - -#endif /* __cplusplus */ -#endif /* USE_RAID */ diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index 62418c0d669..be9947ca2dd 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -67,7 +67,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \ event_executor.cc event.cc event_timed.cc \ rpl_filter.cc sql_partition.cc handlerton.cc sql_plugin.cc \ sql_tablespace.cc \ - rpl_injector.cc my_user.c + rpl_injector.cc my_user.c partition_info.cc libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) EXTRA_libmysqld_a_SOURCES = ha_innodb.cc ha_berkeley.cc ha_archive.cc \ diff --git a/mysql-test/README b/mysql-test/README index 10d64784ed4..77b398ebf39 100644 --- a/mysql-test/README +++ b/mysql-test/README @@ -1,45 +1,51 @@ -This directory contains a test suite for mysql daemon. To run +This directory contains a test suite for the MySQL daemon. To run the currently existing test cases, simply execute ./mysql-test-run in this directory. It will fire up the newly built mysqld and test it. -If you want to run a test with a running MySQL server use the --extern -option to mysql-test-run. Please note that in this mode the test suite -expects user to specify test names to run. Otherwise it falls back to the -normal "non-extern" behaviour. The reason is that some tests -could not run with external server. Here is the sample command -to test "alias" and "analyze" tests on external server: +Note that you do not have to have to do "make install", and you could +actually have a co-existing MySQL installation. The tests will not +conflict with it. -mysql-test-run --extern alias analyze +All tests must pass. If one or more of them fail on your system, please +read the following manual section for instructions on how to report the +problem: -To match your setup you might also need to provide --socket, --user and -other relevant options. +http://dev.mysql.com/doc/mysql/en/mysql-test-suite.html -Note that you do not have to have to do make install, and you could -actually have a co-existing MySQL installation - the tests will not -conflict with it. +If you want to use an already running MySQL server for specific tests, +use the --extern option to mysql-test-run. Please note that in this mode, +the test suite expects you to provide the names of the tests to run. +For example, here is the command to run the "alias" and "analyze" tests +with an external server: -All tests must pass. If one or more of them fail on your system, please -read the following manual section of how to report the problem: +mysql-test-run --extern alias analyze + +To match your setup, you might also need to provide --socket, --user, and +other relevant options. -http://dev.mysql.com/doc/mysql/en/MySQL_test_suite.html +With no test cases named on the command line, mysql-test-run falls back +to the normal "non-extern" behavior. The reason for this is that some +tests cannot run with an external server. -You can create your own test cases. To create a test case: +You can create your own test cases. To create a test case, create a new +file in the t subdirectory using a text editor. The file should have a .test +extension. For example: xemacs t/test_case_name.test - in the file, put a set of SQL commands that will create some tables, - load test data, run some queries to manipulate it. + In the file, put a set of SQL statements that create some tables, + load test data, and run some queries to manipulate it. - We would appreciate if the test tables were called t1, t2, t3 ... (to not + We would appreciate it if you name your test tables t1, t2, t3 ... (to not conflict too much with existing tables). Your test should begin by dropping the tables you are going to create and - end by dropping them again. This will ensure that one can run the test - over and over again. + end by dropping them again. This ensures that you can run the test over + and over again. If you are using mysqltest commands (like result file names) in your - test case you should do create the result file as follows: + test case, you should create the result file as follows: mysql-test-run --record test_case_name @@ -47,8 +53,8 @@ You can create your own test cases. To create a test case: mysqltest --record < t/test_case_name.test - If you only have a simple test cases consistent of SQL commands and comments - you can create the test case one of the following ways: + If you only have a simple test cases consisting of SQL statements and + comments, you can create the test case in one of the following ways: mysql-test-run --record test_case_name @@ -57,11 +63,11 @@ You can create your own test cases. To create a test case: mysqltest --record --record-file=r/test_case_name.result < t/test_case_name.test When this is done, take a look at r/test_case_name.result - - If the result is wrong, you have found a bug; In this case you should + - If the result is incorrect, you have found a bug. In this case, you should edit the test result to the correct results so that we can verify that the bug is corrected in future releases. To submit your test case, put your .test file and .result file(s) into a tar.gz archive, add a README that explains the problem, ftp the -archive to ftp://support.mysql.com/pub/mysql/secret/ and send a mail +archive to ftp://support.mysql.com/pub/mysql/secret/ and send a mail to bugs@lists.mysql.com diff --git a/mysql-test/README.gcov b/mysql-test/README.gcov index 83ddd6df2e1..6d2852e8ca0 100644 --- a/mysql-test/README.gcov +++ b/mysql-test/README.gcov @@ -1,11 +1,13 @@ To be able to see the level of coverage with the current test suite, do the following: - - make sure gcov is installed - - compile with BUILD/compile-pentium-gcov ( if your machine is not pentium, hack -this script, or just live with the pentium-specific stuff) - - ./mysql-test-run -gcov - - to see the level of coverage for a given source file: + - Make sure gcov is installed + - Compile the MySQL distribution with BUILD/compile-pentium-gcov (if your + machine does not have a pentium CPU, hack this script, or just live with + the pentium-specific stuff) + - In the mysql-test directory, run this command: ./mysql-test-run -gcov + - To see the level of coverage for a given source file: grep source_file_name /tmp/gcov.out - - to see which lines are not yet covered, look at source_file_name.gcov in the source tree. Then think hard about a test case that will cover those -lines, and write one! + - To see which lines are not yet covered, look at source_file_name.gcov in + the source tree. Then think hard about a test case that will cover those + lines, and write one! diff --git a/mysql-test/extra/binlog_tests/binlog.test b/mysql-test/extra/binlog_tests/binlog.test index 8eb1dcb7dc3..e569e15e519 100644 --- a/mysql-test/extra/binlog_tests/binlog.test +++ b/mysql-test/extra/binlog_tests/binlog.test @@ -2,6 +2,7 @@ # misc binlogging tests that do not require a slave running # +-- source include/not_embedded.inc -- source include/have_bdb.inc -- source include/have_innodb.inc -- source include/have_debug.inc diff --git a/mysql-test/extra/binlog_tests/blackhole.test b/mysql-test/extra/binlog_tests/blackhole.test index 7e03dc9ed57..bd77286a9fe 100644 --- a/mysql-test/extra/binlog_tests/blackhole.test +++ b/mysql-test/extra/binlog_tests/blackhole.test @@ -2,6 +2,7 @@ # Simple test for blackhole example # Taken from the select test # +-- source include/not_embedded.inc -- source include/have_blackhole.inc --disable_warnings diff --git a/mysql-test/extra/binlog_tests/ctype_cp932.test b/mysql-test/extra/binlog_tests/ctype_cp932.test index ac90ceabf23..688d06c4dde 100644 --- a/mysql-test/extra/binlog_tests/ctype_cp932.test +++ b/mysql-test/extra/binlog_tests/ctype_cp932.test @@ -398,28 +398,6 @@ DROP TABLE t2; DROP TABLE t3; DROP TABLE t4; -# Test prepared statement with 0x8300 sequence in parameter while -# running with cp932 client character set. -RESET MASTER; -CREATE TABLE t1(f1 blob); -PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)'; -SET @var1= x'8300'; -# TODO: Note that this doesn't actually test the code which was added for -# bug#11338 because this syntax for prepared statements causes the PS to -# be replicated differently than if we executed the PS from C or Java. -# Using this syntax, variable names are inserted into the binlog instead -# of values. The real goal of this test is to check the code that was -# added to Item_param::query_val_str() in order to do hex encoding of -# PS parameters when the client character set is cp932; -# Bug#11338 has an example java program which can be used to verify this -# code (and I have used it to test the fix) until there is some way to -# exercise this code from mysql-test-run. -EXECUTE stmt1 USING @var1; -SHOW BINLOG EVENTS FROM 102; -SELECT HEX(f1) FROM t1; -DROP table t1; -# end test for bug#11338 - SET collation_connection='cp932_japanese_ci'; -- source include/ctype_filesort.inc SET collation_connection='cp932_bin'; diff --git a/mysql-test/extra/binlog_tests/insert_select-binlog.test b/mysql-test/extra/binlog_tests/insert_select-binlog.test index d4041f86ab5..a665dfda2b0 100644 --- a/mysql-test/extra/binlog_tests/insert_select-binlog.test +++ b/mysql-test/extra/binlog_tests/insert_select-binlog.test @@ -1,6 +1,10 @@ # Embedded server doesn't support binlog -- source include/not_embedded.inc +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + # Check if a partly-completed INSERT SELECT in a MyISAM table goes into the # binlog diff --git a/mysql-test/extra/rpl_tests/rpl_ndb_2multi_eng.test b/mysql-test/extra/rpl_tests/rpl_ndb_2multi_eng.test new file mode 100644 index 00000000000..014a72db30e --- /dev/null +++ b/mysql-test/extra/rpl_tests/rpl_ndb_2multi_eng.test @@ -0,0 +1,343 @@ +####################################### +# Author: JBM # +# Date: 2006-02-23 # +# Purpose: See if replication between # +# NDB -> MyISAM and InnoDB works. # +# and if # +# MyISAM and InnoDB -> NDB works. # +####################################### +# By JBM # +# Date 2006-02-28 # +# Change: Implemented review comments # +####################################### + +--echo --- Doing pre test cleanup --- + +connection master; +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_query_log + +--echo --- Start test 1 Basic testing --- +--echo --- Create Table Section --- + +################################################# +# Requirment: Create basic table, replicate # +# basice operations such at insert, update # +# delete between 2 different storage engines # +# Alter table and ensure table is handled # +# Correctly on the slave # +################################################# + +CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(255), + bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, total BIGINT UNSIGNED, + y YEAR, t DATE,PRIMARY KEY(id)); + +--echo --- Show table on master --- + +SHOW CREATE TABLE t1; + +--echo --- Show table on slave --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +# Okay lets see how it holds up to table changes +--echo --- Check that simple Alter statements are replicated correctly -- + +ALTER TABLE t1 MODIFY vc TEXT; +ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(id, total); + +--echo --- Show the new improved table on the master --- + +SHOW CREATE TABLE t1; + +--echo --- Make sure that our tables on slave are still same engine --- +--echo --- and that the alter statements replicated correctly --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- End test 1 Basic testing --- +--echo --- Do Cleanup -- + +DROP TABLE IF EXISTS t1; + +################################################################# + +--echo --- Start test 2 partition RANGE testing -- +--echo --- Do setup -- + + +################################################# +# Requirment: Create table that is partitioned # +# by range on year i.e. year(t) and replicate # +# basice operations such at insert, update # +# delete between 2 different storage engines # +# Alter table and ensure table is handled # +# Correctly on the slave # +################################################# + +CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(255), + bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, total BIGINT UNSIGNED, + y YEAR, t DATE) + PARTITION BY RANGE (YEAR(t)) + (PARTITION p0 VALUES LESS THAN (1901), + PARTITION p1 VALUES LESS THAN (1946), + PARTITION p2 VALUES LESS THAN (1966), + PARTITION p3 VALUES LESS THAN (1986), + PARTITION p4 VALUES LESS THAN (2005), + PARTITION p5 VALUES LESS THAN MAXVALUE); + +--echo --- Show table on master --- + +SHOW CREATE TABLE t1; + +--echo --- Show table on slave -- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- Check that simple Alter statements are replicated correctly --- + +ALTER TABLE t1 MODIFY vc TEXT; + +--echo --- Show the new improved table on the master --- + +SHOW CREATE TABLE t1; + +--echo --- Make sure that our tables on slave are still same engine --- +--echo --- and that the alter statements replicated correctly --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- +--enable_query_log + +--source include/rpl_multi_engine3.inc + +--echo --- End test 2 partition RANGE testing --- +--echo --- Do Cleanup --- + +DROP TABLE IF EXISTS t1; + +######################################################## + +--echo --- Start test 3 partition LIST testing --- +--echo --- Do setup --- +################################################# +# Requirment: Create table that is partitioned # +# by list on id i.e. (2,4). Pretend that we # +# missed one and alter to add. Then replicate # +# basice operations such at insert, update # +# delete between 2 different storage engines # +# Alter table and ensure table is handled # +# Correctly on the slave # +################################################# + + +CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(255), + bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, total BIGINT UNSIGNED, + y YEAR, t DATE) + PARTITION BY LIST(id) + (PARTITION p0 VALUES IN (2, 4), + PARTITION p1 VALUES IN (42, 142)); + +--echo --- Test 3 Alter to add partition --- + +ALTER TABLE t1 ADD PARTITION (PARTITION p2 VALUES IN (412)); + +--echo --- Show table on master --- + +SHOW CREATE TABLE t1; + +--echo --- Show table on slave --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- Check that simple Alter statements are replicated correctly --- + +ALTER TABLE t1 MODIFY vc TEXT; + +--echo --- Show the new improved table on the master --- + +SHOW CREATE TABLE t1; + +--echo --- Make sure that our tables on slave are still same engine --- +--echo --- and that the alter statements replicated correctly --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- End test 3 partition LIST testing --- +--echo --- Do Cleanup -- + +DROP TABLE IF EXISTS t1; + +######################################################## + +--echo --- Start test 4 partition HASH testing --- +--echo --- Do setup --- +################################################# +# Requirment: Create table that is partitioned # +# by hash on year i.e. YEAR(t). Then replicate # +# basice operations such at insert, update # +# delete between 2 different storage engines # +# Alter table and ensure table is handled # +# Correctly on the slave # +################################################# + + +CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(255), + bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, total BIGINT UNSIGNED, + y YEAR, t DATE) + PARTITION BY HASH( YEAR(t) ) + PARTITIONS 4; + +--echo --- show that tables have been created correctly --- + +SHOW CREATE TABLE t1; +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- Check that simple Alter statements are replicated correctly --- + +ALTER TABLE t1 MODIFY vc TEXT; + +--echo --- Show the new improved table on the master --- + +SHOW CREATE TABLE t1; + +--echo --- Make sure that our tables on slave are still same engine --- +--echo --- and that the alter statements replicated correctly --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- End test 4 partition HASH testing --- +--echo --- Do Cleanup -- + +DROP TABLE IF EXISTS t1; + +######################################################## + +--echo --- Start test 5 partition by key testing --- +--echo --- Create Table Section --- + +################################################# +# Requirment: Create table that is partitioned # +# by key on id with 4 parts. Then replicate # +# basice operations such at insert, update # +# delete between 2 different storage engines # +# Alter table and ensure table is handled # +# Correctly on the slave # +################################################# + +CREATE TABLE t1 (id MEDIUMINT NOT NULL, b1 BIT(8), vc VARCHAR(255), + bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, total BIGINT UNSIGNED, + y YEAR, t DATE,PRIMARY KEY(id)) + PARTITION BY KEY() + PARTITIONS 4; + +--echo --- Show that tables on master are ndbcluster tables --- + +SHOW CREATE TABLE t1; + +--echo --- Show that tables on slave --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +# Okay lets see how it holds up to table changes +--echo --- Check that simple Alter statements are replicated correctly --- + +ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(id, total); + +--echo --- Show the new improved table on the master --- + +SHOW CREATE TABLE t1; + +--echo --- Make sure that our tables on slave are still right type --- +--echo --- and that the alter statements replicated correctly --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- Check that simple Alter statements are replicated correctly --- + +ALTER TABLE t1 MODIFY vc TEXT; + +--echo --- Show the new improved table on the master --- + +SHOW CREATE TABLE t1; + +--echo --- Make sure that our tables on slave are still same engine --- +--echo --- and that the alter statements replicated correctly --- + +sync_slave_with_master; +SHOW CREATE TABLE t1; + +--echo --- Perform basic operation on master --- +--echo --- and ensure replicated correctly --- + +--source include/rpl_multi_engine3.inc + +--echo --- End test 5 key partition testing --- +--echo --- Do Cleanup --- + +DROP TABLE IF EXISTS t1; + +# End of 5.1 test case diff --git a/mysql-test/extra/rpl_tests/rpl_row_001.test b/mysql-test/extra/rpl_tests/rpl_row_001.test index 44638bdac96..9bdfae81093 100644 --- a/mysql-test/extra/rpl_tests/rpl_row_001.test +++ b/mysql-test/extra/rpl_tests/rpl_row_001.test @@ -2,7 +2,7 @@ -- source include/have_binlog_format_row.inc CREATE TABLE t1 (word CHAR(20) NOT NULL); -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR eval LOAD DATA LOCAL INFILE '$MYSQL_TEST_DIR/std_data/words.dat' INTO TABLE t1; SELECT * FROM t1 ORDER BY word LIMIT 10; diff --git a/mysql-test/extra/rpl_tests/rpl_row_UUID.test b/mysql-test/extra/rpl_tests/rpl_row_UUID.test index 2f203eb8963..d1d6178773b 100644 --- a/mysql-test/extra/rpl_tests/rpl_row_UUID.test +++ b/mysql-test/extra/rpl_tests/rpl_row_UUID.test @@ -56,8 +56,8 @@ SHOW CREATE TABLE test.t1; # then LOAD DATA INFILE in slave, and use a query to compare. # This would have the advantage that it would not assume # the system has a 'diff' ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/rpl_row_UUID_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/rpl_row_UUID_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_slave.sql connection master; # Let's cleanup @@ -72,7 +72,7 @@ DROP TABLE test.t2; # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) ---exec diff ./var/tmp/rpl_row_UUID_master.sql ./var/tmp/rpl_row_UUID_slave.sql; +--exec diff $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_master.sql $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_slave.sql; # Cleanup dump files. # Long-term "system rm" is not portable; we could live without diff --git a/mysql-test/extra/rpl_tests/rpl_row_blob.test b/mysql-test/extra/rpl_tests/rpl_row_blob.test index 7f41118387f..14449e0a018 100644 --- a/mysql-test/extra/rpl_tests/rpl_row_blob.test +++ b/mysql-test/extra/rpl_tests/rpl_row_blob.test @@ -176,10 +176,10 @@ connection master; --echo # Post test clean up section ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/rpl_row_blob_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/rpl_row_blob_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_blob_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_blob_slave.sql ---exec diff ./var/tmp/rpl_row_blob_master.sql ./var/tmp/rpl_row_blob_slave.sql +--exec diff $MYSQLTEST_VARDIR/tmp/rpl_row_blob_master.sql $MYSQLTEST_VARDIR/tmp/rpl_row_blob_slave.sql DROP TABLE IF EXISTS test.t1; DROP TABLE IF EXISTS test.t2; diff --git a/mysql-test/extra/rpl_tests/rpl_row_charset.test b/mysql-test/extra/rpl_tests/rpl_row_charset.test index c2a7cda4333..d0fea6f9580 100644 --- a/mysql-test/extra/rpl_tests/rpl_row_charset.test +++ b/mysql-test/extra/rpl_tests/rpl_row_charset.test @@ -162,8 +162,8 @@ select hex(c1), hex(c2) from t1; connection master; # Let's have a look at generated SETs. ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR -#--exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001 +--replace_result $MYSQLTEST_VARDIR MYSQL_TEST_DIR/var +#--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001 drop table t1; sync_slave_with_master; diff --git a/mysql-test/extra/rpl_tests/rpl_row_func003.test b/mysql-test/extra/rpl_tests/rpl_row_func003.test index f07c8a65265..153a03da2e7 100644 --- a/mysql-test/extra/rpl_tests/rpl_row_func003.test +++ b/mysql-test/extra/rpl_tests/rpl_row_func003.test @@ -77,8 +77,8 @@ SET AUTOCOMMIT=1; # time to dump the databases and so we can see if they match ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/func003_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/func003_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/func003_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/func003_slave.sql # First lets cleanupi DROP FUNCTION test.f1; @@ -88,9 +88,9 @@ DROP TABLE test.t1; # the test will show that the diff statement failed and no reject file # will be created. You will need to go to the mysql-test dir and diff # the files yourself to see what is not matching :-) File are located -# in mysql-test/var/tmp +# in $MYSQLTEST_VARDIR/tmp -exec diff ./var/tmp/func003_master.sql ./var/tmp/func003_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/func003_master.sql $MYSQLTEST_VARDIR/tmp/func003_slave.sql; # End of 5.0 test case diff --git a/mysql-test/extra/rpl_tests/rpl_row_sp006.test b/mysql-test/extra/rpl_tests/rpl_row_sp006.test index 272a7caf9ac..f40b3cbb078 100644 --- a/mysql-test/extra/rpl_tests/rpl_row_sp006.test +++ b/mysql-test/extra/rpl_tests/rpl_row_sp006.test @@ -68,8 +68,8 @@ sync_slave_with_master; connection master; ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > ./var/tmp/sp006_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > ./var/tmp/sp006_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/sp006_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/sp006_slave.sql DROP PROCEDURE IF EXISTS mysqltest1.p1; @@ -81,9 +81,9 @@ DROP TABLE IF EXISTS mysqltest1.t2; # the test will show that the diff statement failed and not reject file # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) Failed test -# Dump files will be located in mysql-test/var/tmp. +# Dump files will be located in $MYSQLTEST_VARDIR/tmp. -exec diff ./var/tmp/sp006_master.sql ./var/tmp/sp006_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/sp006_master.sql $MYSQLTEST_VARDIR/tmp/sp006_slave.sql; sync_slave_with_master; diff --git a/mysql-test/include/drop-on-restart.inc b/mysql-test/include/drop-on-restart.inc index 841b636483a..af1d0d893e0 100644 --- a/mysql-test/include/drop-on-restart.inc +++ b/mysql-test/include/drop-on-restart.inc @@ -23,6 +23,7 @@ drop database if exists db1_secret; drop database if exists db2; drop database if exists federated; drop database if exists mysqldump_test_db; +drop database if exists mysqlslap; drop database if exists mysqltest1; drop database if exists mysqltest2; drop database if exists mysqltest3; @@ -34,6 +35,7 @@ drop database if exists mysqltest_bob; drop database if exists mysqltest_db1; drop database if exists mysqltest_prometheus; drop database if exists mysqltest_sisyfos; +drop database if exists ndbsynctest; drop database if exists ndbtest1; drop database if exists rewrite; drop database if exists test2; @@ -429,6 +431,7 @@ drop table if exists new_t2; drop table if exists not_exist; drop table if exists r1; drop table if exists t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t21,t70; +drop table if exists t00,t03,t04; drop table if exists t0_template; drop table if exists t1Aa,t2Aa,v1Aa,v2Aa; drop table if exists t1_1,t1_2,t9_1,t9_2,t1aa,t2aa; diff --git a/mysql-test/include/gis_generic.inc b/mysql-test/include/gis_generic.inc index e5e7283e0e6..3abc18283fa 100644 --- a/mysql-test/include/gis_generic.inc +++ b/mysql-test/include/gis_generic.inc @@ -8,14 +8,14 @@ DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; --enable_warnings -CREATE TABLE gis_point (fid INTEGER, g POINT); -CREATE TABLE gis_line (fid INTEGER, g LINESTRING); -CREATE TABLE gis_polygon (fid INTEGER, g POLYGON); -CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT); -CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING); -CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON); -CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION); -CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY); +CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT); +CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY); SHOW CREATE TABLE gis_point; SHOW FIELDS FROM gis_point; @@ -141,6 +141,7 @@ DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gi # Check that ALTER TABLE doesn't loose geometry type # CREATE TABLE t1 ( + a INTEGER PRIMARY KEY AUTO_INCREMENT, gp point, ln linestring, pg polygon, @@ -156,24 +157,24 @@ ALTER TABLE t1 ADD fid INT; SHOW FIELDS FROM t1; DROP TABLE t1; -create table t1 (a geometry not null); -insert into t1 values (GeomFromText('Point(1 2)')); +create table t1 (pk integer primary key auto_increment, a geometry not null); +insert into t1 (a) values (GeomFromText('Point(1 2)')); -- error 1416 -insert into t1 values ('Garbage'); +insert into t1 (a) values ('Garbage'); -- error 1416 -insert IGNORE into t1 values ('Garbage'); +insert IGNORE into t1 (a) values ('Garbage'); drop table t1; -create table t1 (fl geometry); +create table t1 (pk integer primary key auto_increment, fl geometry); --error 1416 -insert into t1 values (1); +insert into t1 (fl) values (1); --error 1416 -insert into t1 values (1.11); +insert into t1 (fl) values (1.11); --error 1416 -insert into t1 values ("qwerty"); +insert into t1 (fl) values ("qwerty"); --error 1416 -insert into t1 values (pointfromtext('point(1,1)')); +insert into t1 (fl) values (pointfromtext('point(1,1)')); drop table t1; diff --git a/mysql-test/include/ndb_backup.inc b/mysql-test/include/ndb_backup.inc index 2163b479ed6..f0a883d4e11 100644 --- a/mysql-test/include/ndb_backup.inc +++ b/mysql-test/include/ndb_backup.inc @@ -6,13 +6,13 @@ # there is no neat way to find the backupid, this is a hack to find it... ---exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > var/tmp.dat +--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; DELETE FROM test.backup_info; -LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; --replace_column 1 <the_backup_id> diff --git a/mysql-test/include/partition_1.inc b/mysql-test/include/partition_1.inc index 9b829494a73..b0094db2efe 100644 --- a/mysql-test/include/partition_1.inc +++ b/mysql-test/include/partition_1.inc @@ -36,7 +36,7 @@ let $fixed_bug16370= 0; ##### Option, for displaying files ##### # -# Attention: Displaying the directory content via "ls var/master-data/test/t*" +# Attention: Displaying the directory content via "ls $MYSQLTEST_VARDIR/master-data/test/t*" # is probably not portable. # let $ls= 0; disables the execution of "ls ....." let $ls= 0; diff --git a/mysql-test/include/partition_layout.inc b/mysql-test/include/partition_layout.inc index 0a59c23fafd..95f6cac37d7 100644 --- a/mysql-test/include/partition_layout.inc +++ b/mysql-test/include/partition_layout.inc @@ -9,5 +9,5 @@ eval SHOW CREATE TABLE t1; # listing of files belonging to the table t1 if ($ls) { - --exec ls var/master-data/test/t1* + --exec ls $MYSQLTEST_VARDIR/master-data/test/t1* } diff --git a/mysql-test/include/rpl_multi_engine3.inc b/mysql-test/include/rpl_multi_engine3.inc new file mode 100644 index 00000000000..be89c1907f3 --- /dev/null +++ b/mysql-test/include/rpl_multi_engine3.inc @@ -0,0 +1,62 @@ +############################################################# +# Author: JBM +# Date: 2006-02-23 +# Purpose: To reuse through out test and make maint easier +############################################################# +connection master; +--echo "--- Insert into t1 --" as ""; + +--disable_query_log +INSERT INTO t1 VALUES(42,1,'Testing MySQL databases is a cool ', + 'Must make it bug free for the customer', + 654321.4321,15.21,0,1965,"1905-11-14"); +INSERT INTO t1 VALUES(2,1,'Testing MySQL databases is a cool ', + 'Must make it bug free for the customer', + 654321.4321,15.21,0,1965,"1965-11-14"); +INSERT INTO t1 VALUES(4,1,'Testing MySQL databases is a cool ', + 'Must make it bug free for the customer', + 654321.4321,15.21,0,1965,"1985-11-14"); +INSERT INTO t1 VALUES(142,1,'Testing MySQL databases is a cool ', + 'Must make it bug free for the customer', + 654321.4321,15.21,0,1965,"1995-11-14"); +INSERT INTO t1 VALUES(412,1,'Testing MySQL databases is a cool ', + 'Must make it bug free for the customer', + 654321.4321,15.21,0,1965,"2005-11-14"); +--enable_query_log + +--echo --- Select from t1 on master --- +select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; + +sync_slave_with_master; +--echo --- Select from t1 on slave --- +select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id; + +connection master; + +--echo --- Update t1 on master -- +UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412; + +--echo --- Check the update on master --- +SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; + +# Must give injector thread a little time to get update +# into the binlog other wise we will miss the update. +sleep 3; + +sync_slave_with_master; +--echo --- Check Update on slave --- +SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412; + +connection master; +--echo --- Remove a record from t1 on master --- +DELETE FROM t1 WHERE id = 42; + +--echo --- Show current count on master for t1 --- +SELECT COUNT(*) FROM t1; + +sync_slave_with_master; +--echo --- Show current count on slave for t1 --- +SELECT COUNT(*) FROM t1; + +connection master; +DELETE FROM t1; diff --git a/mysql-test/lib/init_db.sql b/mysql-test/lib/init_db.sql index 8eb1712d489..79a7c528370 100644 --- a/mysql-test/lib/init_db.sql +++ b/mysql-test/lib/init_db.sql @@ -634,5 +634,5 @@ CREATE TABLE event ( PRIMARY KEY (definer, db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events'; -CREATE DATABASE IF NOT EXISTS cluster_replication; -CREATE TABLE IF NOT EXISTS cluster_replication.binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; +CREATE DATABASE IF NOT EXISTS cluster; +CREATE TABLE IF NOT EXISTS cluster.binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 55097a7deeb..acb794bce3b 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -162,6 +162,7 @@ our $path_slave_load_tmpdir; # What is this?! our $path_mysqltest_log; our $path_my_basedir; our $opt_vardir; # A path but set directly on cmd line +our $opt_vardir_trace; # unix formatted opt_vardir for trace files our $opt_tmpdir; # A path but set directly on cmd line our $opt_restart_cleanup; # Source a file with SQL drop statements @@ -197,6 +198,7 @@ our $opt_big_test= 0; # Send --big-test to mysqltest our @opt_extra_mysqld_opt; +our $opt_comment; our $opt_compress; our $opt_ssl; our $opt_skip_ssl; @@ -668,6 +670,14 @@ sub command_line_setup () { print '#' x 78, "\n\n"; } + if ( $opt_comment ) + { + print "\n"; + print '#' x 78, "\n"; + print "# $opt_comment\n"; + print '#' x 78, "\n\n"; + } + foreach my $arg ( @ARGV ) { if ( $arg =~ /^--skip-/ ) @@ -692,7 +702,7 @@ sub command_line_setup () { { $opt_vardir= "$glob_mysql_test_dir/var"; } - + $opt_vardir_trace= $opt_vardir; # We make the path absolute, as the server will do a chdir() before usage unless ( $opt_vardir =~ m,^/, or ($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) ) @@ -981,16 +991,26 @@ sub executable_setup () { if ( $glob_win32 ) { $path_client_bindir= mtr_path_exists("$glob_basedir/client_release", - "$glob_basedir/bin"); - $exe_mysqld= mtr_exe_exists ("$path_client_bindir/mysqld-max", - "$path_client_bindir/mysqld-nt", + "$glob_basedir/client_debug", + "$glob_basedir/bin", + # New CMake locations. + "$glob_basedir/client/release", + "$glob_basedir/client/debug"); + $exe_mysqld= mtr_exe_exists ("$path_client_bindir/mysqld-nt", "$path_client_bindir/mysqld", - "$path_client_bindir/mysqld-debug",); - $path_language= mtr_path_exists("$glob_basedir/share/english/"); - $path_charsetsdir= mtr_path_exists("$glob_basedir/share/charsets"); + "$path_client_bindir/mysqld-debug", + "$path_client_bindir/mysqld-max", + "$glob_basedir/sql/release/mysqld", + "$glob_basedir/sql/debug/mysqld"); + $path_language= mtr_path_exists("$glob_basedir/share/english/", + "$glob_basedir/sql/share/english/"); + $path_charsetsdir= mtr_path_exists("$glob_basedir/share/charsets", + "$glob_basedir/sql/share/charsets"); $exe_my_print_defaults= - mtr_exe_exists("$path_client_bindir/my_print_defaults"); + mtr_exe_exists("$path_client_bindir/my_print_defaults", + "$glob_basedir/extra/release/my_print_defaults", + "$glob_basedir/extra/debug/my_print_defaults"); } else { @@ -1031,6 +1051,7 @@ sub executable_setup () { } $exe_mysql_client_test= mtr_exe_exists("$glob_basedir/tests/mysql_client_test", + "$path_client_bindir/mysql_client_test", "/usr/bin/false"); } $exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck"); @@ -1143,9 +1164,8 @@ sub environment_setup () { $ENV{'LC_COLLATE'}= "C"; $ENV{'USE_RUNNING_SERVER'}= $glob_use_running_server; $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir; - $ENV{'MYSQL_TEST_WINDIR'}= $glob_mysql_test_dir; $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir; - $ENV{'MASTER_WINMYSOCK'}= $master->[0]->{'path_mysock'}; + $ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir; $ENV{'MASTER_MYSOCK'}= $master->[0]->{'path_mysock'}; $ENV{'MASTER_MYSOCK1'}= $master->[1]->{'path_mysock'}; $ENV{'MASTER_MYPORT'}= $master->[0]->{'path_myport'}; @@ -1169,16 +1189,6 @@ sub environment_setup () { $ENV{'IM_MYSQLD2_PORT'}= $instance_manager->{instances}->[1]->{port}; $ENV{'IM_MYSQLD2_PATH_PID'}=$instance_manager->{instances}->[1]->{path_pid}; - if ( $glob_cygwin_perl ) - { - foreach my $key ('MYSQL_TEST_WINDIR','MASTER_MYSOCK') - { - $ENV{$key}= `cygpath -w $ENV{$key}`; - $ENV{$key} =~ s,\\,\\\\,g; - chomp($ENV{$key}); - } - } - $ENV{MTR_BUILD_THREAD}= 0 unless $ENV{MTR_BUILD_THREAD}; # Set if not set # We are nice and report a bit about our settings @@ -1507,8 +1517,8 @@ sub ndbcluster_start ($) { sub rm_ndbcluster_tables ($) { my $dir= shift; - foreach my $bin ( glob("$dir/cluster_replication/apply_status*"), - glob("$dir/cluster_replication/schema*") ) + foreach my $bin ( glob("$dir/cluster/apply_status*"), + glob("$dir/cluster/schema*") ) { unlink($bin); } @@ -2490,12 +2500,12 @@ sub mysqld_arguments ($$$$$$) { if ( $type eq 'master' ) { mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/master%s.trace", - $prefix, $opt_vardir, $sidx); + $prefix, $opt_vardir_trace, $sidx); } if ( $type eq 'slave' ) { mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/slave%s.trace", - $prefix, $opt_vardir, $sidx); + $prefix, $opt_vardir_trace, $sidx); } } @@ -2876,7 +2886,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { $cmdline_mysqlcheck .= - " --debug=d:t:A,$opt_vardir/log/mysqldump.trace"; + " --debug=d:t:A,$opt_vardir_trace/log/mysqlcheck.trace"; } my $cmdline_mysqldump= "$exe_mysqldump --no-defaults -uroot " . @@ -2889,7 +2899,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { $cmdline_mysqldump .= - " --debug=d:t:A,$opt_vardir/log/mysqldump.trace"; + " --debug=d:t:A,$opt_vardir_trace/log/mysqldump.trace"; } my $cmdline_mysqlslap; @@ -2903,7 +2913,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { $cmdline_mysqlslap .= - " --debug=d:t:A,$opt_vardir/log/mysqldump.trace"; + " --debug=d:t:A,$opt_vardir_trace/log/mysqlslap.trace"; } } @@ -2913,7 +2923,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { $cmdline_mysqlimport .= - " --debug=d:t:A,$opt_vardir/log/mysqlimport.trace"; + " --debug=d:t:A,$opt_vardir_trace/log/mysqlimport.trace"; } my $cmdline_mysqlshow= "$exe_mysqlshow -uroot " . @@ -2922,7 +2932,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { $cmdline_mysqlshow .= - " --debug=d:t:A,$opt_vardir/log/mysqlshow.trace"; + " --debug=d:t:A,$opt_vardir_trace/log/mysqlshow.trace"; } my $cmdline_mysqlbinlog= @@ -2933,7 +2943,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { $cmdline_mysqlbinlog .= - " --debug=d:t:A,$opt_vardir/log/mysqlbinlog.trace"; + " --debug=d:t:A,$opt_vardir_trace/log/mysqlbinlog.trace"; } my $cmdline_mysql= @@ -3075,7 +3085,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { - mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace", $opt_vardir); + mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace", $opt_vardir_trace); } if ( $opt_ssl_supported ) @@ -3255,6 +3265,7 @@ Options for coverage, profiling etc Misc options + comment=STR Write STR to the output verbose Verbose output from this script script-debug Debug this script itself timer Show test case execution time diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 212f0b9beb4..41a9a206306 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -19,6 +19,8 @@ TZ=$MY_TZ; export TZ # for UNIX_TIMESTAMP tests to work LOCAL_SOCKET=@MYSQL_UNIX_ADDR@ MYSQL_TCP_PORT=@MYSQL_TCP_PORT@ +umask 022 + # For query_cache test case `uname` in SCO_SV | UnixWare | OpenUNIX ) @@ -202,6 +204,7 @@ SYST=0 REALT=0 FAST_START="" MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp +export MYSQL_TMP_DIR # Use a relative path for where the slave will find the dumps # generated by "LOAD DATA" on the master. The path is relative @@ -217,8 +220,8 @@ MY_LOG_DIR="$MYSQL_TEST_DIR/var/log" # # Set LD_LIBRARY_PATH if we are using shared libraries # -LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/zlib/.libs:$LD_LIBRARY_PATH" -DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/zlib/.libs:$DYLD_LIBRARY_PATH" +LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/libmysql_r/.libs:$BASEDIR/zlib/.libs:$LD_LIBRARY_PATH" +DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/libmysql_r/.libs:$BASEDIR/zlib/.libs:$DYLD_LIBRARY_PATH" export LD_LIBRARY_PATH DYLD_LIBRARY_PATH # @@ -600,7 +603,14 @@ while test $# -gt 0; do FAST_START=1 ;; --use-old-data) - USE_OLD_DATA=1; + USE_OLD_DATA=1 + ;; + --comment=*) + TMP=`$ECHO "$1" | $SED -e "s;--comment=;;"` + echo + echo '############################################' + echo "# $TMP" + echo '############################################' ;; -- ) shift; break ;; --* ) $ECHO "Unrecognized option: $1"; exit 1 ;; @@ -961,7 +971,7 @@ show_failed_diff () $DIFF -c $result_file $reject_file echo "-------------------------------------------------------" echo "Please follow the instructions outlined at" - echo "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html" + echo "http://dev.mysql.com/doc/mysql/en/reporting-mysqltest-bugs.html" echo "to find the reason to this problem and how to report this." echo "" fi @@ -1061,7 +1071,7 @@ report_stats () { $ECHO "The log files in $MY_LOG_DIR may give you some hint" $ECHO "of what went wrong." $ECHO "If you want to report this error, please read first the documentation at" - $ECHO "http://www.mysql.com/doc/en/MySQL_test_suite.html" + $ECHO "http://dev.mysql.com/doc/mysql/en/mysql-test-suite.html" fi if [ $USE_RUNNING_SERVER -eq 0 ] @@ -1325,8 +1335,8 @@ start_ndbcluster() rm_ndbcluster_tables() { - $RM -f $1/cluster_replication/apply_status* - $RM -f $1/cluster_replication/schema* + $RM -f $1/cluster/apply_status* + $RM -f $1/cluster/schema* } stop_ndbcluster() diff --git a/mysql-test/ndb/Makefile.am b/mysql-test/ndb/Makefile.am index 1ef02bec1f0..2a1c59fd359 100644 --- a/mysql-test/ndb/Makefile.am +++ b/mysql-test/ndb/Makefile.am @@ -1,4 +1,6 @@ +BUILT_SOURCES = ndbcluster + benchdir_root= $(prefix) testdir = $(benchdir_root)/mysql-test/ndb diff --git a/mysql-test/r/archive_gis.result b/mysql-test/r/archive_gis.result index 20e427b91a9..3017a811fb0 100644 --- a/mysql-test/r/archive_gis.result +++ b/mysql-test/r/archive_gis.result @@ -1,50 +1,51 @@ SET storage_engine=archive; DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; -CREATE TABLE gis_point (fid INTEGER, g POINT); -CREATE TABLE gis_line (fid INTEGER, g LINESTRING); -CREATE TABLE gis_polygon (fid INTEGER, g POLYGON); -CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT); -CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING); -CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON); -CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION); -CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY); +CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT); +CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY); SHOW CREATE TABLE gis_point; Table Create Table gis_point CREATE TABLE `gis_point` ( - `fid` int(11) DEFAULT NULL, - `g` point DEFAULT NULL + `fid` int(11) NOT NULL AUTO_INCREMENT, + `g` point DEFAULT NULL, + PRIMARY KEY (`fid`) ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g point YES NULL SHOW FIELDS FROM gis_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g linestring YES NULL SHOW FIELDS FROM gis_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g polygon YES NULL SHOW FIELDS FROM gis_multi_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipoint YES NULL SHOW FIELDS FROM gis_multi_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multilinestring YES NULL SHOW FIELDS FROM gis_multi_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipolygon YES NULL SHOW FIELDS FROM gis_geometrycollection; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometrycollection YES NULL SHOW FIELDS FROM gis_geometry; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometry YES NULL INSERT INTO gis_point VALUES (101, PointFromText('POINT(10 10)')), @@ -407,6 +408,7 @@ Warnings: Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,overlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,equals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,disjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,intersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid` DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; CREATE TABLE t1 ( +a INTEGER PRIMARY KEY AUTO_INCREMENT, gp point, ln linestring, pg polygon, @@ -418,6 +420,7 @@ gm geometry ); SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -429,6 +432,7 @@ gm geometry YES NULL ALTER TABLE t1 ADD fid INT; SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -439,20 +443,20 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) YES NULL DROP TABLE t1; -create table t1 (a geometry not null); -insert into t1 values (GeomFromText('Point(1 2)')); -insert into t1 values ('Garbage'); +create table t1 (pk integer primary key auto_increment, a geometry not null); +insert into t1 (a) values (GeomFromText('Point(1 2)')); +insert into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert IGNORE into t1 values ('Garbage'); +insert IGNORE into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; -create table t1 (fl geometry); -insert into t1 values (1); +create table t1 (pk integer primary key auto_increment, fl geometry); +insert into t1 (fl) values (1); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (1.11); +insert into t1 (fl) values (1.11); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values ("qwerty"); +insert into t1 (fl) values ("qwerty"); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (pointfromtext('point(1,1)')); +insert into t1 (fl) values (pointfromtext('point(1,1)')); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; diff --git a/mysql-test/r/backup.result b/mysql-test/r/backup.result index 1207b6b7070..81090c17791 100644 --- a/mysql-test/r/backup.result +++ b/mysql-test/r/backup.result @@ -6,26 +6,26 @@ Table Op Msg_type Msg_text test.t4 backup error Failed copying .frm file (errno: X) test.t4 backup status Operation failed Warnings: -Warning 1540 The 'BACKUP TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. Error 1 Can't create/write to file 'MYSQLTEST_VARDIR/bogus/t4.frm' (Errcode: X) backup table t4 to '../tmp'; Table Op Msg_type Msg_text test.t4 backup status OK Warnings: -Warning 1540 The 'BACKUP TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. backup table t4 to '../tmp'; Table Op Msg_type Msg_text test.t4 backup error Failed copying .frm file (errno: X) test.t4 backup status Operation failed Warnings: -Warning 1540 The 'BACKUP TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. Error 1 Can't create/write to file 'MYSQLTEST_VARDIR/tmp/t4.frm' (Errcode: X) drop table t4; restore table t4 from '../tmp'; Table Op Msg_type Msg_text test.t4 restore status OK Warnings: -Warning 1540 The 'RESTORE TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. select count(*) from t4; count(*) 0 @@ -35,19 +35,19 @@ backup table t1 to '../tmp'; Table Op Msg_type Msg_text test.t1 backup status OK Warnings: -Warning 1540 The 'BACKUP TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. drop table t1; restore table t1 from '../bogus'; Table Op Msg_type Msg_text t1 restore error Failed copying .frm file Warnings: -Warning 1540 The 'RESTORE TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. Error 29 File 'MYSQLTEST_VARDIR/bogus/t1.frm' not found (Errcode: X) restore table t1 from '../tmp'; Table Op Msg_type Msg_text test.t1 restore status OK Warnings: -Warning 1540 The 'RESTORE TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. select n from t1; n 23 @@ -62,7 +62,7 @@ Table Op Msg_type Msg_text test.t2 backup status OK test.t3 backup status OK Warnings: -Warning 1540 The 'BACKUP TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. drop table t1,t2,t3; restore table t1,t2,t3 from '../tmp'; Table Op Msg_type Msg_text @@ -70,7 +70,7 @@ test.t1 restore status OK test.t2 restore status OK test.t3 restore status OK Warnings: -Warning 1540 The 'RESTORE TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. select n from t1; n 23 @@ -91,7 +91,7 @@ restore table t1 from '../tmp'; Table Op Msg_type Msg_text test.t1 restore status OK Warnings: -Warning 1540 The 'RESTORE TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. rename table t1 to t5; lock tables t5 write; backup table t5 to '../tmp'; @@ -99,5 +99,5 @@ unlock tables; Table Op Msg_type Msg_text test.t5 backup status OK Warnings: -Warning 1540 The 'BACKUP TABLE' statement is deprecated and will be removed in MySQL 5.2. Please use client programs (e.g. mysqldump, mysql, MySQL Administrator) instead. +Warning 1540 The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 5.2. Please use MySQL Administrator (mysqldump, mysql) instead. drop table t5; diff --git a/mysql-test/r/bdb_gis.result b/mysql-test/r/bdb_gis.result index 0dadceed04e..969cdb34788 100644 --- a/mysql-test/r/bdb_gis.result +++ b/mysql-test/r/bdb_gis.result @@ -1,50 +1,51 @@ SET storage_engine=bdb; DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; -CREATE TABLE gis_point (fid INTEGER, g POINT); -CREATE TABLE gis_line (fid INTEGER, g LINESTRING); -CREATE TABLE gis_polygon (fid INTEGER, g POLYGON); -CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT); -CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING); -CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON); -CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION); -CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY); +CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT); +CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY); SHOW CREATE TABLE gis_point; Table Create Table gis_point CREATE TABLE `gis_point` ( - `fid` int(11) DEFAULT NULL, - `g` point DEFAULT NULL + `fid` int(11) NOT NULL AUTO_INCREMENT + `g` point DEFAULT NULL, + PRIMARY KEY (`fid`) ) ENGINE=BerkeleyDB DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g point YES NULL SHOW FIELDS FROM gis_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g linestring YES NULL SHOW FIELDS FROM gis_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g polygon YES NULL SHOW FIELDS FROM gis_multi_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipoint YES NULL SHOW FIELDS FROM gis_multi_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multilinestring YES NULL SHOW FIELDS FROM gis_multi_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipolygon YES NULL SHOW FIELDS FROM gis_geometrycollection; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometrycollection YES NULL SHOW FIELDS FROM gis_geometry; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometry YES NULL INSERT INTO gis_point VALUES (101, PointFromText('POINT(10 10)')), @@ -407,6 +408,7 @@ Warnings: Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,overlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,equals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,disjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,intersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid` DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; CREATE TABLE t1 ( +a INTEGER PRIMARY KEY AUTO_INCREMENT, gp point, ln linestring, pg polygon, @@ -418,6 +420,7 @@ gm geometry ); SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -429,6 +432,7 @@ gm geometry YES NULL ALTER TABLE t1 ADD fid INT; SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -439,20 +443,20 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) YES NULL DROP TABLE t1; -create table t1 (a geometry not null); -insert into t1 values (GeomFromText('Point(1 2)')); -insert into t1 values ('Garbage'); +create table t1 (pk integer primary key auto_increment, a geometry not null); +insert into t1 (a) values (GeomFromText('Point(1 2)')); +insert into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert IGNORE into t1 values ('Garbage'); +insert IGNORE into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; -create table t1 (fl geometry); -insert into t1 values (1); +create table t1 (pk integer primary key auto_increment, fl geometry); +insert into t1 (fl) values (1); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (1.11); +insert into t1 (fl) values (1.11); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values ("qwerty"); +insert into t1 (fl) values ("qwerty"); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (pointfromtext('point(1,1)')); +insert into t1 (fl) values (pointfromtext('point(1,1)')); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; diff --git a/mysql-test/r/bigint.result b/mysql-test/r/bigint.result index 039dc0980ce..c76385fa334 100644 --- a/mysql-test/r/bigint.result +++ b/mysql-test/r/bigint.result @@ -332,3 +332,12 @@ SELECT * FROM t1; col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 col11 col12 col13 col14 col15 col16 col17 col18 col19 col20 col21 col22 col23 col24 col25 col26 col27 col28 col29 col30 col31 col32 col33 col34 col35 col36 col37 col38 fix1 fix2 fix3 fix4 fix5 fix6 fix7 fix8 fix9 fix10 fix11 fix12 fix13 fix14 fix15 fix16 fix17 fix18 fix19 fix20 fix21 fix22 fix23 fix24 fix25 fix26 fix27 fix28 fix29 fix30 9 99 999 9999 99999 999999 9999999 99999999 999999999 9999999999 99999999999 999999999999 9999999999999 99999999999999 999999999999999 9999999999999999 99999999999999999 999999999999999999 9999999999999999999 99999999999999999999 999999999999999999999 9999999999999999999999 99999999999999999999999 999999999999999999999999 9999999999999999999999999 99999999999999999999999999 999999999999999999999999999 9999999999999999999999999999 99999999999999999999999999999 999999999999999999999999999999 9999999999999999999999999999999 99999999999999999999999999999999 999999999999999999999999999999999 9999999999999999999999999999999999 99999999999999999999999999999999999 999999999999999999999999999999999999 9999999999999999999999999999999999999 99999999999999999999999999999999999999 9999999999999999999999999999999999999.9 999999999999999999999999999999999999.99 99999999999999999999999999999999999.999 9999999999999999999999999999999999.9999 999999999999999999999999999999999.99999 99999999999999999999999999999999.999999 9999999999999999999999999999999.9999999 999999999999999999999999999999.99999999 99999999999999999999999999999.999999999 9999999999999999999999999999.9999999999 999999999999999999999999999.99999999999 99999999999999999999999999.999999999999 9999999999999999999999999.9999999999999 999999999999999999999999.99999999999999 99999999999999999999999.999999999999999 9999999999999999999999.9999999999999999 999999999999999999999.99999999999999999 99999999999999999999.999999999999999999 9999999999999999999.9999999999999999999 999999999999999999.99999999999999999999 99999999999999999.999999999999999999999 9999999999999999.9999999999999999999999 999999999999999.99999999999999999999999 99999999999999.999999999999999999999999 9999999999999.9999999999999999999999999 999999999999.99999999999999999999999999 99999999999.999999999999999999999999999 9999999999.9999999999999999999999999999 999999999.99999999999999999999999999999 99999999.999999999999999999999999999999 DROP TABLE t1; +create table t1 (bigint_col bigint unsigned); +insert into t1 values (17666000000000000000); +select * from t1 where bigint_col=17666000000000000000; +bigint_col +17666000000000000000 +select * from t1 where bigint_col='17666000000000000000'; +bigint_col +17666000000000000000 +drop table t1; diff --git a/mysql-test/r/binary.result b/mysql-test/r/binary.result index 99d9c4dad02..ccafa43c7ab 100644 --- a/mysql-test/r/binary.result +++ b/mysql-test/r/binary.result @@ -141,3 +141,22 @@ t1 CREATE TABLE `t1` ( `a` binary(1) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +create table t1 (col1 binary(4)); +insert into t1 values ('a'),('a '); +select hex(col1) from t1; +hex(col1) +61000000 +61200000 +alter table t1 modify col1 binary(10); +select hex(col1) from t1; +hex(col1) +61000000000000000000 +61200000000000000000 +insert into t1 values ('b'),('b '); +select hex(col1) from t1; +hex(col1) +61000000000000000000 +61200000000000000000 +62000000000000000000 +62200000000000000000 +drop table t1; diff --git a/mysql-test/r/binlog_row_ctype_cp932.result b/mysql-test/r/binlog_row_ctype_cp932.result index 6d213158ef6..ed57b87c1ba 100644 --- a/mysql-test/r/binlog_row_ctype_cp932.result +++ b/mysql-test/r/binlog_row_ctype_cp932.result @@ -11315,20 +11315,6 @@ DROP TABLE t1; DROP TABLE t2; DROP TABLE t3; DROP TABLE t4; -RESET MASTER; -CREATE TABLE t1(f1 blob); -PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)'; -SET @var1= x'8300'; -EXECUTE stmt1 USING @var1; -SHOW BINLOG EVENTS FROM 102; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 102 Query 1 189 use `test`; CREATE TABLE t1(f1 blob) -master-bin.000001 189 Table_map 1 228 test.t1 -master-bin.000001 228 Write_rows 1 262 -SELECT HEX(f1) FROM t1; -HEX(f1) -8300 -DROP table t1; SET collation_connection='cp932_japanese_ci'; create table t1 select repeat('a',4000) a; delete from t1; diff --git a/mysql-test/r/binlog_row_insert_select.result b/mysql-test/r/binlog_row_insert_select.result index 90a8a5473e9..0a98a6d7233 100644 --- a/mysql-test/r/binlog_row_insert_select.result +++ b/mysql-test/r/binlog_row_insert_select.result @@ -1,3 +1,4 @@ +drop table if exists t1,t2; create table t1(a int, unique(a)); insert into t1 values(2); create table t2(a int); diff --git a/mysql-test/r/binlog_stm_ctype_cp932.result b/mysql-test/r/binlog_stm_ctype_cp932.result index 470ae3b5ab2..ed57b87c1ba 100755 --- a/mysql-test/r/binlog_stm_ctype_cp932.result +++ b/mysql-test/r/binlog_stm_ctype_cp932.result @@ -11315,20 +11315,6 @@ DROP TABLE t1; DROP TABLE t2; DROP TABLE t3; DROP TABLE t4; -RESET MASTER; -CREATE TABLE t1(f1 blob); -PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)'; -SET @var1= x'8300'; -EXECUTE stmt1 USING @var1; -SHOW BINLOG EVENTS FROM 102; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 102 Query 1 189 use `test`; CREATE TABLE t1(f1 blob) -master-bin.000001 189 User var 1 228 @`var1`=_binary 0x8300 COLLATE binary -master-bin.000001 228 Query 1 321 use `test`; INSERT INTO t1 VALUES(@'var1') -SELECT HEX(f1) FROM t1; -HEX(f1) -8300 -DROP table t1; SET collation_connection='cp932_japanese_ci'; create table t1 select repeat('a',4000) a; delete from t1; diff --git a/mysql-test/r/binlog_stm_insert_select.result b/mysql-test/r/binlog_stm_insert_select.result index 35e328a769c..646a76b254d 100644 --- a/mysql-test/r/binlog_stm_insert_select.result +++ b/mysql-test/r/binlog_stm_insert_select.result @@ -1,3 +1,4 @@ +drop table if exists t1,t2; create table t1(a int, unique(a)); insert into t1 values(2); create table t2(a int); diff --git a/mysql-test/r/case.result b/mysql-test/r/case.result index 415ec1ac748..d28c3af4e0b 100644 --- a/mysql-test/r/case.result +++ b/mysql-test/r/case.result @@ -1,4 +1,4 @@ -drop table if exists t1; +drop table if exists t1,t2; select CASE "b" when "a" then 1 when "b" then 2 END; CASE "b" when "a" then 1 when "b" then 2 END 2 diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index acee1eb87c8..edc0ec0d01e 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -770,3 +770,9 @@ t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 MAX_ROWS=4294967295 drop table t1; +create table t1(f1 varchar(800) binary not null, key(f1)) engine = innodb +character set utf8 collate utf8_general_ci; +Warnings: +Warning 1071 Specified key was too long; max key length is 765 bytes +insert into t1 values('aaa'); +drop table t1; diff --git a/mysql-test/r/ctype_cp932_notembedded.result b/mysql-test/r/ctype_cp932_notembedded.result deleted file mode 100644 index 913e8125619..00000000000 --- a/mysql-test/r/ctype_cp932_notembedded.result +++ /dev/null @@ -1,17 +0,0 @@ -drop table if exists t1; -set names cp932; -set character_set_database = cp932; -RESET MASTER; -CREATE TABLE t1(f1 blob); -PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)'; -SET @var1= x'8300'; -EXECUTE stmt1 USING @var1; -SHOW BINLOG EVENTS FROM 102; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query 1 # use `test`; CREATE TABLE t1(f1 blob) -master-bin.000001 # Table_map 1 # test.t1 -master-bin.000001 # Write_rows 1 # -SELECT HEX(f1) FROM t1; -HEX(f1) -8300 -DROP table t1; diff --git a/mysql-test/r/drop.result b/mysql-test/r/drop.result index 02342485c04..fb8c4fb9b37 100644 --- a/mysql-test/r/drop.result +++ b/mysql-test/r/drop.result @@ -47,7 +47,7 @@ create database mysqltest; show databases; Database information_schema -cluster_replication +cluster mysql mysqltest test @@ -59,7 +59,7 @@ drop database mysqltest; show databases; Database information_schema -cluster_replication +cluster mysql test drop database mysqltest; diff --git a/mysql-test/r/events.result b/mysql-test/r/events.result index f7aa6e2bb58..ecaf1ec252e 100644 --- a/mysql-test/r/events.result +++ b/mysql-test/r/events.result @@ -37,6 +37,54 @@ alter event event3 rename to event2; drop event event2; create event event2 on schedule every 2 second starts now() ends date_add(now(), interval 5 hour) comment "some" DO begin end; drop event event2; +CREATE EVENT event_starts_test ON SCHEDULE EVERY 10 SECOND COMMENT "" DO SELECT 1; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost RECURRING NULL 10 SECOND # # ENABLED +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +starts IS NULL ends IS NULL comment +0 1 +ALTER EVENT event_starts_test ON SCHEDULE AT '2020-02-02 20:00:02'; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost ONE TIME 2020-02-02 17:00:02 NULL NULL # # ENABLED +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +starts IS NULL ends IS NULL comment +1 1 +ALTER EVENT event_starts_test COMMENT "non-empty comment"; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost ONE TIME 2020-02-02 17:00:02 NULL NULL # # ENABLED +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +starts IS NULL ends IS NULL comment +1 1 non-empty comment +ALTER EVENT event_starts_test COMMENT ""; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost ONE TIME 2020-02-02 17:00:02 NULL NULL # # ENABLED +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +starts IS NULL ends IS NULL comment +1 1 +DROP EVENT event_starts_test; +CREATE EVENT event_starts_test ON SCHEDULE EVERY 20 SECOND STARTS '2020-02-02 20:00:02' ENDS '2022-02-02 20:00:02' DO SELECT 2; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost RECURRING NULL 20 SECOND # # ENABLED +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +starts IS NULL ends IS NULL comment +0 0 +ALTER EVENT event_starts_test COMMENT "non-empty comment"; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost RECURRING NULL 20 SECOND # # ENABLED +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +starts IS NULL ends IS NULL comment +0 0 non-empty comment +ALTER EVENT event_starts_test COMMENT ""; +SHOW EVENTS; +Db Name Definer Type Execute at Interval value Interval field Starts Ends Status +events_test event_starts_test root@localhost RECURRING NULL 20 SECOND # # ENABLED +DROP EVENT event_starts_test; create event e_43 on schedule every 1 second do set @a = 5; set global event_scheduler = 1; alter event e_43 do alter event e_43 do set @a = 4; diff --git a/mysql-test/r/events_logs_tests.result b/mysql-test/r/events_logs_tests.result new file mode 100644 index 00000000000..e6ca3c29e9b --- /dev/null +++ b/mysql-test/r/events_logs_tests.result @@ -0,0 +1,84 @@ +create database if not exists events_test; +use events_test; +"We use procedure here because its statements won't be logged into the general log" +"If we had used normal select that are logged in different ways depending on whether" +"the test suite is run in normal mode or with --ps-protocol" +CREATE procedure select_general_log() +BEGIN +SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%'; +END| +"Check General Query Log" +SET GLOBAL event_scheduler=0; +create event log_general on schedule every 1 minute do SELect 'alabala', sleep(3) from dual; +TRUNCATE mysql.general_log; +"1 row, the current statement!" +call select_general_log(); +user_host argument +SET GLOBAL event_scheduler=1; +"Wait the scheduler to start" +"Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" +call select_general_log(); +user_host argument +root[root] @ localhost [localhost] SELect 'alabala', sleep(3) from dual +DROP PROCEDURE select_general_log; +DROP EVENT log_general; +SET GLOBAL event_scheduler=0; +"Check slow query log" +"Save the values" +SET @old_global_long_query_time:=(select get_value()); +SET @old_session_long_query_time:=@@long_query_time; +SHOW VARIABLES LIKE 'log_slow_queries'; +Variable_name Value +log_slow_queries ON +DROP FUNCTION get_value; +TRUNCATE mysql.slow_log; +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +user_host query_time db sql_text +"Set new values" +SET GLOBAL long_query_time=4; +SET SESSION long_query_time=2; +"Check that logging is working" +SELECT SLEEP(3); +SLEEP(3) +0 +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +user_host query_time db sql_text +root[root] @ localhost [] 00:00:03 events_test SELECT SLEEP(3) +TRUNCATE mysql.slow_log; +CREATE TABLE slow_event_test (slo_val tinyint, val tinyint); +"This won't go to the slow log" +CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(3); +SELECT * FROM slow_event_test; +slo_val val +SET GLOBAL event_scheduler=1; +"Sleep some more time than the actual event run will take" +SHOW VARIABLES LIKE 'event_scheduler'; +Variable_name Value +event_scheduler ON +"Check our table. Should see 1 row" +SELECT * FROM slow_event_test; +slo_val val +4 0 +"Check slow log. Should not see anything because 3 is under the threshold of 4 for GLOBAL, though over SESSION which is 2" +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +user_host query_time db sql_text +"This should go to the slow log" +SET SESSION long_query_time=10; +DROP EVENT long_event; +CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(5); +"Sleep some more time than the actual event run will take" +"Check our table. Should see 2 rows" +SELECT * FROM slow_event_test; +slo_val val +4 0 +4 0 +"Check slow log. Should see 1 row because 5 is over the threshold of 4 for GLOBAL, though under SESSION which is 10" +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +user_host query_time db sql_text +root[root] @ localhost [localhost] 00:00:05 events_test INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(5) +DROP EVENT long_event2; +SET GLOBAL long_query_time =@old_global_long_query_time; +SET SESSION long_query_time =@old_session_long_query_time; +TRUNCATE mysql.slow_log; +DROP TABLE slow_event_test; +drop database events_test; diff --git a/mysql-test/r/events_microsec.result b/mysql-test/r/events_microsec.result new file mode 100644 index 00000000000..ed15b066b93 --- /dev/null +++ b/mysql-test/r/events_microsec.result @@ -0,0 +1,59 @@ +create database if not exists events_test; +use events_test; +CREATE EVENT micro_test ON SCHEDULE EVERY 100 MICROSECOND DO SELECT 1; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +CREATE EVENT micro_test ON SCHEDULE EVERY 100 DAY_MICROSECOND DO SELECT 1; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +CREATE EVENT micro_test ON SCHEDULE EVERY 100 HOUR_MICROSECOND DO SELECT 1; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +CREATE EVENT micro_test ON SCHEDULE EVERY 100 MINUTE_MICROSECOND DO SELECT 1; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +CREATE EVENT micro_test ON SCHEDULE EVERY 100 SECOND_MICROSECOND DO SELECT 1; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +"Now create normal event and change it on SQL level" +CREATE EVENT micro_test2 ON SCHEDULE EVERY 1 MONTH DO SELECT 1; +UPDATE mysql.event SET interval_field='MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +SHOW CREATE EVENT micro_test2; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +SET GLOBAL event_scheduler=0; +"Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +Variable_name Value +event_scheduler OFF +UPDATE mysql.event SET interval_field='DAY_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +SHOW CREATE EVENT micro_test2; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +SET GLOBAL event_scheduler=0; +"Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +Variable_name Value +event_scheduler OFF +UPDATE mysql.event SET interval_field='SECOND_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +SHOW CREATE EVENT micro_test2; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +SET GLOBAL event_scheduler=0; +"Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +Variable_name Value +event_scheduler OFF +UPDATE mysql.event SET interval_field='HOUR_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +SHOW CREATE EVENT micro_test2; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +SET GLOBAL event_scheduler=0; +"Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +Variable_name Value +event_scheduler OFF +UPDATE mysql.event SET interval_field='MINUTE_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +SHOW CREATE EVENT micro_test2; +ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' +SET GLOBAL event_scheduler=0; +"Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +Variable_name Value +event_scheduler OFF +SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='event_scheduler'; +COUNT(*) +0 +DROP EVENT micro_test2; +drop database events_test; diff --git a/mysql-test/r/func_system.result b/mysql-test/r/func_system.result index 9871de0f27c..e186afdfafa 100644 --- a/mysql-test/r/func_system.result +++ b/mysql-test/r/func_system.result @@ -42,13 +42,13 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 select sql_no_cache database() AS `database()`,user() AS `user()` -create table t1 (version char(40)) select database(), user(), version() as 'version'; +create table t1 (version char(60)) select database(), user(), version() as 'version'; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `database()` varchar(34) CHARACTER SET utf8 DEFAULT NULL, `user()` varchar(77) CHARACTER SET utf8 NOT NULL DEFAULT '', - `version` char(40) DEFAULT NULL + `version` char(60) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select charset(charset(_utf8'a')), charset(collation(_utf8'a')); diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 45ab83a0cfc..661b7141a59 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -448,7 +448,7 @@ Create view Tables To create new views Create user Server Admin To create new users Delete Tables To delete existing rows Drop Databases,Tables To drop databases, tables, and views -Event Server Admin Creation, alteration, deletion and execution of events. +Event Server Admin To create, alter, drop and execute events Execute Functions,Procedures To execute stored routines File File access on server To read and write files on the server Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result index e38953b6446..6c6e0f19e08 100644 --- a/mysql-test/r/grant2.result +++ b/mysql-test/r/grant2.result @@ -334,3 +334,24 @@ lock table mysql.user write; revoke all on *.* from 'mysqltest_1'@'localhost'; unlock tables; drop user 'mysqltest_1'@'localhost'; +create database TESTDB; +create table t2(a int); +create temporary table t1 as select * from mysql.user; +delete from mysql.user where host='localhost'; +INSERT INTO mysql.user (host, user, password) VALUES +('%','mysqltest_1',password('password')); +Warnings: +Warning 1364 Field 'ssl_cipher' doesn't have a default value +Warning 1364 Field 'x509_issuer' doesn't have a default value +Warning 1364 Field 'x509_subject' doesn't have a default value +INSERT INTO mysql.db (host, db, user, select_priv) VALUES +('%','TESTDB','mysqltest_1','Y'); +FLUSH PRIVILEGES; +create database TEStdb; +Got one of the listed errors +delete from mysql.user; +delete from mysql.db where host='%' and user='mysqltest_1' and db='TESTDB'; +insert into mysql.user select * from t1; +drop table t1, t2; +drop database TESTDB; +flush privileges; diff --git a/mysql-test/r/index_merge.result b/mysql-test/r/index_merge.result index db87253e19a..3a69f56cbd3 100644 --- a/mysql-test/r/index_merge.result +++ b/mysql-test/r/index_merge.result @@ -402,3 +402,25 @@ explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'b id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index_merge cola,colb cola,colb 3,3 NULL 24 Using intersect(cola,colb); Using where drop table t1; +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 ( +a int, b int, +filler1 char(200), filler2 char(200), +key(a),key(b) +); +insert into t1 select @v:= A.a, @v, 't1', 'filler2' from t0 A, t0 B, t0 C; +create table t2 like t1; +create table t3 ( +a int, b int, +filler1 char(200), filler2 char(200), +key(a),key(b) +) engine=merge union=(t1,t2); +explain select * from t1 where a=1 and b=1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge a,b a,b 5,5 NULL # Using intersect(a,b); Using where +explain select * from t3 where a=1 and b=1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t3 index_merge a,b a,b 5,5 NULL # Using intersect(a,b); Using where +drop table t3; +drop table t0, t1, t2; diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 02718b89619..457235e7003 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -14,7 +14,7 @@ NULL test latin1 latin1_swedish_ci NULL select schema_name from information_schema.schemata; schema_name information_schema -cluster_replication +cluster mysql test show databases like 't%'; @@ -23,7 +23,7 @@ test show databases; Database information_schema -cluster_replication +cluster mysql test show databases where `database` = 't%'; @@ -339,7 +339,7 @@ create view v0 (c) as select schema_name from information_schema.schemata; select * from v0; c information_schema -cluster_replication +cluster mysql test explain select * from v0; @@ -835,7 +835,7 @@ delete from mysql.db where user='mysqltest_4'; flush privileges; SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA; table_schema count(*) -cluster_replication 1 +cluster 1 information_schema 22 mysql 21 create table t1 (i int, j int); diff --git a/mysql-test/r/innodb_gis.result b/mysql-test/r/innodb_gis.result index 849c67019ad..0222c462923 100644 --- a/mysql-test/r/innodb_gis.result +++ b/mysql-test/r/innodb_gis.result @@ -1,50 +1,51 @@ SET storage_engine=innodb; DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; -CREATE TABLE gis_point (fid INTEGER, g POINT); -CREATE TABLE gis_line (fid INTEGER, g LINESTRING); -CREATE TABLE gis_polygon (fid INTEGER, g POLYGON); -CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT); -CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING); -CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON); -CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION); -CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY); +CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT); +CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY); SHOW CREATE TABLE gis_point; Table Create Table gis_point CREATE TABLE `gis_point` ( - `fid` int(11) DEFAULT NULL, - `g` point DEFAULT NULL + `fid` int(11) NOT NULL AUTO_INCREMENT, + `g` point DEFAULT NULL, + PRIMARY KEY (`fid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g point YES NULL SHOW FIELDS FROM gis_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g linestring YES NULL SHOW FIELDS FROM gis_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g polygon YES NULL SHOW FIELDS FROM gis_multi_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipoint YES NULL SHOW FIELDS FROM gis_multi_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multilinestring YES NULL SHOW FIELDS FROM gis_multi_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipolygon YES NULL SHOW FIELDS FROM gis_geometrycollection; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometrycollection YES NULL SHOW FIELDS FROM gis_geometry; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometry YES NULL INSERT INTO gis_point VALUES (101, PointFromText('POINT(10 10)')), @@ -407,6 +408,7 @@ Warnings: Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,overlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,equals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,disjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,intersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid` DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; CREATE TABLE t1 ( +a INTEGER PRIMARY KEY AUTO_INCREMENT, gp point, ln linestring, pg polygon, @@ -418,6 +420,7 @@ gm geometry ); SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -429,6 +432,7 @@ gm geometry YES NULL ALTER TABLE t1 ADD fid INT; SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -439,20 +443,20 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) YES NULL DROP TABLE t1; -create table t1 (a geometry not null); -insert into t1 values (GeomFromText('Point(1 2)')); -insert into t1 values ('Garbage'); +create table t1 (pk integer primary key auto_increment, a geometry not null); +insert into t1 (a) values (GeomFromText('Point(1 2)')); +insert into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert IGNORE into t1 values ('Garbage'); +insert IGNORE into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; -create table t1 (fl geometry); -insert into t1 values (1); +create table t1 (pk integer primary key auto_increment, fl geometry); +insert into t1 (fl) values (1); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (1.11); +insert into t1 (fl) values (1.11); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values ("qwerty"); +insert into t1 (fl) values ("qwerty"); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (pointfromtext('point(1,1)')); +insert into t1 (fl) values (pointfromtext('point(1,1)')); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; diff --git a/mysql-test/r/innodb_notembedded.result b/mysql-test/r/innodb_notembedded.result index fc71468b97b..9aac20e515d 100644 --- a/mysql-test/r/innodb_notembedded.result +++ b/mysql-test/r/innodb_notembedded.result @@ -1,3 +1,4 @@ +drop table if exists t1; create table t1 (col1 integer primary key, col2 integer) engine=innodb; insert t1 values (1,100); create function f1 () returns integer begin diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index 724d1b1e39f..54536d6c32a 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -677,6 +677,11 @@ select t1.b from v1a; ERROR 42S22: Unknown column 't1.b' in 'field list' select * from v1a join v1b on t1.b = t2.b; ERROR 42S22: Unknown column 't1.b' in 'on clause' +select * from information_schema.statistics join information_schema.columns +using(table_name,column_name) where table_name='user'; +TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT +user Host NULL mysql 0 mysql PRIMARY 1 A NULL NULL NULL BTREE NULL mysql 1 NO char 20 60 NULL NULL utf8 utf8_bin char(60) PRI select,insert,update,references +user User NULL mysql 0 mysql PRIMARY 2 A 5 NULL NULL BTREE NULL mysql 2 NO char 5 16 NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references drop table t1; drop table t2; drop table t3; diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 561c430417b..538f1fa1a20 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -56,8 +56,8 @@ a b 4 Testing 5 table 5 table -6 t1 6 t2 +6 t1 7 Testing 7 Testing 8 table diff --git a/mysql-test/r/mysqlbinlog_base64.result b/mysql-test/r/mysqlbinlog_base64.result index 499587cb465..c31dbee56c6 100644 --- a/mysql-test/r/mysqlbinlog_base64.result +++ b/mysql-test/r/mysqlbinlog_base64.result @@ -5,7 +5,7 @@ insert into t1 values (3); update t1 set a=a+2 where a=2; update t1 set a=a+2 where a=3; create table t2 (word varchar(20)); -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; drop table t1; drop table t2; select * from t1; diff --git a/mysql-test/r/mysqlcheck.result b/mysql-test/r/mysqlcheck.result index bd4bbc15a4f..acdbd868361 100644 --- a/mysql-test/r/mysqlcheck.result +++ b/mysql-test/r/mysqlcheck.result @@ -1,4 +1,6 @@ -cluster_replication.binlog_index OK +DROP SCHEMA test; +CREATE SCHEMA test; +cluster.binlog_index OK mysql.columns_priv OK mysql.db OK mysql.event OK diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 73f676b6b69..e54dee1fcfd 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1464,7 +1464,10 @@ DROP TABLE IF EXISTS `v2`; ) */; /*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where (`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where (`t2`.`a` like _latin1'a%') */ +/*!50002 WITH CASCADED CHECK OPTION */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -1797,7 +1800,9 @@ DROP TABLE IF EXISTS `v1`; ) */; /*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v1` AS select `t1`.`a` AS `a` from `t1` */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -1853,7 +1858,10 @@ DROP TABLE IF EXISTS `v2`; ) */; /*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where (`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where (`t2`.`a` like _latin1'a%') */ +/*!50002 WITH CASCADED CHECK OPTION */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -1959,13 +1967,19 @@ DROP TABLE IF EXISTS `v3`; ) */; /*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `v3` where (`v3`.`b` in (1,2,3,4,5,6,7))*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `v3` where (`v3`.`b` in (1,2,3,4,5,6,7)) */; /*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `v3`.`a` AS `a` from (`v3` join `v1`) where ((`v1`.`a` = `v3`.`a`) and (`v3`.`b` = 3)) limit 1*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v2` AS select `v3`.`a` AS `a` from (`v3` join `v1`) where ((`v1`.`a` = `v3`.`a`) and (`v3`.`b` = 3)) limit 1 */; /*!50001 DROP TABLE IF EXISTS `v3`*/; /*!50001 DROP VIEW IF EXISTS `v3`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from `t1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v3` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from `t1` */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -2399,10 +2413,10 @@ drop table t1; set global time_zone=default; set time_zone=default; DROP TABLE IF EXISTS `t1 test`; +DROP TABLE IF EXISTS `t2 test`; CREATE TABLE `t1 test` ( `a1` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -DROP TABLE IF EXISTS `t2 test`; CREATE TABLE `t2 test` ( `a2` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; @@ -2534,13 +2548,19 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET l USE `test`; /*!50001 DROP TABLE IF EXISTS `v0`*/; /*!50001 DROP VIEW IF EXISTS `v0`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v0` AS select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`c` AS `c` from `v1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v0` AS select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`c` AS `c` from `v1` */; /*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from `t1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b`,`t1`.`c` AS `c` from `t1` */; /*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `v0`.`a` AS `a`,`v0`.`b` AS `b`,`v0`.`c` AS `c` from `v0`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v2` AS select `v0`.`a` AS `a`,`v0`.`b` AS `b`,`v0`.`c` AS `c` from `v0` */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -2650,6 +2670,68 @@ DELIMITER ; DROP TRIGGER tr1; DROP TABLE t1; +create table t1 (a int); +insert into t1 values (289), (298), (234), (456), (789); +create definer = CURRENT_USER view v1 as select * from t1; +create SQL SECURITY INVOKER view v2 as select * from t1; +create view v3 as select * from t1 with local check option; +create algorithm=merge view v4 as select * from t1 with cascaded check option; +create algorithm =temptable view v5 as select * from t1; +drop table t1; +drop view v1, v2, v3, v4, v5; +show tables; +Tables_in_test +t1 +v1 +v2 +v3 +v4 +v5 +select * from v3 order by a; +a +234 +289 +298 +456 +789 +drop table t1; +drop view v1, v2, v3, v4, v5; +create table t1 (a int, created datetime); +create table t2 (b int, created datetime); +create trigger tr1 before insert on t1 for each row set +new.created=now(); +create trigger tr2 after insert on t1 +for each row +begin +insert into t2 set b=new.a and created=new.created; +end| +drop trigger tr1; +drop trigger tr2; +drop table t1, t2; +show triggers; +Trigger Event Table Statement Timing Created sql_mode Definer +tr1 INSERT t1 set +new.created=now() BEFORE # root@localhost +tr2 INSERT t1 begin +insert into t2 set b=new.a and created=new.created; +end AFTER # root@localhost +drop trigger tr1; +drop trigger tr2; +drop table t1, t2; +/*!50003 CREATE FUNCTION `f`() RETURNS bigint(20) +return 42 */| +/*!50003 CREATE PROCEDURE `p`() +select 42 */| +show create function f; +Function sql_mode Create Function +f CREATE FUNCTION `f`() RETURNS bigint(20) +return 42 +show create procedure p; +Procedure sql_mode Create Procedure +p CREATE PROCEDURE `p`() +select 42 +drop function f; +drop procedure p; create table t1 (a text , b text); create table t2 (a text , b text); insert t1 values ("Duck, Duck", "goose"); diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index c3a234875df..169eb5424f9 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -223,7 +223,7 @@ mysqltest: At line 1: Missing arguments to let mysqltest: At line 1: Missing variable name in let mysqltest: At line 1: Missing assignment operator in let mysqltest: At line 1: Missing assignment operator in let -mysqltest: At line 1: Missing arguments to let +mysqltest: At line 1: Missing assignment operator in let mysqltest: At line 1: Missing variable name in let mysqltest: At line 1: Missing variable name in let mysqltest: At line 1: Missing assignment operator in let @@ -296,7 +296,9 @@ here is the sourced script In loop here is the sourced script mysqltest: At line 1: Missing argument to sleep +mysqltest: At line 1: Missing argument to real_sleep mysqltest: At line 1: Invalid argument to sleep "abc" +mysqltest: At line 1: Invalid argument to real_sleep "abc" 1 2 101 diff --git a/mysql-test/r/ndb_alter_table_row.result b/mysql-test/r/ndb_alter_table_row.result index 450b2c9a5af..ee7c9b1c7b0 100644 --- a/mysql-test/r/ndb_alter_table_row.result +++ b/mysql-test/r/ndb_alter_table_row.result @@ -3,10 +3,19 @@ create table t1 ( a int primary key, b varchar(10), c varchar(10), index (b) ) engine=ndb; insert into t1 values (1,'one','one'), (2,'two','two'), (3,'three','three'); create index c on t1(c); +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t1 0 PRIMARY 1 a A 3 NULL NULL BTREE +t1 1 b 1 b A 3 NULL NULL YES BTREE +t1 1 c 1 c A 3 NULL NULL YES BTREE select * from t1 where c = 'two'; a b c 2 two two alter table t1 drop index c; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t1 0 PRIMARY 1 a A 3 NULL NULL BTREE +t1 1 b 1 b A 3 NULL NULL YES BTREE select * from t1 where c = 'two'; a b c 2 two two diff --git a/mysql-test/r/ndb_binlog_basic.result b/mysql-test/r/ndb_binlog_basic.result index d84a331ee16..f51634d3d54 100644 --- a/mysql-test/r/ndb_binlog_basic.result +++ b/mysql-test/r/ndb_binlog_basic.result @@ -6,7 +6,7 @@ drop database mysqltest; use test; create table t1 (a int primary key) engine=ndb; insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); -select @max_epoch:=max(epoch)-1 from cluster_replication.binlog_index; +select @max_epoch:=max(epoch)-1 from cluster.binlog_index; @max_epoch:=max(epoch)-1 # delete from t1; @@ -19,25 +19,25 @@ update t2 set b=1 where a=3; delete from t2 where a=4; commit; drop table t2; -select inserts from cluster_replication.binlog_index where epoch > @max_epoch and inserts > 5; +select inserts from cluster.binlog_index where epoch > @max_epoch and inserts > 5; inserts 10 -select deletes from cluster_replication.binlog_index where epoch > @max_epoch and deletes > 5; +select deletes from cluster.binlog_index where epoch > @max_epoch and deletes > 5; deletes 10 select inserts,updates,deletes from -cluster_replication.binlog_index where epoch > @max_epoch and updates > 0; +cluster.binlog_index where epoch > @max_epoch and updates > 0; inserts updates deletes 2 1 1 select schemaops from -cluster_replication.binlog_index where epoch > @max_epoch and schemaops > 0; +cluster.binlog_index where epoch > @max_epoch and schemaops > 0; schemaops 1 1 1 flush logs; purge master logs before now(); -select count(*) from cluster_replication.binlog_index; +select count(*) from cluster.binlog_index; count(*) 0 create table t1 (a int primary key, b int) engine=ndb; @@ -46,17 +46,17 @@ use mysqltest; create table t1 (c int, d int primary key) engine=ndb; use test; insert into mysqltest.t1 values (2,1),(2,2); -select @max_epoch:=max(epoch)-1 from cluster_replication.binlog_index; +select @max_epoch:=max(epoch)-1 from cluster.binlog_index; @max_epoch:=max(epoch)-1 # drop table t1; drop database mysqltest; select inserts,updates,deletes from -cluster_replication.binlog_index where epoch > @max_epoch and inserts > 0; +cluster.binlog_index where epoch > @max_epoch and inserts > 0; inserts updates deletes 2 0 0 select schemaops from -cluster_replication.binlog_index where epoch > @max_epoch and schemaops > 0; +cluster.binlog_index where epoch > @max_epoch and schemaops > 0; schemaops 1 1 diff --git a/mysql-test/r/ndb_binlog_basic2.result b/mysql-test/r/ndb_binlog_basic2.result new file mode 100644 index 00000000000..9b9f642bd86 --- /dev/null +++ b/mysql-test/r/ndb_binlog_basic2.result @@ -0,0 +1,12 @@ +set session binlog_format=row; +ERROR HY000: The NDB cluster engine does not support changing the binlog format on the fly yet +set session binlog_format=statement; +ERROR HY000: The NDB cluster engine does not support changing the binlog format on the fly yet +set global binlog_format=row; +ERROR HY000: The NDB cluster engine does not support changing the binlog format on the fly yet +set global binlog_format=statement; +ERROR HY000: The NDB cluster engine does not support changing the binlog format on the fly yet +set session binlog_format=default; +ERROR HY000: The NDB cluster engine does not support changing the binlog format on the fly yet +set global binlog_format=default; +ERROR HY000: The NDB cluster engine does not support changing the binlog format on the fly yet diff --git a/mysql-test/r/ndb_binlog_ddl_multi.result b/mysql-test/r/ndb_binlog_ddl_multi.result index e9a3f80281d..1f44b7d5e3c 100644 --- a/mysql-test/r/ndb_binlog_ddl_multi.result +++ b/mysql-test/r/ndb_binlog_ddl_multi.result @@ -24,7 +24,7 @@ alter table t2 add column (b int); show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info master-bin1.000001 # Query # # BEGIN -master-bin1.000001 # Table_map # # cluster_replication.apply_status +master-bin1.000001 # Table_map # # cluster.apply_status master-bin1.000001 # Write_rows # # master-bin1.000001 # Query # # COMMIT master-bin1.000001 # Query # # use `test`; alter table t2 add column (b int) @@ -36,7 +36,7 @@ show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query # # ALTER DATABASE mysqltest CHARACTER SET latin1 master-bin.000001 # Query # # BEGIN -master-bin.000001 # Table_map # # cluster_replication.apply_status +master-bin.000001 # Table_map # # cluster.apply_status master-bin.000001 # Write_rows # # master-bin.000001 # Query # # COMMIT master-bin.000001 # Query # # use `mysqltest`; drop table `t1` @@ -49,7 +49,7 @@ create table t1 (a int primary key) engine=ndb; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info master-bin1.000001 # Query # # BEGIN -master-bin1.000001 # Table_map # # cluster_replication.apply_status +master-bin1.000001 # Table_map # # cluster.apply_status master-bin1.000001 # Write_rows # # master-bin1.000001 # Table_map # # test.t2 master-bin1.000001 # Write_rows # # @@ -119,7 +119,7 @@ ENGINE = NDB master-bin1.000001 # Query # # DROP LOGFILE GROUP lg1 ENGINE =NDB master-bin1.000001 # Query # # BEGIN -master-bin1.000001 # Table_map # # cluster_replication.apply_status +master-bin1.000001 # Table_map # # cluster.apply_status master-bin1.000001 # Write_rows # # master-bin1.000001 # Query # # COMMIT master-bin1.000001 # Query # # use `test`; drop table `t1` diff --git a/mysql-test/r/ndb_binlog_multi.result b/mysql-test/r/ndb_binlog_multi.result index 5f739327db2..808b96bcc3d 100644 --- a/mysql-test/r/ndb_binlog_multi.result +++ b/mysql-test/r/ndb_binlog_multi.result @@ -12,7 +12,7 @@ a b 1 1 2 2 SELECT @the_epoch:=epoch,inserts,updates,deletes,schemaops FROM -cluster_replication.binlog_index ORDER BY epoch DESC LIMIT 1; +cluster.binlog_index ORDER BY epoch DESC LIMIT 1; @the_epoch:=epoch inserts updates deletes schemaops <the_epoch> 2 0 0 0 SELECT * FROM t2 ORDER BY a; @@ -20,24 +20,24 @@ a b 1 1 2 2 SELECT inserts,updates,deletes,schemaops FROM -cluster_replication.binlog_index WHERE epoch=<the_epoch>; +cluster.binlog_index WHERE epoch=<the_epoch>; inserts updates deletes schemaops 2 0 0 0 DROP TABLE t2; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE = NDB; INSERT INTO t1 VALUES (1),(2); SELECT @the_epoch2:=epoch,inserts,updates,deletes,schemaops FROM -cluster_replication.binlog_index ORDER BY epoch DESC LIMIT 1; +cluster.binlog_index ORDER BY epoch DESC LIMIT 1; @the_epoch2:=epoch inserts updates deletes schemaops <the_epoch2> 2 0 0 0 SELECT inserts,updates,deletes,schemaops FROM -cluster_replication.binlog_index WHERE epoch > <the_epoch> AND epoch < <the_epoch2>; +cluster.binlog_index WHERE epoch > <the_epoch> AND epoch < <the_epoch2>; inserts updates deletes schemaops 0 0 0 1 drop table t1; SHOW TABLES; Tables_in_test SELECT inserts,updates,deletes,schemaops FROM -cluster_replication.binlog_index WHERE epoch > <the_epoch> AND epoch < <the_epoch2>; +cluster.binlog_index WHERE epoch > <the_epoch> AND epoch < <the_epoch2>; inserts updates deletes schemaops 0 0 0 1 diff --git a/mysql-test/r/ndb_cache_multi2.result b/mysql-test/r/ndb_cache_multi2.result index 63cc4d4ceed..53767bb6d3c 100644 --- a/mysql-test/r/ndb_cache_multi2.result +++ b/mysql-test/r/ndb_cache_multi2.result @@ -1,14 +1,17 @@ drop table if exists t1, t2; +== Connected to server1 == set GLOBAL query_cache_type=on; set GLOBAL query_cache_size=1355776; set GLOBAL ndb_cache_check_time=1; reset query cache; flush status; +== Connected to server2 == set GLOBAL query_cache_type=on; set GLOBAL query_cache_size=1355776; set GLOBAL ndb_cache_check_time=1; reset query cache; flush status; +== Connected to server1 == create table t1 (a int) engine=ndbcluster; create table t2 (a int) engine=ndbcluster; insert into t1 value (2); @@ -16,18 +19,22 @@ insert into t2 value (3); select * from t1; a 2 +select a != 3 from t1; +a != 3 +1 select * from t2; a 3 show status like "Qcache_queries_in_cache"; Variable_name Value -Qcache_queries_in_cache 2 +Qcache_queries_in_cache 3 show status like "Qcache_inserts"; Variable_name Value -Qcache_inserts 2 +Qcache_inserts 3 show status like "Qcache_hits"; Variable_name Value Qcache_hits 0 +== Connected to server2 == show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 0 @@ -50,24 +57,13 @@ show status like "Qcache_hits"; Variable_name Value Qcache_hits 0 update t1 set a=3 where a=2; -show status like "Qcache_queries_in_cache"; -Variable_name Value -Qcache_queries_in_cache 2 -show status like "Qcache_inserts"; -Variable_name Value -Qcache_inserts 2 -show status like "Qcache_hits"; -Variable_name Value -Qcache_hits 0 +== Connected to server1 == select * from t1; a 3 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 3 -show status like "Qcache_inserts"; -Variable_name Value -Qcache_inserts 4 drop table t1, t2; set GLOBAL query_cache_size=0; set GLOBAL ndb_cache_check_time=0; diff --git a/mysql-test/r/ndb_dd_backuprestore.result b/mysql-test/r/ndb_dd_backuprestore.result index b5727418d17..0410589e93a 100644 --- a/mysql-test/r/ndb_dd_backuprestore.result +++ b/mysql-test/r/ndb_dd_backuprestore.result @@ -4,7 +4,9 @@ DROP TABLE IF EXISTS test.t3; DROP TABLE IF EXISTS test.t4; DROP TABLE IF EXISTS test.t5; DROP TABLE IF EXISTS test.t6; -**** Test 1 Simple DD backup and restore **** CREATE LOGFILE GROUP log_group1 ADD UNDOFILE './log_group1/undofile.dat' +**** Test 1 Simple DD backup and restore **** +CREATE LOGFILE GROUP log_group1 +ADD UNDOFILE './log_group1/undofile.dat' INITIAL_SIZE 16M UNDO_BUFFER_SIZE = 1M ENGINE=NDB; @@ -14,7 +16,8 @@ USE LOGFILE GROUP log_group1 INITIAL_SIZE 12M ENGINE NDB; CREATE TABLE test.t1 -(pk1 MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL) TABLESPACE table_space1 STORAGE DISK ENGINE=NDB; SELECT COUNT(*) FROM test.t1; +(pk1 MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 CHAR(50) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL) TABLESPACE table_space1 STORAGE DISK ENGINE=NDB; +SELECT COUNT(*) FROM test.t1; COUNT(*) 500 SELECT pk1, c2, c3, hex(c4) FROM test.t1 ORDER BY pk1 LIMIT 5; @@ -24,8 +27,16 @@ pk1 c2 c3 hex(c4) 3 Sweden 498 1 4 Sweden 497 1 5 Sweden 496 1 +CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM test.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM test.backup_info; +@the_backup_id:=backup_id +<the_backup_id> +DROP TABLE test.backup_info; DROP TABLE test.t1; -CREATE TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; DELETE FROM test.backup_info; LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; SELECT @the_backup_id:=backup_id FROM test.backup_info; @the_backup_id:=backup_id <the_backup_id> DROP TABLE test.backup_info; ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' +ALTER TABLESPACE table_space1 +DROP DATAFILE './table_space1/datafile.dat' ENGINE = NDB; DROP TABLESPACE table_space1 ENGINE = NDB; @@ -41,8 +52,12 @@ pk1 c2 c3 hex(c4) 3 Sweden 498 1 4 Sweden 497 1 5 Sweden 496 1 -**** Test 2 Mixed Cluster Test backup and restore **** CREATE TABLE test.t2 -(pk1 MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL)ENGINE=NDB; CREATE TABLE test.t3 (c1 int not null auto_increment, data LONGBLOB, PRIMARY KEY(c1))TABLESPACE table_space1 STORAGE DISK ENGINE=NDB; CREATE TABLE test.t4 (c1 int not null auto_increment, data LONGBLOB, PRIMARY KEY(c1))ENGINE=NDB; SELECT COUNT(*) FROM test.t1; +**** Test 2 Mixed Cluster Test backup and restore **** +CREATE TABLE test.t2 +(pk1 MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 VARCHAR(200) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL)ENGINE=NDB; +CREATE TABLE test.t3 (c1 int not null auto_increment, data LONGBLOB, PRIMARY KEY(c1))TABLESPACE table_space1 STORAGE DISK ENGINE=NDB; +CREATE TABLE test.t4 (c1 int not null auto_increment, data LONGBLOB, PRIMARY KEY(c1))ENGINE=NDB; +SELECT COUNT(*) FROM test.t1; COUNT(*) 500 SELECT pk1, c2, c3, hex(c4) FROM test.t1 ORDER BY pk1 LIMIT 5; @@ -80,7 +95,19 @@ LENGTH(data) SELECT LENGTH(data) FROM test.t4 WHERE c1 = 2; LENGTH(data) 16384 -CREATE TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; DELETE FROM test.backup_info; LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; SELECT @the_backup_id:=backup_id FROM test.backup_info; @the_backup_id:=backup_id <the_backup_id> DROP TABLE test.backup_info; DROP TABLE test.t1; DROP TABLE test.t2; DROP TABLE test.t3; DROP TABLE test.t4; ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' +CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM test.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM test.backup_info; +@the_backup_id:=backup_id +<the_backup_id> +DROP TABLE test.backup_info; +DROP TABLE test.t1; +DROP TABLE test.t2; +DROP TABLE test.t3; +DROP TABLE test.t4; +ALTER TABLESPACE table_space1 +DROP DATAFILE './table_space1/datafile.dat' ENGINE = NDB; DROP TABLESPACE table_space1 ENGINE = NDB; @@ -128,59 +155,73 @@ DROP TABLE test.t1; DROP TABLE test.t2; DROP TABLE test.t3; DROP TABLE test.t4; -**** Test 3 Adding partition Test backup and restore **** CREATE TABLESPACE table_space2 ADD DATAFILE './table_space2/datafile.dat' +**** Test 3 Adding partition Test backup and restore **** +CREATE TABLESPACE table_space2 +ADD DATAFILE './table_space2/datafile.dat' USE LOGFILE GROUP log_group1 INITIAL_SIZE 12M ENGINE NDB; -CREATE TABLE test.t1 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space1 STORAGE DISK ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 4; CREATE TABLE test.t4 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 2; CREATE TABLE test.t2 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY KEY(c3) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); CREATE TABLE test.t5 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY KEY(pk1) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); CREATE TABLE test.t3 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY RANGE (c3) PARTITIONS 3 (PARTITION x1 VALUES LESS THAN (105), PARTITION x2 VALUES LESS THAN (333), PARTITION x3 VALUES LESS THAN (720)); CREATE TABLE test.t6 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY RANGE (pk1) PARTITIONS 2 (PARTITION x1 VALUES LESS THAN (333), PARTITION x2 VALUES LESS THAN (720)); SHOW CREATE TABLE test.t1; +CREATE TABLE test.t1 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(150) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space1 STORAGE DISK ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 4; +CREATE TABLE test.t4 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(180) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY HASH(c3) PARTITIONS 2; +CREATE TABLE test.t2 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY KEY(c3) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); +CREATE TABLE test.t5 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 TEXT NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY KEY(pk1) (PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB); +CREATE TABLE test.t3 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(202) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))TABLESPACE table_space2 STORAGE DISK ENGINE=NDB PARTITION BY RANGE (c3) PARTITIONS 3 (PARTITION x1 VALUES LESS THAN (105), PARTITION x2 VALUES LESS THAN (333), PARTITION x3 VALUES LESS THAN (720)); +CREATE TABLE test.t6 (pk1 MEDIUMINT NOT NULL AUTO_INCREMENT, c2 VARCHAR(220) NOT NULL, c3 INT NOT NULL, c4 BIT NOT NULL, PRIMARY KEY(pk1,c3))ENGINE=NDB PARTITION BY RANGE (pk1) PARTITIONS 2 (PARTITION x1 VALUES LESS THAN (333), PARTITION x2 VALUES LESS THAN (720)); +SHOW CREATE TABLE test.t1; Table Create Table t1 CREATE TABLE `t1` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(150) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 4 SHOW CREATE TABLE test.t2; + PRIMARY KEY (`pk1`,`c3`) +) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 4 +SHOW CREATE TABLE test.t2; Table Create Table t2 CREATE TABLE `t2` ( `pk1` mediumint(9) NOT NULL auto_increment, `c2` text NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (c3) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) SHOW CREATE TABLE test.t3; + PRIMARY KEY (`pk1`,`c3`) +) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (c3) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) +SHOW CREATE TABLE test.t3; Table Create Table t3 CREATE TABLE `t3` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(202) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (c3) (PARTITION x1 VALUES LESS THAN (105) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (720) ENGINE = ndbcluster) SHOW CREATE TABLE test.t4; + PRIMARY KEY (`pk1`,`c3`) +) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (c3) (PARTITION x1 VALUES LESS THAN (105) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (720) ENGINE = ndbcluster) +SHOW CREATE TABLE test.t4; Table Create Table t4 CREATE TABLE `t4` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(180) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 2 SHOW CREATE TABLE test.t5; + PRIMARY KEY (`pk1`,`c3`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 2 +SHOW CREATE TABLE test.t5; Table Create Table t5 CREATE TABLE `t5` ( `pk1` mediumint(9) NOT NULL auto_increment, `c2` text NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (pk1) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) SHOW CREATE TABLE test.t6; + PRIMARY KEY (`pk1`,`c3`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (pk1) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) +SHOW CREATE TABLE test.t6; Table Create Table t6 CREATE TABLE `t6` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(220) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (pk1) (PARTITION x1 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (720) ENGINE = ndbcluster) SELECT * FROM information_schema.partitions WHERE table_name= 't1'; + PRIMARY KEY (`pk1`,`c3`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (pk1) (PARTITION x1 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (720) ENGINE = ndbcluster) +SELECT * FROM information_schema.partitions WHERE table_name= 't1'; TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME NULL test t1 p0 NULL 1 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default NULL test t1 p1 NULL 2 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default @@ -267,7 +308,21 @@ pk1 c2 c3 hex(c4) 248 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 4 1 247 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 6 1 246 TEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXASTEXAS, ITALY, Kyle, JO, JBM,TU 8 1 -CREATE TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; DELETE FROM test.backup_info; LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; SELECT @the_backup_id:=backup_id FROM test.backup_info; @the_backup_id:=backup_id <the_backup_id> DROP TABLE test.backup_info; DROP TABLE test.t1; DROP TABLE test.t2; DROP TABLE test.t3; DROP TABLE test.t4; DROP TABLE test.t5; DROP TABLE test.t6; ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' +CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM test.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM test.backup_info; +@the_backup_id:=backup_id +<the_backup_id> +DROP TABLE test.backup_info; +DROP TABLE test.t1; +DROP TABLE test.t2; +DROP TABLE test.t3; +DROP TABLE test.t4; +DROP TABLE test.t5; +DROP TABLE test.t6; +ALTER TABLESPACE table_space1 +DROP DATAFILE './table_space1/datafile.dat' ENGINE = NDB; ALTER TABLESPACE table_space2 DROP DATAFILE './table_space2/datafile.dat' @@ -282,51 +337,57 @@ SHOW CREATE TABLE test.t1; Table Create Table t1 CREATE TABLE `t1` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(150) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 4 SHOW CREATE TABLE test.t2; + PRIMARY KEY (`pk1`,`c3`) +) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 4 +SHOW CREATE TABLE test.t2; Table Create Table t2 CREATE TABLE `t2` ( `pk1` mediumint(9) NOT NULL auto_increment, `c2` text NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (c3) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) SHOW CREATE TABLE test.t3; + PRIMARY KEY (`pk1`,`c3`) +) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (c3) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) +SHOW CREATE TABLE test.t3; Table Create Table t3 CREATE TABLE `t3` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(202) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (c3) (PARTITION x1 VALUES LESS THAN (105) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (720) ENGINE = ndbcluster) SHOW CREATE TABLE test.t4; + PRIMARY KEY (`pk1`,`c3`) +) TABLESPACE table_space2 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (c3) (PARTITION x1 VALUES LESS THAN (105) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (720) ENGINE = ndbcluster) +SHOW CREATE TABLE test.t4; Table Create Table t4 CREATE TABLE `t4` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(180) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 2 SHOW CREATE TABLE test.t5; + PRIMARY KEY (`pk1`,`c3`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY HASH (c3) PARTITIONS 2 +SHOW CREATE TABLE test.t5; Table Create Table t5 CREATE TABLE `t5` ( `pk1` mediumint(9) NOT NULL auto_increment, `c2` text NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (pk1) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) SHOW CREATE TABLE test.t6; + PRIMARY KEY (`pk1`,`c3`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (pk1) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster) +SHOW CREATE TABLE test.t6; Table Create Table t6 CREATE TABLE `t6` ( `pk1` mediumint(9) NOT NULL auto_increment, - `c2` text NOT NULL, + `c2` varchar(220) NOT NULL, `c3` int(11) NOT NULL, `c4` bit(1) NOT NULL, - PRIMARY KEY (`pk1`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (pk1) (PARTITION x1 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (720) ENGINE = ndbcluster) SELECT * FROM information_schema.partitions WHERE table_name= 't1'; + PRIMARY KEY (`pk1`,`c3`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (pk1) (PARTITION x1 VALUES LESS THAN (333) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (720) ENGINE = ndbcluster) +SELECT * FROM information_schema.partitions WHERE table_name= 't1'; TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME NULL test t1 p0 NULL 1 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default NULL test t1 p1 NULL 2 NULL HASH NULL c3 NULL NULL 0 0 0 NULL 0 0 NULL NULL NULL NULL default 0 default @@ -419,5 +480,8 @@ DROP TABLE test.t3; DROP TABLE test.t4; DROP TABLE test.t5; DROP TABLE test.t6; -ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' ENGINE=NDB; ALTER TABLESPACE table_space2 DROP DATAFILE './table_space2/datafile.dat' ENGINE=NDB; DROP TABLESPACE table_space1 ENGINE = NDB; DROP TABLESPACE table_space2 ENGINE = NDB; DROP LOGFILE GROUP log_group1 ENGINE = NDB; - +ALTER TABLESPACE table_space1 DROP DATAFILE './table_space1/datafile.dat' ENGINE=NDB; +ALTER TABLESPACE table_space2 DROP DATAFILE './table_space2/datafile.dat' ENGINE=NDB; +DROP TABLESPACE table_space1 ENGINE = NDB; +DROP TABLESPACE table_space2 ENGINE = NDB; +DROP LOGFILE GROUP log_group1 ENGINE = NDB; diff --git a/mysql-test/r/ndb_gis.result b/mysql-test/r/ndb_gis.result index 6c95b3d4e4e..f9b9ceb76a5 100644 --- a/mysql-test/r/ndb_gis.result +++ b/mysql-test/r/ndb_gis.result @@ -1,66 +1,51 @@ SET storage_engine=ndbcluster; DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; -CREATE TABLE gis_point (fid INTEGER, g POINT); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_line (fid INTEGER, g LINESTRING); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_polygon (fid INTEGER, g POLYGON); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' +CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT); +CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY); SHOW CREATE TABLE gis_point; Table Create Table gis_point CREATE TABLE `gis_point` ( - `fid` int(11) DEFAULT NULL, - `g` point DEFAULT NULL + `fid` int(11) NOT NULL AUTO_INCREMENT, + `g` point DEFAULT NULL, + PRIMARY KEY (`fid`) ) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g point YES NULL SHOW FIELDS FROM gis_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g linestring YES NULL SHOW FIELDS FROM gis_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g polygon YES NULL SHOW FIELDS FROM gis_multi_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipoint YES NULL SHOW FIELDS FROM gis_multi_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multilinestring YES NULL SHOW FIELDS FROM gis_multi_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipolygon YES NULL SHOW FIELDS FROM gis_geometrycollection; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometrycollection YES NULL SHOW FIELDS FROM gis_geometry; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometry YES NULL INSERT INTO gis_point VALUES (101, PointFromText('POINT(10 10)')), @@ -423,6 +408,7 @@ Warnings: Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,overlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,equals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,disjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,intersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid` DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; CREATE TABLE t1 ( +a INTEGER PRIMARY KEY AUTO_INCREMENT, gp point, ln linestring, pg polygon, @@ -432,10 +418,9 @@ mpg multipolygon, gc geometrycollection, gm geometry ); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -445,10 +430,9 @@ mpg multipolygon YES NULL gc geometrycollection YES NULL gm geometry YES NULL ALTER TABLE t1 ADD fid INT; -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -459,90 +443,71 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) YES NULL DROP TABLE t1; -create table t1 (a geometry not null); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -insert into t1 values (GeomFromText('Point(1 2)')); -insert into t1 values ('Garbage'); +create table t1 (pk integer primary key auto_increment, a geometry not null); +insert into t1 (a) values (GeomFromText('Point(1 2)')); +insert into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert IGNORE into t1 values ('Garbage'); +insert IGNORE into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; -create table t1 (fl geometry); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -insert into t1 values (1); +create table t1 (pk integer primary key auto_increment, fl geometry); +insert into t1 (fl) values (1); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (1.11); +insert into t1 (fl) values (1.11); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values ("qwerty"); +insert into t1 (fl) values ("qwerty"); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (pointfromtext('point(1,1)')); +insert into t1 (fl) values (pointfromtext('point(1,1)')); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; set engine_condition_pushdown = on; DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; -CREATE TABLE gis_point (fid INTEGER, g POINT); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_line (fid INTEGER, g LINESTRING); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_polygon (fid INTEGER, g POLYGON); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' +CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT); +CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY); SHOW CREATE TABLE gis_point; Table Create Table gis_point CREATE TABLE `gis_point` ( - `fid` int(11) DEFAULT NULL, - `g` point DEFAULT NULL + `fid` int(11) NOT NULL AUTO_INCREMENT, + `g` point DEFAULT NULL, + PRIMARY KEY (`fid`) ) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g point YES NULL SHOW FIELDS FROM gis_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g linestring YES NULL SHOW FIELDS FROM gis_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g polygon YES NULL SHOW FIELDS FROM gis_multi_point; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipoint YES NULL SHOW FIELDS FROM gis_multi_line; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multilinestring YES NULL SHOW FIELDS FROM gis_multi_polygon; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g multipolygon YES NULL SHOW FIELDS FROM gis_geometrycollection; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometrycollection YES NULL SHOW FIELDS FROM gis_geometry; Field Type Null Key Default Extra -fid int(11) YES NULL +fid int(11) NO PRI NULL auto_increment g geometry YES NULL INSERT INTO gis_point VALUES (101, PointFromText('POINT(10 10)')), @@ -905,6 +870,7 @@ Warnings: Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,overlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,equals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,disjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,intersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid` DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; CREATE TABLE t1 ( +a INTEGER PRIMARY KEY AUTO_INCREMENT, gp point, ln linestring, pg polygon, @@ -914,10 +880,9 @@ mpg multipolygon, gc geometrycollection, gm geometry ); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -927,10 +892,9 @@ mpg multipolygon YES NULL gc geometrycollection YES NULL gm geometry YES NULL ALTER TABLE t1 ADD fid INT; -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' SHOW FIELDS FROM t1; Field Type Null Key Default Extra +a int(11) NO PRI NULL auto_increment gp point YES NULL ln linestring YES NULL pg polygon YES NULL @@ -941,24 +905,20 @@ gc geometrycollection YES NULL gm geometry YES NULL fid int(11) YES NULL DROP TABLE t1; -create table t1 (a geometry not null); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -insert into t1 values (GeomFromText('Point(1 2)')); -insert into t1 values ('Garbage'); +create table t1 (pk integer primary key auto_increment, a geometry not null); +insert into t1 (a) values (GeomFromText('Point(1 2)')); +insert into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert IGNORE into t1 values ('Garbage'); +insert IGNORE into t1 (a) values ('Garbage'); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; -create table t1 (fl geometry); -Warnings: -Error 1538 Table storage engine 'ndbcluster' does not support the create option 'Binlog of table with BLOB attribute and no PK' -insert into t1 values (1); +create table t1 (pk integer primary key auto_increment, fl geometry); +insert into t1 (fl) values (1); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (1.11); +insert into t1 (fl) values (1.11); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values ("qwerty"); +insert into t1 (fl) values ("qwerty"); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field -insert into t1 values (pointfromtext('point(1,1)')); +insert into t1 (fl) values (pointfromtext('point(1,1)')); ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field drop table t1; diff --git a/mysql-test/r/ndb_load.result b/mysql-test/r/ndb_load.result index 76da5b2a215..416a350066b 100644 --- a/mysql-test/r/ndb_load.result +++ b/mysql-test/r/ndb_load.result @@ -1,10 +1,10 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB; -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1 ; ERROR 23000: Can't write; duplicate key in table 't1' DROP TABLE t1; CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=NDB; -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1 ; SELECT * FROM t1 ORDER BY word; word Aarhus diff --git a/mysql-test/r/ndb_partition_error.result b/mysql-test/r/ndb_partition_error.result index 3fd111a7c0f..66f623dee13 100644 --- a/mysql-test/r/ndb_partition_error.result +++ b/mysql-test/r/ndb_partition_error.result @@ -28,3 +28,11 @@ partitions 3 partition x2 values less than (10), partition x3 values less than (20)); drop table t1; +CREATE TABLE t1 (id INT) ENGINE=NDB +PARTITION BY LIST(id) +(PARTITION p0 VALUES IN (2, 4), +PARTITION p1 VALUES IN (42, 142)); +INSERT INTO t1 VALUES (2); +UPDATE t1 SET id=5 WHERE id=2; +ERROR HY000: Table has no partition for value 5 +DROP TABLE t1; diff --git a/mysql-test/r/ndb_partition_range.result b/mysql-test/r/ndb_partition_range.result index 2b9c55c3929..cb79f04873e 100644 --- a/mysql-test/r/ndb_partition_range.result +++ b/mysql-test/r/ndb_partition_range.result @@ -117,3 +117,147 @@ t1 CREATE TABLE `t1` ( UNIQUE KEY `a` (`a`) ) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY RANGE (b) (PARTITION x1 VALUES LESS THAN (5) ENGINE = ndbcluster, PARTITION x2 VALUES LESS THAN (10) ENGINE = ndbcluster, PARTITION x3 VALUES LESS THAN (20) ENGINE = ndbcluster) drop table t1; +CREATE TABLE t1 +(id MEDIUMINT NOT NULL, +b1 BIT(8), +vc VARCHAR(255), +bc CHAR(255), +d DECIMAL(10,4) DEFAULT 0, +f FLOAT DEFAULT 0, +total BIGINT UNSIGNED, +y YEAR, +t DATE) ENGINE=NDB +PARTITION BY RANGE (YEAR(t)) +(PARTITION p0 VALUES LESS THAN (1901), +PARTITION p1 VALUES LESS THAN (1946), +PARTITION p2 VALUES LESS THAN (1966), +PARTITION p3 VALUES LESS THAN (1986), +PARTITION p4 VALUES LESS THAN (2005), +PARTITION p5 VALUES LESS THAN MAXVALUE); +INSERT INTO t1 VALUES (0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); +SELECT * FROM t1; +id b1 vc bc d f total y t +0 NULL NULL NULL NULL NULL NULL NULL NULL +ALTER TABLE t1 ENGINE=MYISAM; +SELECT * FROM t1; +id b1 vc bc d f total y t +0 NULL NULL NULL NULL NULL NULL NULL NULL +DROP TABLE t1; +CREATE LOGFILE GROUP lg1 +ADD UNDOFILE 'undofile.dat' + INITIAL_SIZE 16M +UNDO_BUFFER_SIZE=1M +ENGINE=NDB; +CREATE TABLESPACE ts1 +ADD DATAFILE 'datafile.dat' + USE LOGFILE GROUP lg1 +INITIAL_SIZE 12M +ENGINE NDB; +CREATE TABLE test.t1 ( +a1 INT, +a2 TEXT NOT NULL, +a3 BIT NOT NULL, +a4 DECIMAL(8,3), +a5 INT NOT NULL, +a6 INT, +PRIMARY KEY(a1)) +TABLESPACE ts1 STORAGE DISK ENGINE=NDB +PARTITION BY LIST (a1) +(PARTITION p0 VALUES IN (1,2,3,4,5), +PARTITION p1 VALUES IN (6,7,8,9, 10), +PARTITION p2 VALUES IN (11, 12, 13, 14, 15)); +ALTER TABLE test.t1 DROP COLUMN a6; +ALTER TABLE test.t1 ADD COLUMN a6 VARCHAR(255); +SELECT COUNT(*) FROM test.t1; +COUNT(*) +15 +ALTER TABLE test.t1 DROP COLUMN a4; +SELECT COUNT(*) FROM test.t1; +COUNT(*) +15 +DROP TABLE t1; +CREATE TABLE test.t1 ( +a1 INT, +a2 TEXT NOT NULL, +a3 BIT NOT NULL, +a4 DECIMAL(8,3), +a5 INT NOT NULL, +a6 VARCHAR(255), +PRIMARY KEY(a1)) +TABLESPACE ts1 STORAGE DISK ENGINE=NDB +PARTITION BY HASH(a1) +PARTITIONS 4; +SELECT COUNT(*) FROM test.t1; +COUNT(*) +15 +ALTER TABLE test.t1 DROP COLUMN a4; +SELECT COUNT(*) FROM test.t1; +COUNT(*) +15 +DROP TABLE t1; +ALTER TABLESPACE ts1 +DROP DATAFILE 'datafile.dat' +ENGINE=NDB; +DROP TABLESPACE ts1 ENGINE=NDB; +DROP LOGFILE GROUP lg1 ENGINE=NDB; +CREATE TABLE t1 +(id MEDIUMINT NOT NULL, +b1 BIT(8), +vc VARCHAR(255), +bc CHAR(255), +d DECIMAL(10,4) DEFAULT 0, +f FLOAT DEFAULT 0, +total BIGINT UNSIGNED, +y YEAR, +t DATE) ENGINE=NDB +PARTITION BY LIST(id) +(PARTITION p0 VALUES IN (2, 4), +PARTITION p1 VALUES IN (42, 142)); +INSERT INTO t1 VALUES (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); +SELECT * FROM t1; +id b1 vc bc d f total y t +2 NULL NULL NULL NULL NULL NULL NULL NULL +ALTER TABLE t1 ADD PARTITION +(PARTITION p2 VALUES IN (412)); +SELECT * FROM t1; +id b1 vc bc d f total y t +2 NULL NULL NULL NULL NULL NULL NULL NULL +DROP TABLE t1; +CREATE TABLE t1 ( +a int not null, +b int not null, +c int not null) +partition by list(a) +partitions 2 +(partition x123 values in (1,5,6), +partition x234 values in (4,7,8)); +INSERT into t1 VALUES (5,1,1); +select * from t1; +a b c +5 1 1 +UPDATE t1 SET a=8 WHERE a=5 AND b=1; +select * from t1; +a b c +8 1 1 +drop table t1; +CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) engine=ndb +PARTITION BY RANGE(f1) +( PARTITION part1 VALUES LESS THAN (2), +PARTITION part2 VALUES LESS THAN (1000)); +INSERT INTO t1 VALUES(1, '---1---'); +INSERT INTO t1 VALUES(2, '---2---'); +select * from t1 order by f1; +f1 f2 +1 ---1--- +2 ---2--- +UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2; +select * from t1 order by f1; +f1 f2 +1 ---1--- +6 ---2--- +UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1; +select * from t1 order by f1; +f1 f2 +5 ---1--- +6 ---2--- +drop table t1; diff --git a/mysql-test/r/ndb_restore.result b/mysql-test/r/ndb_restore.result index 85c4e34cc5a..01ab286aad8 100644 --- a/mysql-test/r/ndb_restore.result +++ b/mysql-test/r/ndb_restore.result @@ -125,6 +125,13 @@ create table t6 engine=myisam as select * from t6_c; create table t7 engine=myisam as select * from t7_c; create table t8 engine=myisam as select * from t8_c; create table t9 engine=myisam as select * from t9_c; +CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM test.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM test.backup_info; +@the_backup_id:=backup_id +<the_backup_id> +DROP TABLE test.backup_info; drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; select count(*) from t1; count(*) @@ -241,6 +248,13 @@ PARTITION BY LINEAR HASH (`relatta`) PARTITIONS 4; ALTER TABLE t7_c PARTITION BY LINEAR KEY (`dardtestard`); +CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM test.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM test.backup_info; +@the_backup_id:=backup_id +<the_backup_id> +DROP TABLE test.backup_info; drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; select count(*) from t1; count(*) @@ -445,4 +459,4 @@ drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; Create table test/def/t2_c failed: Translate frm error drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; -520093696,2 +520093696,<the_backup_id> diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 70ff49be905..cd333cc5fb4 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -315,4 +315,62 @@ drop table t1; create table t1 (s1 int, unique (s1)) partition by list (s1) (partition x1 VALUES in (10), partition x2 values in (20)); alter table t1 add partition (partition x3 values in (30)); drop table t1; +CREATE TABLE t1 ( +f_int1 INTEGER, f_int2 INTEGER, +f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000) +) +PARTITION BY RANGE(f_int1 DIV 2) +SUBPARTITION BY HASH(f_int1) +SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN (5), +PARTITION parte VALUES LESS THAN (10), +PARTITION partf VALUES LESS THAN (2147483647)); +INSERT INTO t1 SET f_int1 = NULL , f_int2 = -20, f_char1 = CAST(-20 AS CHAR), +f_char2 = CAST(-20 AS CHAR), f_charbig = '#NULL#'; +SELECT * FROM t1 WHERE f_int1 IS NULL; +f_int1 f_int2 f_char1 f_char2 f_charbig +NULL -20 -20 -20 #NULL# +SELECT * FROM t1; +f_int1 f_int2 f_char1 f_char2 f_charbig +NULL -20 -20 -20 #NULL# +drop table t1; +CREATE TABLE t1 ( +f_int1 INTEGER, f_int2 INTEGER, +f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000) ) +PARTITION BY LIST(MOD(f_int1,2)) +SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES IN (-1) (SUBPARTITION sp1, SUBPARTITION sp2), +PARTITION part2 VALUES IN (0) (SUBPARTITION sp3, SUBPARTITION sp5), +PARTITION part3 VALUES IN (1) (SUBPARTITION sp4, SUBPARTITION sp6)); +INSERT INTO t1 SET f_int1 = 2, f_int2 = 2, f_char1 = '2', f_char2 = '2', f_charbig = '===2==='; +INSERT INTO t1 SET f_int1 = 2, f_int2 = 2, f_char1 = '2', f_char2 = '2', f_charbig = '===2==='; +SELECT * FROM t1 WHERE f_int1 IS NULL; +f_int1 f_int2 f_char1 f_char2 f_charbig +drop table t1; +create procedure p () +begin +create table t1 (s1 mediumint,s2 mediumint) +partition by list (s2) +(partition p1 values in (0), +partition p2 values in (1)); +end// +call p()// +drop procedure p// +drop table t1; +create procedure p () +begin +create table t1 (a int not null,b int not null,c int not null,primary key (a,b)) +partition by range (a) +subpartition by hash (a+b) +(partition x1 values less than (1) +(subpartition x11, +subpartition x12), +partition x2 values less than (5) +(subpartition x21, +subpartition x22)); +end// +call p()// +drop procedure p// +drop table t1// End of 5.1 tests diff --git a/mysql-test/r/partition_02myisam.result b/mysql-test/r/partition_02myisam.result index 29d54c8a8b8..a7786bfcfbd 100644 --- a/mysql-test/r/partition_02myisam.result +++ b/mysql-test/r/partition_02myisam.result @@ -1160,12 +1160,12 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp (PARTITION part1 VALUES LESS THAN (100), PARTITION part2 VALUES LESS THAN (21' at line 3 CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) PARTITION BY HASH(f1) PARTITIONS 1000000; -ERROR HY000: Too many partitions were defined +ERROR HY000: Too many partitions (including subpartitions) were defined CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) PARTITION BY RANGE(f1) SUBPARTITION BY HASH(f1) SUBPARTITIONS 1000000 (PARTITION part1 VALUES LESS THAN (100), PARTITION part2 VALUES LESS THAN (2147483647)); -ERROR HY000: Too many partitions were defined +ERROR HY000: Too many partitions (including subpartitions) were defined # 3.2.4 partition/subpartition numbers STRING notation CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) PARTITION BY HASH(f1) PARTITIONS '2'; diff --git a/mysql-test/r/partition_charset.result b/mysql-test/r/partition_charset.result new file mode 100644 index 00000000000..665e5d55f8f --- /dev/null +++ b/mysql-test/r/partition_charset.result @@ -0,0 +1,18 @@ +drop table if exists t1; +set names utf8; +create table t1 (s1 int) +partition by list (s1) +(partition c values in (1), +partition Ç values in (3)); +insert into t1 values (1),(3); +select * from t1; +s1 +1 +3 +flush tables; +set names latin1; +select * from t1; +s1 +1 +3 +drop table t1; diff --git a/mysql-test/r/partition_mgm_err.result b/mysql-test/r/partition_mgm_err.result index a419d5b361b..c7003c6e14c 100644 --- a/mysql-test/r/partition_mgm_err.result +++ b/mysql-test/r/partition_mgm_err.result @@ -91,7 +91,7 @@ PARTITION BY KEY (a) ALTER TABLE t1 ADD PARTITION PARTITIONS 0; ERROR HY000: At least one partition must be added ALTER TABLE t1 ADD PARTITION PARTITIONS 1024; -ERROR HY000: Too many partitions were defined +ERROR HY000: Too many partitions (including subpartitions) were defined ALTER TABLE t1 DROP PARTITION x0; ERROR HY000: DROP PARTITION can only be used on RANGE/LIST partitions ALTER TABLE t1 COALESCE PARTITION 1; @@ -112,8 +112,6 @@ ALTER TABLE t1 DROP PARTITION x1; ALTER TABLE t1 DROP PARTITION x0; ERROR HY000: Cannot remove all partitions, use DROP TABLE instead DROP TABLE t1; -INSERT INTO t1 VALUES (15); -DROP TABLE t1; CREATE TABLE t1 ( id INT NOT NULL, fname VARCHAR(50) NOT NULL, lname VARCHAR(50) NOT NULL, @@ -142,3 +140,9 @@ t1 CREATE TABLE `t1` ( DROP TABLE t1; CREATE TABLE t1 (a INT) PARTITION BY HASH(a); ALTER TABLE t1 ADD PARTITION PARTITIONS 4; +DROP TABLE t1; +CREATE TABLE t1 (s1 int, s2 int) PARTITION BY LIST (s1) ( +PARTITION p1 VALUES IN (0) (SUBPARTITION p1b), +PARTITION p2 VALUES IN (2) (SUBPARTITION p1b) +); +ERROR HY000: Duplicate partition name p1b diff --git a/mysql-test/r/partition_mgm_err2.result b/mysql-test/r/partition_mgm_err2.result new file mode 100644 index 00000000000..7e5763b8f1b --- /dev/null +++ b/mysql-test/r/partition_mgm_err2.result @@ -0,0 +1,2 @@ +INSERT INTO t1 VALUES (15); +DROP TABLE t1; diff --git a/mysql-test/r/partition_pruning.result b/mysql-test/r/partition_pruning.result index 776a98c7d4d..cbad5d067b0 100644 --- a/mysql-test/r/partition_pruning.result +++ b/mysql-test/r/partition_pruning.result @@ -85,29 +85,29 @@ partition p1 values in (14) insert into t5 values (10,2,0,0), (10,4,0,0), (10,2,0,1), (10,4,0,1); explain partitions select * from t5; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp0,p0_sp1,p1_sp0,p1_sp1 ALL NULL NULL NULL NULL 4 +1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 4 explain partitions select * from t5 where (a=10 and b=1) or (a=10 and b=2) or (a=10 and b = 3); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp0,p0_sp1 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t5 where (a=10 and b=2) or (a=10 and b=3) or (a=10 and b = 4); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp0,p0_sp1,p1_sp0,p1_sp1 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where explain partitions select * from t5 where (c=1 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp0,p1_sp0 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t5 p0_p0sp0,p1_p1sp0 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t5 where (c=2 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp1,p1_sp1 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t5 p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or (c=2 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp0,p0_sp1,p1_sp1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 3 Using where explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or (b=2 and c=2 and d=1); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t5 p0_sp0,p0_sp1,p1_sp1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t5 p0_p0sp0,p0_p0sp1,p1_p1sp1 ALL NULL NULL NULL NULL 3 Using where create table t6 (a int not null) partition by LIST(a) ( partition p1 values in (1), partition p3 values in (3), @@ -242,13 +242,13 @@ partition p3 values in (4) insert into t3 values (1,1),(2,2),(3,3); explain partitions select * from t3 where a=2 or b=1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t3 p0_sp1,p1_sp0,p1_sp1,p1_sp2,p1_sp3,p2_sp1,p3_sp1 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t3 p0_p0sp1,p1_p1sp0,p1_p1sp1,p1_p1sp2,p1_p1sp3,p2_p2sp1,p3_p3sp1 ALL NULL NULL NULL NULL 2 Using where explain partitions select * from t3 where a=4 or b=2; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t3 p0_sp2,p1_sp2,p2_sp2,p3_sp0,p3_sp1,p3_sp2,p3_sp3 system NULL NULL NULL NULL 1 +1 SIMPLE t3 p0_p0sp2,p1_p1sp2,p2_p2sp2,p3_p3sp0,p3_p3sp1,p3_p3sp2,p3_p3sp3 system NULL NULL NULL NULL 1 explain partitions select * from t3 where (a=2 or b=1) and (a=4 or b=2) ; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t3 p1_sp2,p3_sp1 system NULL NULL NULL NULL 1 +1 SIMPLE t3 p1_p1sp2,p3_p3sp1 system NULL NULL NULL NULL 1 drop table t3; create table t1 (a int) partition by hash(a) partitions 2; insert into t1 values (1),(2); @@ -300,10 +300,10 @@ partition p3 values in (3) insert into t1 values (1,1),(2,2),(3,3); explain partitions select * from t1 where b > 1 and b < 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p0_sp2,p1_sp2,p2_sp2,p3_sp2 system NULL NULL NULL NULL 1 +1 SIMPLE t1 p0_p0sp2,p1_p1sp2,p2_p2sp2,p3_p3sp2 system NULL NULL NULL NULL 1 explain partitions select * from t1 where b > 1 and b < 3 and (a =1 or a =2); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1_sp2,p2_sp2 system NULL NULL NULL NULL 1 +1 SIMPLE t1 p1_p1sp2,p2_p2sp2 system NULL NULL NULL NULL 1 drop table t1; create table t1 (a int) partition by list(a) ( partition p0 values in (1,2), diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 5c0a13fe640..e24cee9e875 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -859,6 +859,20 @@ count(*) 5 deallocate prepare stmt; drop table t1; +prepare stmt from 'create table t1 (a varchar(10) character set utf8)'; +execute stmt; +insert into t1 (a) values (repeat('a', 20)); +select length(a) from t1; +length(a) +10 +drop table t1; +execute stmt; +insert into t1 (a) values (repeat('a', 20)); +select length(a) from t1; +length(a) +10 +drop table t1; +deallocate prepare stmt; create table t1 (id int); prepare ins_call from "insert into t1 (id) values (1)"; execute ins_call; diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index 859050fd4a3..22d59c7bd8f 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -259,7 +259,7 @@ prepare stmt4 from ' show databases '; execute stmt4; Database information_schema -cluster_replication +cluster mysql test prepare stmt4 from ' show tables from test like ''t2%'' '; diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index 942eca42c93..40aa88439b9 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -3,7 +3,7 @@ flush query cache; flush query cache; reset query cache; flush status; -drop table if exists t1,t2,t3,t4,t11,t21; +drop table if exists t1,t2,t3,t4,t11,t21,t1_1,t1_2,t9,t9_1,t9_2; drop database if exists mysqltest; drop table if exists ```a`; drop view if exists v1; diff --git a/mysql-test/r/rpl_LD_INFILE.result b/mysql-test/r/rpl_LD_INFILE.result index b092dd9e088..70013f95d85 100644 --- a/mysql-test/r/rpl_LD_INFILE.result +++ b/mysql-test/r/rpl_LD_INFILE.result @@ -6,10 +6,10 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; DROP TABLE IF EXISTS test.t1; CREATE TABLE test.t1 (a VARCHAR(255), PRIMARY KEY(a)); -LOAD DATA INFILE '../../std_data/words2.dat' INTO TABLE test.t1; +LOAD DATA INFILE '../std_data_ln/words2.dat' INTO TABLE test.t1; DELETE FROM test.t1 WHERE a = 'abashed'; DELETE FROM test.t1; -LOAD DATA INFILE '../../std_data/words2.dat' INTO TABLE test.t1; +LOAD DATA INFILE '../std_data_ln/words2.dat' INTO TABLE test.t1; SELECT * FROM test.t1 ORDER BY a DESC; a aberration diff --git a/mysql-test/r/rpl_alter_db.result b/mysql-test/r/rpl_alter_db.result new file mode 100644 index 00000000000..6edbe5d427f --- /dev/null +++ b/mysql-test/r/rpl_alter_db.result @@ -0,0 +1,8 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +use mysql; +alter database collate latin1_bin; diff --git a/mysql-test/r/rpl_bit_npk.result b/mysql-test/r/rpl_bit_npk.result index aeefc77d69b..2850e63aabd 100644 --- a/mysql-test/r/rpl_bit_npk.result +++ b/mysql-test/r/rpl_bit_npk.result @@ -45,25 +45,27 @@ GSuppDf TINYINT, VNotSupp TINYINT, x034 TINYINT); LOCK TABLES test.t1 WRITE; -INSERT INTO test.t1 VALUES (6,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'111111',b'111110',b'110101',4,5,5,5,5,5,5,5,5,5,3,2,1); +INSERT INTO test.t1 VALUES (6,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'111111',b'111110',b'110101',4,5,5,5,5,5,5,5,5,5,3,NULL,1); INSERT INTO test.t1 VALUES (1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'111111',b'000000',b'100100',4,5,5,5,5,5,5,5,5,5,3,2,1); INSERT INTO test.t1 VALUES (2,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'000000',b'101010',b'010101',4,5,5,5,5,5,5,5,5,5,3,2,1); INSERT INTO test.t1 VALUES (3,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'101010',b'111111',b'000000',4,5,5,5,5,5,5,5,5,5,3,2,1); -INSERT INTO test.t1 VALUES (4,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,4,5,5,5,5,5,5,5,5,5,3,2,1); +INSERT INTO test.t1 VALUES (4,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'0',1,1,4,5,5,5,5,5,5,5,5,5,3,2,1); INSERT INTO test.t1 VALUES (5,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,4,5,5,5,5,5,5,5,5,5,3,2,1); INSERT INTO test.t1 VALUES (7,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,4,5,5,5,5,5,5,5,5,5,3,2,1); INSERT INTO test.t1 VALUES (8,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,4,5,5,5,5,5,5,5,5,5,3,2,1); UNLOCK TABLES; +UPDATE test.t1 set x034 = 50 where bit3 = b'000000'; +UPDATE test.t1 set VNotSupp = 33 where bit1 = b'0'; SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 FROM test.t1; oSupp sSuppD GSuppDf VNotSupp x034 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 +5 5 3 NULL 1 +5 5 3 2 1 +5 5 3 33 1 +5 5 3 2 50 +5 5 3 33 1 +5 5 3 33 1 +5 5 3 33 1 +5 5 3 33 1 SELECT hex(bit1) from test.t1; hex(bit1) 3F @@ -96,14 +98,14 @@ hex(bit3) 1 SELECT oSupp, sSuppD, GSuppDf, VNotSupp, x034 FROM test.t1; oSupp sSuppD GSuppDf VNotSupp x034 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 -5 5 3 2 1 +5 5 3 NULL 1 +5 5 3 2 1 +5 5 3 33 1 +5 5 3 2 50 +5 5 3 33 1 +5 5 3 33 1 +5 5 3 33 1 +5 5 3 33 1 SELECT hex(bit1) from test.t1; hex(bit1) 3F @@ -134,4 +136,30 @@ hex(bit3) 1 1 1 +CREATE TABLE test.t2 (a INT, b BIT(1)); +INSERT INTO test.t2 VALUES (1, b'0'); +INSERT INTO test.t2 VALUES (1, b'1'); +UPDATE test.t2 SET a = 2 WHERE b = b'1'; +CREATE TABLE test.t3 (a INT, b INT); +INSERT INTO test.t3 VALUES (1, NULL); +INSERT INTO test.t3 VALUES (1, 0); +UPDATE test.t3 SET a = 2 WHERE b = 0; +SELECT a, hex(b) FROM test.t2; +a hex(b) +1 0 +2 1 +SELECT * FROM test.t3; +a b +1 NULL +2 0 +SELECT a, hex(b) FROM test.t2; +a hex(b) +1 0 +2 1 +SELECT * FROM test.t3; +a b +1 NULL +2 0 DROP TABLE IF EXISTS test.t1; +DROP TABLE IF EXISTS test.t2; +DROP TABLE IF EXISTS test.t3; diff --git a/mysql-test/r/rpl_create_database.result b/mysql-test/r/rpl_create_database.result index cb3c7944962..0593501f623 100644 --- a/mysql-test/r/rpl_create_database.result +++ b/mysql-test/r/rpl_create_database.result @@ -23,7 +23,7 @@ ALTER DATABASE mysqltest_bob CHARACTER SET latin1; SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql mysqltest_bob mysqltest_prometheus @@ -32,7 +32,7 @@ test SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql mysqltest_prometheus mysqltest_sisyfos @@ -47,7 +47,7 @@ CREATE TABLE t2 (a INT); SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql mysqltest_bob mysqltest_prometheus @@ -56,7 +56,7 @@ test SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql mysqltest_prometheus mysqltest_sisyfos diff --git a/mysql-test/r/rpl_load_from_master.result b/mysql-test/r/rpl_load_from_master.result index edf1f0ee7c9..c279ee6e0aa 100644 --- a/mysql-test/r/rpl_load_from_master.result +++ b/mysql-test/r/rpl_load_from_master.result @@ -33,7 +33,7 @@ create database mysqltest; show databases; Database information_schema -cluster_replication +cluster mysql mysqltest mysqltest2 @@ -51,7 +51,7 @@ set sql_log_bin = 1; show databases; Database information_schema -cluster_replication +cluster mysql test create database mysqltest2; @@ -71,7 +71,7 @@ load data from master; show databases; Database information_schema -cluster_replication +cluster mysql mysqltest mysqltest2 diff --git a/mysql-test/r/rpl_load_table_from_master.result b/mysql-test/r/rpl_load_table_from_master.result index 9d9a1d7d6cb..c24f857d829 100644 --- a/mysql-test/r/rpl_load_table_from_master.result +++ b/mysql-test/r/rpl_load_table_from_master.result @@ -29,9 +29,9 @@ drop table t1; drop table t1; set SQL_LOG_BIN=0; create table t1 (word char(20) not null, index(word))ENGINE=MyISAM; -load data infile '../../std_data/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; create table t2 (word char(20) not null)ENGINE=MyISAM; -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; create table t3 (word char(20) not null primary key)ENGINE=MyISAM; load table t1 from master; load table t2 from master; diff --git a/mysql-test/r/rpl_loaddata2.result b/mysql-test/r/rpl_loaddata2.result index 5e3923616ed..196093211b6 100644 --- a/mysql-test/r/rpl_loaddata2.result +++ b/mysql-test/r/rpl_loaddata2.result @@ -5,7 +5,7 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; CREATE TABLE t1 (word CHAR(20) NOT NULL); -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; SELECT * FROM t1 ORDER BY word; word Aarhus diff --git a/mysql-test/r/rpl_loaddata_m.result b/mysql-test/r/rpl_loaddata_m.result index 54348df9aaa..ec2f788a5e1 100644 --- a/mysql-test/r/rpl_loaddata_m.result +++ b/mysql-test/r/rpl_loaddata_m.result @@ -7,21 +7,21 @@ start slave; drop database if exists mysqltest; USE test; CREATE TABLE t1(a INT, b INT, UNIQUE(b)); -LOAD DATA INFILE '../../std_data/rpl_loaddata.dat' INTO TABLE test.t1; +LOAD DATA INFILE '../std_data_ln/rpl_loaddata.dat' INTO TABLE test.t1; SELECT COUNT(*) FROM test.t1; COUNT(*) 2 CREATE DATABASE mysqltest; USE mysqltest; CREATE TABLE t1(a INT, b INT, UNIQUE(b)); -LOAD DATA INFILE '../../std_data/rpl_loaddata.dat' INTO TABLE mysqltest.t1; +LOAD DATA INFILE '../std_data_ln/rpl_loaddata.dat' INTO TABLE mysqltest.t1; SELECT COUNT(*) FROM mysqltest.t1; COUNT(*) 2 SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql mysqltest test diff --git a/mysql-test/r/rpl_loadfile.result b/mysql-test/r/rpl_loadfile.result index 7a5a7bc50c9..7487693a9f7 100644 --- a/mysql-test/r/rpl_loadfile.result +++ b/mysql-test/r/rpl_loadfile.result @@ -8,11 +8,11 @@ DROP PROCEDURE IF EXISTS test.p1; DROP TABLE IF EXISTS test.t1; CREATE TABLE test.t1 (a INT, blob_column LONGBLOB, PRIMARY KEY(a)); INSERT INTO test.t1 VALUES(1,'test'); -UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=1; +UPDATE test.t1 SET blob_column=LOAD_FILE('../std_data_ln/words2.dat') WHERE a=1; create procedure test.p1() begin INSERT INTO test.t1 VALUES(2,'test'); -UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=2; +UPDATE test.t1 SET blob_column=LOAD_FILE('../std_data_ln/words2.dat') WHERE a=2; end| CALL test.p1(); SELECT * FROM test.t1 ORDER BY blob_column; diff --git a/mysql-test/r/rpl_ndb_bank.result b/mysql-test/r/rpl_ndb_bank.result index 2d2d54c9170..62ab3f18d37 100644 --- a/mysql-test/r/rpl_ndb_bank.result +++ b/mysql-test/r/rpl_ndb_bank.result @@ -47,17 +47,17 @@ CREATE DATABASE IF NOT EXISTS BANK; DROP DATABASE BANK; CREATE DATABASE BANK; RESET MASTER; -CREATE TABLE IF NOT EXISTS cluster_replication.backup_info (id INT, backup_id INT) ENGINE = HEAP; -DELETE FROM cluster_replication.backup_info; -LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE cluster_replication.backup_info FIELDS TERMINATED BY ','; -SELECT @the_backup_id:=backup_id FROM cluster_replication.backup_info; +CREATE TABLE IF NOT EXISTS cluster.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM cluster.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE cluster.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM cluster.backup_info; @the_backup_id:=backup_id <the_backup_id> -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; @the_epoch:=MAX(epoch) <the_epoch> SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) -FROM cluster_replication.binlog_index WHERE epoch > <the_epoch> ORDER BY epoch ASC LIMIT 1; +FROM cluster.binlog_index WHERE epoch > <the_epoch> ORDER BY epoch ASC LIMIT 1; @the_pos:=Position @the_file:=SUBSTRING_INDEX(FILE, '/', -1) <the_pos> master-bin.000001 CHANGE MASTER TO diff --git a/mysql-test/r/rpl_ndb_blob.result b/mysql-test/r/rpl_ndb_blob.result index 031b489f7da..1419875c743 100644 --- a/mysql-test/r/rpl_ndb_blob.result +++ b/mysql-test/r/rpl_ndb_blob.result @@ -86,41 +86,41 @@ a int not null primary key, b text not null ) engine=ndb master-bin.000001 239 Query 1 303 BEGIN -master-bin.000001 303 Table_map 1 65 cluster_replication.apply_status -master-bin.000001 368 Write_rows 1 107 -master-bin.000001 410 Table_map 1 147 test.t1 -master-bin.000001 450 Write_rows 1 818 -master-bin.000001 1121 Write_rows 1 9853 -master-bin.000001 10156 Query 1 10221 COMMIT -master-bin.000001 10221 Query 1 10285 BEGIN -master-bin.000001 10285 Table_map 1 65 cluster_replication.apply_status -master-bin.000001 10350 Write_rows 1 107 -master-bin.000001 10392 Query 1 10457 COMMIT -master-bin.000001 10457 Query 1 10533 use `test`; drop table t1 -master-bin.000001 10533 Query 1 10708 use `test`; create table t1 ( +master-bin.000001 303 Table_map 1 53 cluster.apply_status +master-bin.000001 356 Write_rows 1 95 +master-bin.000001 398 Table_map 1 135 test.t1 +master-bin.000001 438 Write_rows 1 806 +master-bin.000001 1109 Write_rows 1 9841 +master-bin.000001 10144 Query 1 10209 COMMIT +master-bin.000001 10209 Query 1 10273 BEGIN +master-bin.000001 10273 Table_map 1 53 cluster.apply_status +master-bin.000001 10326 Write_rows 1 95 +master-bin.000001 10368 Query 1 10433 COMMIT +master-bin.000001 10433 Query 1 10509 use `test`; drop table t1 +master-bin.000001 10509 Query 1 10684 use `test`; create table t1 ( a int not null primary key, b text not null, c int, d longblob, e tinyblob ) engine=ndbcluster -master-bin.000001 10708 Query 1 10772 BEGIN -master-bin.000001 10772 Table_map 1 65 cluster_replication.apply_status -master-bin.000001 10837 Write_rows 1 107 -master-bin.000001 10879 Table_map 1 150 test.t1 -master-bin.000001 10922 Write_rows 1 48934 -master-bin.000001 59706 Write_rows 1 124436 -master-bin.000001 135208 Write_rows 1 124542 -master-bin.000001 135314 Write_rows 1 205961 -master-bin.000001 216733 Write_rows 1 224245 -master-bin.000001 235017 Write_rows 1 227523 -master-bin.000001 238295 Write_rows 1 242391 -master-bin.000001 253163 Write_rows 1 254087 -master-bin.000001 264859 Write_rows 1 304335 -master-bin.000001 315107 Write_rows 1 330427 -master-bin.000001 341199 Query 1 341264 COMMIT -master-bin.000001 341264 Query 1 341328 BEGIN -master-bin.000001 341328 Table_map 1 65 cluster_replication.apply_status -master-bin.000001 341393 Write_rows 1 107 -master-bin.000001 341435 Query 1 341500 COMMIT -master-bin.000001 341500 Query 1 341576 use `test`; drop table t1 +master-bin.000001 10684 Query 1 10748 BEGIN +master-bin.000001 10748 Table_map 1 53 cluster.apply_status +master-bin.000001 10801 Write_rows 1 95 +master-bin.000001 10843 Table_map 1 138 test.t1 +master-bin.000001 10886 Write_rows 1 48922 +master-bin.000001 59670 Write_rows 1 124424 +master-bin.000001 135172 Write_rows 1 124530 +master-bin.000001 135278 Write_rows 1 205949 +master-bin.000001 216697 Write_rows 1 224233 +master-bin.000001 234981 Write_rows 1 227511 +master-bin.000001 238259 Write_rows 1 242379 +master-bin.000001 253127 Write_rows 1 254075 +master-bin.000001 264823 Write_rows 1 304323 +master-bin.000001 315071 Write_rows 1 330415 +master-bin.000001 341163 Query 1 341228 COMMIT +master-bin.000001 341228 Query 1 341292 BEGIN +master-bin.000001 341292 Table_map 1 53 cluster.apply_status +master-bin.000001 341345 Write_rows 1 95 +master-bin.000001 341387 Query 1 341452 COMMIT +master-bin.000001 341452 Query 1 341528 use `test`; drop table t1 diff --git a/mysql-test/r/rpl_ndb_dd_basic.result b/mysql-test/r/rpl_ndb_dd_basic.result index 24488b8e62d..1afe235bd72 100644 --- a/mysql-test/r/rpl_ndb_dd_basic.result +++ b/mysql-test/r/rpl_ndb_dd_basic.result @@ -57,11 +57,11 @@ master-bin.000001 798 Query 1 978 use `test`; CREATE TABLE t1 tablespace ts1 storage disk engine ndb master-bin.000001 978 Query 1 1042 BEGIN -master-bin.000001 1042 Table_map 1 65 cluster_replication.apply_status -master-bin.000001 1107 Write_rows 1 107 -master-bin.000001 1149 Table_map 1 148 test.t1 -master-bin.000001 1190 Write_rows 1 190 -master-bin.000001 1232 Query 1 1297 COMMIT +master-bin.000001 1042 Table_map 1 53 cluster.apply_status +master-bin.000001 1095 Write_rows 1 95 +master-bin.000001 1137 Table_map 1 136 test.t1 +master-bin.000001 1178 Write_rows 1 178 +master-bin.000001 1220 Query 1 1285 COMMIT drop table t1; alter tablespace ts1 drop datafile 'datafile.dat' diff --git a/mysql-test/r/rpl_ndb_idempotent.result b/mysql-test/r/rpl_ndb_idempotent.result index 3315e05f97e..1ba23e703c2 100644 --- a/mysql-test/r/rpl_ndb_idempotent.result +++ b/mysql-test/r/rpl_ndb_idempotent.result @@ -9,14 +9,14 @@ INSERT INTO t1 VALUES ("row1","will go away",1); SELECT * FROM t1 ORDER BY c3; c1 c2 c3 row1 will go away 1 -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; @the_epoch:=MAX(epoch) <the_epoch> SELECT * FROM t1 ORDER BY c3; c1 c2 c3 row1 will go away 1 SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) -FROM cluster_replication.binlog_index WHERE epoch = <the_epoch> ; +FROM cluster.binlog_index WHERE epoch = <the_epoch> ; @the_pos:=Position @the_file:=SUBSTRING_INDEX(FILE, '/', -1) <the_pos> master-bin.000001 INSERT INTO t1 VALUES ("row2","will go away",2),("row3","will change",3),("row4","D",4); diff --git a/mysql-test/r/rpl_ndb_log.result b/mysql-test/r/rpl_ndb_log.result index 2fec18ad113..1396e829568 100644 --- a/mysql-test/r/rpl_ndb_log.result +++ b/mysql-test/r/rpl_ndb_log.result @@ -21,7 +21,7 @@ Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Format_desc 1 # Server ver: VERSION, Binlog ver: 4 master-bin.000001 # Query 1 # use `test`; create table t1(n int not null auto_increment primary key)ENGINE=NDB master-bin.000001 # Query 1 # BEGIN -master-bin.000001 # Table_map 1 # cluster_replication.apply_status +master-bin.000001 # Table_map 1 # cluster.apply_status master-bin.000001 # Write_rows 1 # master-bin.000001 # Table_map 1 # test.t1 master-bin.000001 # Write_rows 1 # @@ -29,7 +29,7 @@ master-bin.000001 # Query 1 # COMMIT master-bin.000001 # Query 1 # use `test`; drop table t1 master-bin.000001 # Query 1 # use `test`; create table t1 (word char(20) not null)ENGINE=NDB master-bin.000001 # Query 1 # BEGIN -master-bin.000001 # Table_map 1 # cluster_replication.apply_status +master-bin.000001 # Table_map 1 # cluster.apply_status master-bin.000001 # Write_rows 1 # master-bin.000001 # Table_map 1 # test.t1 master-bin.000001 # Write_rows 1 # @@ -43,7 +43,7 @@ master-bin.000001 # Query 1 # use `test`; create table t1(n int not null auto_in master-bin.000001 # Query 1 # BEGIN show binlog events from 102 limit 2,1; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Table_map 1 # cluster_replication.apply_status +master-bin.000001 # Table_map 1 # cluster.apply_status flush logs; create table t3 (a int)ENGINE=NDB; start slave; @@ -56,7 +56,7 @@ Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Format_desc 1 # Server ver: VERSION, Binlog ver: 4 master-bin.000001 # Query 1 # use `test`; create table t1(n int not null auto_increment primary key)ENGINE=NDB master-bin.000001 # Query 1 # BEGIN -master-bin.000001 # Table_map 1 # cluster_replication.apply_status +master-bin.000001 # Table_map 1 # cluster.apply_status master-bin.000001 # Write_rows 1 # master-bin.000001 # Table_map 1 # test.t1 master-bin.000001 # Write_rows 1 # @@ -64,7 +64,7 @@ master-bin.000001 # Query 1 # COMMIT master-bin.000001 # Query 1 # use `test`; drop table t1 master-bin.000001 # Query 1 # use `test`; create table t1 (word char(20) not null)ENGINE=NDB master-bin.000001 # Query 1 # BEGIN -master-bin.000001 # Table_map 1 # cluster_replication.apply_status +master-bin.000001 # Table_map 1 # cluster.apply_status master-bin.000001 # Write_rows 1 # master-bin.000001 # Table_map 1 # test.t1 master-bin.000001 # Write_rows 1 # @@ -76,7 +76,7 @@ master-bin.000002 # Format_desc 1 # Server ver: VERSION, Binlog ver: 4 master-bin.000002 # Query 1 # use `test`; create table t3 (a int)ENGINE=NDB master-bin.000002 # Query 1 # use `test`; create table t2 (n int)ENGINE=NDB master-bin.000002 # Query 1 # BEGIN -master-bin.000002 # Table_map 1 # cluster_replication.apply_status +master-bin.000002 # Table_map 1 # cluster.apply_status master-bin.000002 # Write_rows 1 # master-bin.000002 # Table_map 1 # test.t2 master-bin.000002 # Write_rows 1 # @@ -95,7 +95,7 @@ Log_name Pos Event_type Server_id End_log_pos Info slave-bin.000001 # Format_desc 2 # Server ver: VERSION, Binlog ver: 4 slave-bin.000001 # Query 1 # use `test`; create table t1(n int not null auto_increment primary key)ENGINE=NDB slave-bin.000001 # Query 2 # BEGIN -slave-bin.000001 # Table_map 2 # cluster_replication.apply_status +slave-bin.000001 # Table_map 2 # cluster.apply_status slave-bin.000001 # Write_rows 2 # slave-bin.000001 # Table_map 2 # test.t1 slave-bin.000001 # Write_rows 2 # @@ -104,7 +104,7 @@ slave-bin.000001 # Query 1 # use `test`; drop table t1 slave-bin.000001 # Query 1 # use `test`; create table t1 (word char(20) not null)ENGINE=NDB slave-bin.000001 # Query 1 # use `test`; create table t3 (a int)ENGINE=NDB slave-bin.000001 # Query 2 # BEGIN -slave-bin.000001 # Table_map 2 # cluster_replication.apply_status +slave-bin.000001 # Table_map 2 # cluster.apply_status slave-bin.000001 # Write_rows 2 # slave-bin.000001 # Table_map 2 # test.t1 slave-bin.000001 # Write_rows 2 # @@ -115,7 +115,7 @@ Log_name Pos Event_type Server_id End_log_pos Info slave-bin.000002 # Format_desc 2 # Server ver: VERSION, Binlog ver: 4 slave-bin.000002 # Query 1 # use `test`; create table t2 (n int)ENGINE=NDB slave-bin.000002 # Query 2 # BEGIN -slave-bin.000002 # Table_map 2 # cluster_replication.apply_status +slave-bin.000002 # Table_map 2 # cluster.apply_status slave-bin.000002 # Write_rows 2 # slave-bin.000002 # Table_map 2 # test.t2 slave-bin.000002 # Write_rows 2 # diff --git a/mysql-test/r/rpl_ndb_multi.result b/mysql-test/r/rpl_ndb_multi.result index d3afd787613..13751060ed3 100644 --- a/mysql-test/r/rpl_ndb_multi.result +++ b/mysql-test/r/rpl_ndb_multi.result @@ -16,7 +16,7 @@ row1 will go away 1 SELECT * FROM t1 ORDER BY c3; c1 c2 c3 row1 will go away 1 -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; @the_epoch:=MAX(epoch) <the_epoch> SELECT * FROM t1 ORDER BY c3; @@ -24,7 +24,7 @@ c1 c2 c3 row1 will go away 1 stop slave; SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) -FROM cluster_replication.binlog_index WHERE epoch = <the_epoch> ; +FROM cluster.binlog_index WHERE epoch = <the_epoch> ; @the_pos:=Position @the_file:=SUBSTRING_INDEX(FILE, '/', -1) 102 master-bin1.000001 CHANGE MASTER TO diff --git a/mysql-test/r/rpl_ndb_row_001.result b/mysql-test/r/rpl_ndb_row_001.result index 20e98dab00d..56bb31e329d 100644 --- a/mysql-test/r/rpl_ndb_row_001.result +++ b/mysql-test/r/rpl_ndb_row_001.result @@ -5,7 +5,7 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; CREATE TABLE t1 (word CHAR(20) NOT NULL); -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; LOAD DATA LOCAL INFILE 'MYSQL_TEST_DIR/std_data/words.dat' INTO TABLE t1; SELECT * FROM t1 ORDER BY word LIMIT 10; word diff --git a/mysql-test/r/rpl_ndb_sync.result b/mysql-test/r/rpl_ndb_sync.result index 5f465dc427c..897737e95d5 100644 --- a/mysql-test/r/rpl_ndb_sync.result +++ b/mysql-test/r/rpl_ndb_sync.result @@ -25,13 +25,13 @@ hex(c2) hex(c3) c1 0 1 BCDEF 1 0 CD 0 0 DEFGHIJKL -CREATE TEMPORARY TABLE IF NOT EXISTS cluster_replication.backup_info (id INT, backup_id INT)ENGINE=HEAP; -DELETE FROM cluster_replication.backup_info; -LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE cluster_replication.backup_info FIELDS TERMINATED BY ','; -SELECT @the_backup_id:=backup_id FROM cluster_replication.backup_info; +CREATE TEMPORARY TABLE IF NOT EXISTS cluster.backup_info (id INT, backup_id INT)ENGINE=HEAP; +DELETE FROM cluster.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE cluster.backup_info FIELDS TERMINATED BY ','; +SELECT @the_backup_id:=backup_id FROM cluster.backup_info; @the_backup_id:=backup_id <the_backup_id> -DROP TABLE cluster_replication.backup_info; +DROP TABLE cluster.backup_info; UPDATE t1 SET c2=0 WHERE c3="row2"; SELECT hex(c1),hex(c2),c3 FROM t1 ORDER BY c3; hex(c1) hex(c2) c3 @@ -60,11 +60,11 @@ hex(c2) hex(c3) c1 0 1 BCDEF 1 0 CD 0 0 DEFGHIJKL -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; @the_epoch:=MAX(epoch) <the_epoch> SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) -FROM cluster_replication.binlog_index WHERE epoch > <the_epoch> ORDER BY epoch ASC LIMIT 1; +FROM cluster.binlog_index WHERE epoch > <the_epoch> ORDER BY epoch ASC LIMIT 1; @the_pos:=Position @the_file:=SUBSTRING_INDEX(FILE, '/', -1) <the_pos> master-bin.000001 CHANGE MASTER TO @@ -89,8 +89,8 @@ hex(c2) hex(c3) c1 DROP DATABASE ndbsynctest; STOP SLAVE; reset master; -select * from cluster_replication.binlog_index; +select * from cluster.binlog_index; Position File epoch inserts updates deletes schemaops reset slave; -select * from cluster_replication.apply_status; +select * from cluster.apply_status; server_id epoch diff --git a/mysql-test/r/rpl_row_001.result b/mysql-test/r/rpl_row_001.result index b07a99644fc..fad60af664f 100644 --- a/mysql-test/r/rpl_row_001.result +++ b/mysql-test/r/rpl_row_001.result @@ -5,7 +5,7 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; CREATE TABLE t1 (word CHAR(20) NOT NULL); -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; LOAD DATA LOCAL INFILE 'MYSQL_TEST_DIR/std_data/words.dat' INTO TABLE t1; SELECT * FROM t1 ORDER BY word LIMIT 10; word diff --git a/mysql-test/r/rpl_row_4_bytes.result b/mysql-test/r/rpl_row_4_bytes.result index b88d5661a90..e2431364ed3 100644 --- a/mysql-test/r/rpl_row_4_bytes.result +++ b/mysql-test/r/rpl_row_4_bytes.result @@ -24,4 +24,4 @@ a ABE ANG LIL -DROP TABLE t1,t2; +DROP DATABASE mysqltest1; diff --git a/mysql-test/r/rpl_row_basic_11bugs.result b/mysql-test/r/rpl_row_basic_11bugs.result index 6cb71e48ecc..46ea9c26422 100644 --- a/mysql-test/r/rpl_row_basic_11bugs.result +++ b/mysql-test/r/rpl_row_basic_11bugs.result @@ -9,7 +9,7 @@ CREATE DATABASE test_ignore; SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql test test_ignore @@ -29,7 +29,7 @@ INSERT INTO t2 VALUES (3,3), (4,4); SHOW DATABASES; Database information_schema -cluster_replication +cluster mysql test USE test; diff --git a/mysql-test/r/rpl_row_drop.result b/mysql-test/r/rpl_row_drop.result index 4ef21884fda..a5abc2837e3 100644 --- a/mysql-test/r/rpl_row_drop.result +++ b/mysql-test/r/rpl_row_drop.result @@ -41,12 +41,6 @@ t1 t2 **** On Master **** DROP TABLE t1,t2; -SHOW BINLOG EVENTS; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 4 Format_desc 1 102 Server ver: VERSION, Binlog ver: 4 -master-bin.000001 102 Query 1 188 use `test`; CREATE TABLE t1 (a int) -master-bin.000001 188 Query 1 274 use `test`; CREATE TABLE t2 (a int) -master-bin.000001 274 Query 1 378 use `test`; DROP TABLE `t1` /* generated by server */ SHOW TABLES; Tables_in_test t2 diff --git a/mysql-test/r/rpl_row_loaddata_m.result b/mysql-test/r/rpl_row_loaddata_m.result index 198e55c71d0..149efddaf8d 100644 --- a/mysql-test/r/rpl_row_loaddata_m.result +++ b/mysql-test/r/rpl_row_loaddata_m.result @@ -9,7 +9,7 @@ stop slave; create database mysqltest; use mysqltest; create table t1(a int, b int, unique(b)); -load data infile '../../std_data/rpl_loaddata.dat' into table t1; +load data infile '../std_data_ln/rpl_loaddata.dat' into table t1; show binlog events from 102; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query 1 # # diff --git a/mysql-test/r/rpl_row_mysqlbinlog.result b/mysql-test/r/rpl_row_mysqlbinlog.result new file mode 100644 index 00000000000..374f2d3ee82 --- /dev/null +++ b/mysql-test/r/rpl_row_mysqlbinlog.result @@ -0,0 +1,266 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; + +---Setup Section -- +set timestamp=1000000000; +DROP TABLE IF EXISTS t1,t2,t3; +CREATE TABLE t1(word VARCHAR(20)); +CREATE TABLE t2(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY); +CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT); + +---Test1 check table load -- +SELECT COUNT(*) from t1; +COUNT(*) +351 +SELECT COUNT(*) from t2; +COUNT(*) +500 +SELECT COUNT(*) from t3; +COUNT(*) +500 +SELECT * FROM t1 ORDER BY word LIMIT 5; +word +Aarhus +Aarhus +Aarhus +Aarhus +Aarhus +SELECT * FROM t2 ORDER BY id LIMIT 5; +id +1 +2 +3 +4 +5 +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; +c1 c3 c4 c5 +1 2006-02-22 00:00:00 Tested in Texas 2.2 +2 2006-02-22 00:00:00 Tested in Texas 4.4 +3 2006-02-22 00:00:00 Tested in Texas 6.6 +4 2006-02-22 00:00:00 Tested in Texas 8.8 +5 2006-02-22 00:00:00 Tested in Texas 11 +SELECT COUNT(*) from t1; +COUNT(*) +351 +SELECT COUNT(*) from t2; +COUNT(*) +500 +SELECT COUNT(*) from t3; +COUNT(*) +500 +SELECT * FROM t1 ORDER BY word LIMIT 5; +word +Aarhus +Aarhus +Aarhus +Aarhus +Aarhus +SELECT * FROM t2 ORDER BY id LIMIT 5; +id +1 +2 +3 +4 +5 +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; +c1 c3 c4 c5 +1 2006-02-22 00:00:00 Tested in Texas 2.2 +2 2006-02-22 00:00:00 Tested in Texas 4.4 +3 2006-02-22 00:00:00 Tested in Texas 6.6 +4 2006-02-22 00:00:00 Tested in Texas 8.8 +5 2006-02-22 00:00:00 Tested in Texas 11 +insert into t1 values ("Alas"); +flush logs; + +--- Test 1 Dump binlog to file -- + +--- Test 1 delete tables, clean master and slave -- +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; +stop slave; +reset master; +reset slave; +start slave; + +--- Test 1 Load from Dump binlog file -- + +--- Test 1 Check Load Results -- +SELECT COUNT(*) from t1; +COUNT(*) +352 +SELECT COUNT(*) from t2; +COUNT(*) +500 +SELECT COUNT(*) from t3; +COUNT(*) +500 +SELECT * FROM t1 ORDER BY word LIMIT 5; +word +Aarhus +Aarhus +Aarhus +Aarhus +Aarhus +SELECT * FROM t2 ORDER BY id LIMIT 5; +id +1 +2 +3 +4 +5 +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; +c1 c3 c4 c5 +1 2006-02-22 00:00:00 Tested in Texas 2.2 +2 2006-02-22 00:00:00 Tested in Texas 4.4 +3 2006-02-22 00:00:00 Tested in Texas 6.6 +4 2006-02-22 00:00:00 Tested in Texas 8.8 +5 2006-02-22 00:00:00 Tested in Texas 11 +SELECT COUNT(*) from t1; +COUNT(*) +352 +SELECT COUNT(*) from t2; +COUNT(*) +500 +SELECT COUNT(*) from t3; +COUNT(*) +500 +SELECT * FROM t1 ORDER BY word LIMIT 5; +word +Aarhus +Aarhus +Aarhus +Aarhus +Aarhus +SELECT * FROM t2 ORDER BY id LIMIT 5; +id +1 +2 +3 +4 +5 +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; +c1 c3 c4 c5 +1 2006-02-22 00:00:00 Tested in Texas 2.2 +2 2006-02-22 00:00:00 Tested in Texas 4.4 +3 2006-02-22 00:00:00 Tested in Texas 6.6 +4 2006-02-22 00:00:00 Tested in Texas 8.8 +5 2006-02-22 00:00:00 Tested in Texas 11 + +--- Test 2 position test -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +use test; +SET TIMESTAMP=1000000000; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1; +SET @@session.sql_mode=0; +/*!\C latin1 */; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8; +CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT); +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- Test 3 First Remote test -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +ROLLBACK; +use test; +SET TIMESTAMP=1000000000; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1; +SET @@session.sql_mode=0; +/*!\C latin1 */; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8; +DROP TABLE IF EXISTS t1,t2,t3; +SET TIMESTAMP=1000000000; +CREATE TABLE t1(word VARCHAR(20)); +SET TIMESTAMP=1000000000; +CREATE TABLE t2(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY); +SET TIMESTAMP=1000000000; +CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT); +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- Test 5 LOAD DATA -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- Test 6 reading stdin -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +ROLLBACK; +use test; +SET TIMESTAMP=1000000000; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1; +SET @@session.sql_mode=0; +/*!\C latin1 */; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8; +DROP TABLE IF EXISTS t1,t2,t3; +SET TIMESTAMP=1000000000; +CREATE TABLE t1(word VARCHAR(20)); +SET TIMESTAMP=1000000000; +CREATE TABLE t2(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY); +SET TIMESTAMP=1000000000; +CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT); +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- Test 7 reading stdin w/position -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +use test; +SET TIMESTAMP=1000000000; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1; +SET @@session.sql_mode=0; +/*!\C latin1 */; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8; +CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT); +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- Test 8 switch internal charset -- +stop slave; +reset master; +reset slave; +start slave; +create table t4 (f text character set utf8); +create table t5 (f text character set cp932); +flush logs; +rename table t4 to t04, t5 to t05; +select HEX(f) from t04; +HEX(f) +E382BD +select HEX(f) from t4; +HEX(f) +E382BD +select HEX(f) from t05; +HEX(f) +835C +select HEX(f) from t5; +HEX(f) +835C +select HEX(f) from t04; +HEX(f) +E382BD +select HEX(f) from t4; +HEX(f) +E382BD +select HEX(f) from t05; +HEX(f) +835C +select HEX(f) from t5; +HEX(f) +835C + +--- Test cleanup -- +DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5; diff --git a/mysql-test/r/rpl_row_sp010.result b/mysql-test/r/rpl_row_sp010.result index ba97f83b86a..02567465428 100644 --- a/mysql-test/r/rpl_row_sp010.result +++ b/mysql-test/r/rpl_row_sp010.result @@ -22,7 +22,7 @@ INSERT INTO test.t1 VALUES(1); CALL test.p1(); END| CALL test.p2(); -SELECT * FROM test.t1; +SELECT * FROM test.t1 ORDER BY a; a 1 2 @@ -40,11 +40,11 @@ INSERT INTO test.t2 VALUES(6); CALL test.p3(); END| CALL test.p4(); -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; a 6 7 -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; a 6 7 diff --git a/mysql-test/r/rpl_row_stop_middle_update.result b/mysql-test/r/rpl_row_stop_middle_update.result index 584a3af4543..0fd4ff86893 100644 --- a/mysql-test/r/rpl_row_stop_middle_update.result +++ b/mysql-test/r/rpl_row_stop_middle_update.result @@ -5,7 +5,7 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; create table t1 (words varchar(20)) engine=myisam; -load data infile '../../std_data/words.dat' into table t1 (words); +load data infile '../std_data_ln/words.dat' into table t1 (words); select count(*) from t1; count(*) 70 diff --git a/mysql-test/r/rpl_switch_stm_row_mixed.result b/mysql-test/r/rpl_switch_stm_row_mixed.result new file mode 100644 index 00000000000..3459320b59d --- /dev/null +++ b/mysql-test/r/rpl_switch_stm_row_mixed.result @@ -0,0 +1,224 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +drop database if exists mysqltest1; +create database mysqltest1; +use mysqltest1; +show global variables like "binlog_format%"; +Variable_name Value +binlog_format ROW +show session variables like "binlog_format%"; +Variable_name Value +binlog_format ROW +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +ROW ROW +CREATE TABLE t1 (a varchar(100)); +prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work")); +execute stmt1 using @string; +deallocate prepare stmt1; +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; +create temporary table tmp(a char(3)); +insert into tmp values("see"); +set binlog_format=statement; +ERROR HY000: Cannot switch out of the row-based binary log format when the session has open temporary tables +insert into t1 select * from tmp; +drop temporary table tmp; +set binlog_format=statement; +show global variables like "binlog_format%"; +Variable_name Value +binlog_format ROW +show session variables like "binlog_format%"; +Variable_name Value +binlog_format STATEMENT +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +ROW STATEMENT +set global binlog_format=statement; +show global variables like "binlog_format%"; +Variable_name Value +binlog_format STATEMENT +show session variables like "binlog_format%"; +Variable_name Value +binlog_format STATEMENT +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +STATEMENT STATEMENT +prepare stmt1 from 'insert into t1 select ?'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; +insert into t1 values("for"); +insert into t1 select "yesterday"; +set binlog_format=default; +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +STATEMENT STATEMENT +set global binlog_format=default; +ERROR 42000: Variable 'binlog_format' doesn't have a default value +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +STATEMENT STATEMENT +prepare stmt1 from 'insert into t1 select ?'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; +insert into t1 values("for"); +insert into t1 select "yesterday"; +set binlog_format=mixed; +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +STATEMENT MIXED +set global binlog_format=mixed; +select @@global.binlog_format, @@session.binlog_format; +@@global.binlog_format @@session.binlog_format +MIXED MIXED +prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work")); +execute stmt1 using @string; +deallocate prepare stmt1; +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work")); +execute stmt1 using @string; +deallocate prepare stmt1; +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; +create procedure foo() +begin +insert into t1 values("work"); +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; +end| +create procedure foo2() +begin +insert into t1 values(concat("emergency",UUID())); +insert into t1 values("work"); +insert into t1 values(concat("for",UUID())); +set session binlog_format=row; # accepted for stored procs +insert into t1 values("more work"); +set session binlog_format=mixed; +end| +create function foo3() returns bigint unsigned +begin +set session binlog_format=row; # rejected for stored funcs +insert into t1 values("alarm"); +return 100; +end| +call foo(); +call foo2(); +select foo3(); +ERROR HY000: Cannot change the binary logging format inside a stored function or trigger +select * from t1 where a="alarm"; +a +show binlog events from 102; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 102 Query 1 205 drop database if exists mysqltest1 +master-bin.000001 205 Query 1 300 create database mysqltest1 +master-bin.000001 300 Query 1 401 use `mysqltest1`; CREATE TABLE t1 (a varchar(100)) +master-bin.000001 401 Table_map 1 446 mysqltest1.t1 +master-bin.000001 446 Write_rows 1 481 +master-bin.000001 481 Table_map 1 526 mysqltest1.t1 +master-bin.000001 526 Write_rows 1 602 +master-bin.000001 602 Table_map 1 647 mysqltest1.t1 +master-bin.000001 647 Write_rows 1 718 +master-bin.000001 718 Table_map 1 763 mysqltest1.t1 +master-bin.000001 763 Write_rows 1 803 +master-bin.000001 803 Table_map 1 848 mysqltest1.t1 +master-bin.000001 848 Write_rows 1 918 +master-bin.000001 918 Table_map 1 963 mysqltest1.t1 +master-bin.000001 963 Write_rows 1 1003 +master-bin.000001 1003 Table_map 1 1048 mysqltest1.t1 +master-bin.000001 1048 Write_rows 1 1082 +master-bin.000001 1082 Query 1 1180 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 1180 User var 1 1228 @`string`=_latin1 0x656D657267656E6379 COLLATE latin1_swedish_ci +master-bin.000001 1228 Query 1 1328 use `mysqltest1`; insert into t1 select @'string' +master-bin.000001 1328 Query 1 1426 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 1426 User var 1 1474 @`string`=_latin1 0x656D657267656E6379 COLLATE latin1_swedish_ci +master-bin.000001 1474 Query 1 1574 use `mysqltest1`; insert into t1 select @'string' +master-bin.000001 1574 Query 1 1671 use `mysqltest1`; insert into t1 values("for") +master-bin.000001 1671 Query 1 1773 use `mysqltest1`; insert into t1 select "yesterday" +master-bin.000001 1773 Query 1 1871 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 1871 User var 1 1919 @`string`=_latin1 0x656D657267656E6379 COLLATE latin1_swedish_ci +master-bin.000001 1919 Query 1 2019 use `mysqltest1`; insert into t1 select @'string' +master-bin.000001 2019 Query 1 2117 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 2117 User var 1 2165 @`string`=_latin1 0x656D657267656E6379 COLLATE latin1_swedish_ci +master-bin.000001 2165 Query 1 2265 use `mysqltest1`; insert into t1 select @'string' +master-bin.000001 2265 Query 1 2362 use `mysqltest1`; insert into t1 values("for") +master-bin.000001 2362 Query 1 2464 use `mysqltest1`; insert into t1 select "yesterday" +master-bin.000001 2464 Query 1 2562 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 2562 Table_map 1 2607 mysqltest1.t1 +master-bin.000001 2607 Write_rows 1 2683 +master-bin.000001 2683 Table_map 1 2728 mysqltest1.t1 +master-bin.000001 2728 Write_rows 1 2799 +master-bin.000001 2799 User var 1 2847 @`string`=_latin1 0x656D657267656E6379 COLLATE latin1_swedish_ci +master-bin.000001 2847 Query 1 2947 use `mysqltest1`; insert into t1 select @'string' +master-bin.000001 2947 Table_map 1 2992 mysqltest1.t1 +master-bin.000001 2992 Write_rows 1 3062 +master-bin.000001 3062 Query 1 3164 use `mysqltest1`; insert into t1 select "yesterday" +master-bin.000001 3164 Table_map 1 3209 mysqltest1.t1 +master-bin.000001 3209 Write_rows 1 3280 +master-bin.000001 3280 User var 1 3328 @`string`=_latin1 0x656D657267656E6379 COLLATE latin1_swedish_ci +master-bin.000001 3328 Query 1 3428 use `mysqltest1`; insert into t1 select @'string' +master-bin.000001 3428 Table_map 1 3473 mysqltest1.t1 +master-bin.000001 3473 Write_rows 1 3543 +master-bin.000001 3543 Query 1 3645 use `mysqltest1`; insert into t1 select "yesterday" +master-bin.000001 3645 Query 1 3857 use `mysqltest1`; create procedure foo() +begin +insert into t1 values("work"); +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; +end +master-bin.000001 3857 Query 1 4214 use `mysqltest1`; create procedure foo2() +begin +insert into t1 values(concat("emergency",UUID())); +insert into t1 values("work"); +insert into t1 values(concat("for",UUID())); +set session binlog_format=row; # accepted for stored procs +insert into t1 values("more work"); +set session binlog_format=mixed; +end +master-bin.000001 4214 Query 1 4442 use `mysqltest1`; create function foo3() returns bigint unsigned +begin +set session binlog_format=row; # rejected for stored funcs +insert into t1 values("alarm"); +return 100; +end +master-bin.000001 4442 Query 1 4548 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 4548 Table_map 1 4593 mysqltest1.t1 +master-bin.000001 4593 Write_rows 1 4663 +master-bin.000001 4663 Query 1 4773 use `mysqltest1`; insert into t1 select "yesterday" +master-bin.000001 4773 Table_map 1 4818 mysqltest1.t1 +master-bin.000001 4818 Write_rows 1 4894 +master-bin.000001 4894 Query 1 5000 use `mysqltest1`; insert into t1 values("work") +master-bin.000001 5000 Table_map 1 5045 mysqltest1.t1 +master-bin.000001 5045 Write_rows 1 5115 +master-bin.000001 5115 Table_map 1 5160 mysqltest1.t1 +master-bin.000001 5160 Write_rows 1 5200 +drop database mysqltest1; diff --git a/mysql-test/r/schema.result b/mysql-test/r/schema.result index a1b3fa9f1b3..8ed1a587588 100644 --- a/mysql-test/r/schema.result +++ b/mysql-test/r/schema.result @@ -6,7 +6,7 @@ foo CREATE DATABASE `foo` /*!40100 DEFAULT CHARACTER SET latin1 */ show schemas; Database information_schema -cluster_replication +cluster foo mysql test diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 59e9cca1e8e..a8af5c59b81 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -53,7 +53,7 @@ Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length I show databases; Database information_schema -cluster_replication +cluster mysql test show databases like "test%"; diff --git a/mysql-test/r/skip_grants.result b/mysql-test/r/skip_grants.result index 5dc770a7363..95464ee4ce5 100644 --- a/mysql-test/r/skip_grants.result +++ b/mysql-test/r/skip_grants.result @@ -12,3 +12,6 @@ create table t1 (a int); create definer='user'@'host' sql security definer view v1 as select * from t1; drop view v1; drop table t1; +drop function if exists f1; +Warnings: +Note 1305 FUNCTION f1 does not exist diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index fc29f915b82..5ab8779782a 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1163,3 +1163,6 @@ end| call bug15091(); ERROR 42S02: Unknown table 'c' in field list drop procedure bug15091; +drop function if exists bug16896; +create aggregate function bug16896() returns int return 1; +ERROR 42000: AGGREGATE is not supported for stored functions diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result index ff729e87f97..a1a197cb9d6 100644 --- a/mysql-test/r/sp-security.result +++ b/mysql-test/r/sp-security.result @@ -314,3 +314,12 @@ select * from db_bug14533.t1; ERROR 42000: SELECT command denied to user 'user_bug14533'@'localhost' for table 't1' drop user user_bug14533@localhost; drop database db_bug14533; +CREATE DATABASE db_bug7787; +use db_bug7787; +CREATE PROCEDURE p1() +SHOW INNODB STATUS; +Warnings: +Warning 1540 The syntax 'SHOW INNODB STATUS' is deprecated and will be removed in MySQL 5.2. Please use 'SHOW ENGINE INNODB STATUS' instead. +GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost; +DROP DATABASE db_bug7787; +use test; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 7b2edd98a5b..50ab0e9d9eb 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -539,7 +539,7 @@ drop procedure if exists into_outfile| create procedure into_outfile(x char(16), y int) begin insert into test.t1 values (x, y); -select * into outfile "/tmp/spout" from test.t1; +select * into outfile "../tmp/spout" from test.t1; insert into test.t1 values (concat(x, "2"), y+2); end| call into_outfile("ofile", 1)| @@ -549,7 +549,7 @@ drop procedure if exists into_dumpfile| create procedure into_dumpfile(x char(16), y int) begin insert into test.t1 values (x, y); -select * into dumpfile "/tmp/spdump" from test.t1 limit 1; +select * into dumpfile "../tmp/spdump" from test.t1 limit 1; insert into test.t1 values (concat(x, "2"), y+2); end| call into_dumpfile("dfile", 1)| @@ -1413,8 +1413,6 @@ select `foo` ()| 5 drop function `foo`| drop function if exists t1max| -Warnings: -Note 1305 FUNCTION t1max does not exist create function t1max() returns int begin declare x int; @@ -1470,6 +1468,339 @@ zip 3 foo 1 drop table t3| drop function getcount| +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +create table t3 (a smallint primary key)| +insert into t3 (a) values (1)| +create procedure h_ee() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (bad)' as 'h_ee'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_ee'; +insert into t3 values (1); +end; +end| +create procedure h_es() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (good)' as 'h_es'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' + select 'Inner (bad)' as 'h_es'; +insert into t3 values (1); +end; +end| +create procedure h_en() +deterministic +begin +declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA +select 'Outer (good)' as 'h_en'; +begin +declare x int; +declare continue handler for sqlstate '02000' -- no data +select 'Inner (bad)' as 'h_en'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_ew() +deterministic +begin +declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE +select 'Outer (good)' as 'h_ew'; +begin +declare continue handler for sqlwarning +select 'Inner (bad)' as 'h_ew'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ex() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (good)' as 'h_ex'; +begin +declare continue handler for sqlexception +select 'Inner (bad)' as 'h_ex'; +insert into t3 values (1); +end; +end| +create procedure h_se() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_se'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_se'; +insert into t3 values (1); +end; +end| +create procedure h_ss() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_ss'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Inner (good)' as 'h_ss'; +insert into t3 values (1); +end; +end| +create procedure h_sn() +deterministic +begin +-- Note: '02000' is more specific than NOT FOUND ; +-- there might be other not found states +declare continue handler for sqlstate '02000' -- no data +select 'Outer (good)' as 'h_sn'; +begin +declare x int; +declare continue handler for not found +select 'Inner (bad)' as 'h_sn'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_sw() +deterministic +begin +-- data exception - numeric value out of range +declare continue handler for sqlstate '22003' + select 'Outer (good)' as 'h_sw'; +begin +declare continue handler for sqlwarning +select 'Inner (bad)' as 'h_sw'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_sx() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (good)' as 'h_sx'; +begin +declare continue handler for sqlexception +select 'Inner (bad)' as 'h_sx'; +insert into t3 values (1); +end; +end| +create procedure h_ne() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_ne'; +begin +declare x int; +declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA +select 'Inner (good)' as 'h_ne'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_ns() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_ns'; +begin +declare x int; +declare continue handler for sqlstate '02000' -- no data +select 'Inner (good)' as 'h_ns'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_nn() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_nn'; +begin +declare x int; +declare continue handler for not found +select 'Inner (good)' as 'h_nn'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_we() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_we'; +begin +declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE +select 'Inner (good)' as 'h_we'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ws() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_ws'; +begin +-- data exception - numeric value out of range +declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ww() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_ww'; +begin +declare continue handler for sqlwarning +select 'Inner (good)' as 'h_ww'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_xe() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xe'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_xe'; +insert into t3 values (1); +end; +end| +create procedure h_xs() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xs'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; +insert into t3 values (1); +end; +end| +create procedure h_xx() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xx'; +begin +declare continue handler for sqlexception +select 'Inner (good)' as 'h_xx'; +insert into t3 values (1); +end; +end| +call h_ee()| +h_ee +Inner (good) +call h_es()| +h_es +Outer (good) +call h_en()| +h_en +Outer (good) +call h_ew()| +h_ew +Outer (good) +call h_ex()| +h_ex +Outer (good) +call h_se()| +h_se +Inner (good) +call h_ss()| +h_ss +Inner (good) +call h_sn()| +h_sn +Outer (good) +call h_sw()| +h_sw +Outer (good) +call h_sx()| +h_sx +Outer (good) +call h_ne()| +h_ne +Inner (good) +call h_ns()| +h_ns +Inner (good) +call h_nn()| +h_nn +Inner (good) +call h_we()| +h_we +Inner (good) +call h_ws()| +h_ws +Inner (good) +call h_ww()| +h_ww +Inner (good) +call h_xe()| +h_xe +Inner (good) +call h_xs()| +h_xs +Inner (good) +call h_xx()| +h_xx +Inner (good) +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| drop procedure if exists bug822| create procedure bug822(a_id char(16), a_data int) begin @@ -2170,7 +2501,7 @@ Create view Tables To create new views Create user Server Admin To create new users Delete Tables To delete existing rows Drop Databases,Tables To drop databases, tables, and views -Event Server Admin Creation, alteration, deletion and execution of events. +Event Server Admin To create, alter, drop and execute events Execute Functions,Procedures To execute stored routines File File access on server To read and write files on the server Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess @@ -2224,7 +2555,7 @@ Create view Tables To create new views Create user Server Admin To create new users Delete Tables To delete existing rows Drop Databases,Tables To drop databases, tables, and views -Event Server Admin Creation, alteration, deletion and execution of events. +Event Server Admin To create, alter, drop and execute events Execute Functions,Procedures To execute stored routines File File access on server To read and write files on the server Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess @@ -4447,4 +4778,23 @@ Handler Inner drop procedure bug15011| drop table t3| +drop procedure if exists bug17476| +create table t3 ( d date )| +insert into t3 values +( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ), +( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )| +create procedure bug17476(pDateFormat varchar(10)) +select date_format(t3.d, pDateFormat), count(*) +from t3 +group by date_format(t3.d, pDateFormat)| +call bug17476('%Y-%m')| +date_format(t3.d, pDateFormat) count(*) +2005-01 4 +2005-02 2 +call bug17476('%Y-%m')| +date_format(t3.d, pDateFormat) count(*) +2005-01 4 +2005-02 2 +drop table t3| +drop procedure bug17476| drop table t1,t2; diff --git a/mysql-test/r/sp.result.orig b/mysql-test/r/sp.result.orig new file mode 100644 index 00000000000..663204681f2 --- /dev/null +++ b/mysql-test/r/sp.result.orig @@ -0,0 +1,4853 @@ +use test; +drop table if exists t1,t2,t3,t4; +create table t1 ( +id char(16) not null default '', +data int not null +); +create table t2 ( +s char(16), +i int, +d double +); +drop procedure if exists foo42; +create procedure foo42() +insert into test.t1 values ("foo", 42); +call foo42(); +select * from t1; +id data +foo 42 +delete from t1; +drop procedure foo42; +drop procedure if exists bar; +create procedure bar(x char(16), y int) +insert into test.t1 values (x, y); +call bar("bar", 666); +select * from t1; +id data +bar 666 +delete from t1; +drop procedure if exists empty| +create procedure empty() +begin +end| +call empty()| +drop procedure empty| +drop procedure if exists scope| +create procedure scope(a int, b float) +begin +declare b int; +declare c float; +begin +declare c int; +end; +end| +drop procedure scope| +drop procedure if exists two| +create procedure two(x1 char(16), x2 char(16), y int) +begin +insert into test.t1 values (x1, y); +insert into test.t1 values (x2, y); +end| +call two("one", "two", 3)| +select * from t1| +id data +one 3 +two 3 +delete from t1| +drop procedure two| +drop procedure if exists locset| +create procedure locset(x char(16), y int) +begin +declare z1, z2 int; +set z1 = y; +set z2 = z1+2; +insert into test.t1 values (x, z2); +end| +call locset("locset", 19)| +select * from t1| +id data +locset 21 +delete from t1| +drop procedure locset| +drop procedure if exists setcontext| +create procedure setcontext() +begin +declare data int default 2; +insert into t1 (id, data) values ("foo", 1); +replace t1 set data = data, id = "bar"; +update t1 set id = "kaka", data = 3 where t1.data = data; +end| +call setcontext()| +select * from t1| +id data +foo 1 +kaka 3 +delete from t1| +drop procedure setcontext| +create table t3 ( d date, i int, f double, s varchar(32) )| +drop procedure if exists nullset| +create procedure nullset() +begin +declare ld date; +declare li int; +declare lf double; +declare ls varchar(32); +set ld = null, li = null, lf = null, ls = null; +insert into t3 values (ld, li, lf, ls); +insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), +((li is null), 1, "li is null"), +((li = 0), null, "li = 0"), +((lf is null), 1, "lf is null"), +((lf = 0), null, "lf = 0"), +((ls is null), 1, "ls is null"); +end| +call nullset()| +select * from t3| +d i f s +NULL NULL NULL NULL +NULL 1 1 ld is null +NULL 1 1 li is null +NULL NULL NULL li = 0 +NULL 1 1 lf is null +NULL NULL NULL lf = 0 +NULL 1 1 ls is null +drop table t3| +drop procedure nullset| +drop procedure if exists mixset| +create procedure mixset(x char(16), y int) +begin +declare z int; +set @z = y, z = 666, max_join_size = 100; +insert into test.t1 values (x, z); +end| +call mixset("mixset", 19)| +show variables like 'max_join_size'| +Variable_name Value +max_join_size 100 +select id,data,@z from t1| +id data @z +mixset 666 19 +delete from t1| +drop procedure mixset| +drop procedure if exists zip| +create procedure zip(x char(16), y int) +begin +declare z int; +call zap(y, z); +call bar(x, z); +end| +drop procedure if exists zap| +create procedure zap(x int, out y int) +begin +declare z int; +set z = x+1, y = z; +end| +call zip("zip", 99)| +select * from t1| +id data +zip 100 +delete from t1| +drop procedure zip| +drop procedure bar| +call zap(7, @zap)| +select @zap| +@zap +8 +drop procedure zap| +drop procedure if exists c1| +create procedure c1(x int) +call c2("c", x)| +drop procedure if exists c2| +create procedure c2(s char(16), x int) +call c3(x, s)| +drop procedure if exists c3| +create procedure c3(x int, s char(16)) +call c4("level", x, s)| +drop procedure if exists c4| +create procedure c4(l char(8), x int, s char(16)) +insert into t1 values (concat(l,s), x)| +call c1(42)| +select * from t1| +id data +levelc 42 +delete from t1| +drop procedure c1| +drop procedure c2| +drop procedure c3| +drop procedure c4| +drop procedure if exists iotest| +create procedure iotest(x1 char(16), x2 char(16), y int) +begin +call inc2(x2, y); +insert into test.t1 values (x1, y); +end| +drop procedure if exists inc2| +create procedure inc2(x char(16), y int) +begin +call inc(y); +insert into test.t1 values (x, y); +end| +drop procedure if exists inc| +create procedure inc(inout io int) +set io = io + 1| +call iotest("io1", "io2", 1)| +select * from t1| +id data +io2 2 +io1 1 +delete from t1| +drop procedure iotest| +drop procedure inc2| +drop procedure if exists incr| +create procedure incr(inout x int) +call inc(x)| +select @zap| +@zap +8 +call incr(@zap)| +select @zap| +@zap +9 +drop procedure inc| +drop procedure incr| +drop procedure if exists cbv1| +create procedure cbv1() +begin +declare y int default 3; +call cbv2(y+1, y); +insert into test.t1 values ("cbv1", y); +end| +drop procedure if exists cbv2| +create procedure cbv2(y1 int, inout y2 int) +begin +set y2 = 4711; +insert into test.t1 values ("cbv2", y1); +end| +call cbv1()| +select * from t1| +id data +cbv2 4 +cbv1 4711 +delete from t1| +drop procedure cbv1| +drop procedure cbv2| +insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| +drop procedure if exists sub1| +create procedure sub1(id char(16), x int) +insert into test.t1 values (id, x)| +drop procedure if exists sub2| +create procedure sub2(id char(16)) +begin +declare x int; +set x = (select sum(t.i) from test.t2 t); +insert into test.t1 values (id, x); +end| +drop procedure if exists sub3| +create function sub3(i int) returns int +return i+1| +call sub1("sub1a", (select 7))| +call sub1("sub1b", (select max(i) from t2))| +call sub1("sub1c", (select i,d from t2 limit 1))| +ERROR 21000: Operand should contain 1 column(s) +call sub1("sub1d", (select 1 from (select 1) a))| +call sub2("sub2")| +select * from t1| +id data +sub1a 7 +sub1b 3 +sub1d 1 +sub2 6 +select sub3((select max(i) from t2))| +sub3((select max(i) from t2)) +4 +drop procedure sub1| +drop procedure sub2| +drop function sub3| +delete from t1| +delete from t2| +drop procedure if exists a0| +create procedure a0(x int) +while x do +set x = x-1; +insert into test.t1 values ("a0", x); +end while| +call a0(3)| +select * from t1| +id data +a0 2 +a0 1 +a0 0 +delete from t1| +drop procedure a0| +drop procedure if exists a| +create procedure a(x int) +while x > 0 do +set x = x-1; +insert into test.t1 values ("a", x); +end while| +call a(3)| +select * from t1| +id data +a 2 +a 1 +a 0 +delete from t1| +drop procedure a| +drop procedure if exists b| +create procedure b(x int) +repeat +insert into test.t1 values (repeat("b",3), x); +set x = x-1; +until x = 0 end repeat| +call b(3)| +select * from t1| +id data +bbb 3 +bbb 2 +bbb 1 +delete from t1| +drop procedure b| +drop procedure if exists b2| +create procedure b2(x int) +repeat(select 1 into outfile 'b2'); +insert into test.t1 values (repeat("b2",3), x); +set x = x-1; +until x = 0 end repeat| +drop procedure b2| +drop procedure if exists c| +create procedure c(x int) +hmm: while x > 0 do +insert into test.t1 values ("c", x); +set x = x-1; +iterate hmm; +insert into test.t1 values ("x", x); +end while hmm| +call c(3)| +select * from t1| +id data +c 3 +c 2 +c 1 +delete from t1| +drop procedure c| +drop procedure if exists d| +create procedure d(x int) +hmm: while x > 0 do +insert into test.t1 values ("d", x); +set x = x-1; +leave hmm; +insert into test.t1 values ("x", x); +end while| +call d(3)| +select * from t1| +id data +d 3 +delete from t1| +drop procedure d| +drop procedure if exists e| +create procedure e(x int) +foo: loop +if x = 0 then +leave foo; +end if; +insert into test.t1 values ("e", x); +set x = x-1; +end loop foo| +call e(3)| +select * from t1| +id data +e 3 +e 2 +e 1 +delete from t1| +drop procedure e| +drop procedure if exists f| +create procedure f(x int) +if x < 0 then +insert into test.t1 values ("f", 0); +elseif x = 0 then +insert into test.t1 values ("f", 1); +else +insert into test.t1 values ("f", 2); +end if| +call f(-2)| +call f(0)| +call f(4)| +select * from t1| +id data +f 0 +f 1 +f 2 +delete from t1| +drop procedure f| +drop procedure if exists g| +create procedure g(x int) +case +when x < 0 then +insert into test.t1 values ("g", 0); +when x = 0 then +insert into test.t1 values ("g", 1); +else +insert into test.t1 values ("g", 2); +end case| +call g(-42)| +call g(0)| +call g(1)| +select * from t1| +id data +g 0 +g 1 +g 2 +delete from t1| +drop procedure g| +drop procedure if exists h| +create procedure h(x int) +case x +when 0 then +insert into test.t1 values ("h0", x); +when 1 then +insert into test.t1 values ("h1", x); +else +insert into test.t1 values ("h?", x); +end case| +call h(0)| +call h(1)| +call h(17)| +select * from t1| +id data +h0 0 +h1 1 +h? 17 +delete from t1| +drop procedure h| +drop procedure if exists i| +create procedure i(x int) +foo: +begin +if x = 0 then +leave foo; +end if; +insert into test.t1 values ("i", x); +end foo| +call i(0)| +call i(3)| +select * from t1| +id data +i 3 +delete from t1| +drop procedure i| +insert into t1 values ("foo", 3), ("bar", 19)| +insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| +drop procedure if exists sel1| +create procedure sel1() +begin +select * from t1; +end| +call sel1()| +id data +foo 3 +bar 19 +drop procedure sel1| +drop procedure if exists sel2| +create procedure sel2() +begin +select * from t1; +select * from t2; +end| +call sel2()| +id data +foo 3 +bar 19 +s i d +x 9 4.1 +y -1 19.2 +z 3 2.2 +drop procedure sel2| +delete from t1| +delete from t2| +drop procedure if exists into_test| +create procedure into_test(x char(16), y int) +begin +insert into test.t1 values (x, y); +select id,data into x,y from test.t1 limit 1; +insert into test.t1 values (concat(x, "2"), y+2); +end| +call into_test("into", 100)| +select * from t1| +id data +into 100 +into2 102 +delete from t1| +drop procedure into_test| +drop procedure if exists into_tes2| +create procedure into_test2(x char(16), y int) +begin +insert into test.t1 values (x, y); +select id,data into x,@z from test.t1 limit 1; +insert into test.t1 values (concat(x, "2"), y+2); +end| +call into_test2("into", 100)| +select id,data,@z from t1| +id data @z +into 100 100 +into2 102 100 +delete from t1| +drop procedure into_test2| +drop procedure if exists into_test3| +create procedure into_test3() +begin +declare x char(16); +declare y int; +select * into x,y from test.t1 limit 1; +insert into test.t2 values (x, y, 0.0); +end| +insert into t1 values ("into3", 19)| +call into_test3()| +call into_test3()| +select * from t2| +s i d +into3 19 0 +into3 19 0 +delete from t1| +delete from t2| +drop procedure into_test3| +drop procedure if exists into_test4| +create procedure into_test4() +begin +declare x int; +select data into x from test.t1 limit 1; +insert into test.t3 values ("into4", x); +end| +delete from t1| +create table t3 ( s char(16), d int)| +call into_test4()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +select * from t3| +s d +into4 NULL +insert into t1 values ("i4", 77)| +call into_test4()| +select * from t3| +s d +into4 NULL +into4 77 +delete from t1| +drop table t3| +drop procedure into_test4| +drop procedure if exists into_outfile| +create procedure into_outfile(x char(16), y int) +begin +insert into test.t1 values (x, y); +select * into outfile "../tmp/spout" from test.t1; +insert into test.t1 values (concat(x, "2"), y+2); +end| +call into_outfile("ofile", 1)| +delete from t1| +drop procedure into_outfile| +drop procedure if exists into_dumpfile| +create procedure into_dumpfile(x char(16), y int) +begin +insert into test.t1 values (x, y); +select * into dumpfile "../tmp/spdump" from test.t1 limit 1; +insert into test.t1 values (concat(x, "2"), y+2); +end| +call into_dumpfile("dfile", 1)| +delete from t1| +drop procedure into_dumpfile| +drop procedure if exists create_select| +create procedure create_select(x char(16), y int) +begin +insert into test.t1 values (x, y); +create temporary table test.t3 select * from test.t1; +insert into test.t3 values (concat(x, "2"), y+2); +end| +call create_select("cs", 90)| +select * from t1, t3| +id data id data +cs 90 cs 90 +cs 90 cs2 92 +drop table t3| +delete from t1| +drop procedure create_select| +drop function if exists e| +create function e() returns double +return 2.7182818284590452354| +set @e = e()| +select e(), @e| +e() @e +2.718281828459 2.718281828459 +drop function if exists inc| +create function inc(i int) returns int +return i+1| +select inc(1), inc(99), inc(-71)| +inc(1) inc(99) inc(-71) +2 100 -70 +drop function if exists mul| +create function mul(x int, y int) returns int +return x*y| +select mul(1,1), mul(3,5), mul(4711, 666)| +mul(1,1) mul(3,5) mul(4711, 666) +1 15 3137526 +drop function if exists append| +create function append(s1 char(8), s2 char(8)) returns char(16) +return concat(s1, s2)| +select append("foo", "bar")| +append("foo", "bar") +foobar +drop function if exists fac| +create function fac(n int unsigned) returns bigint unsigned +begin +declare f bigint unsigned default 1; +while n > 1 do +set f = f * n; +set n = n - 1; +end while; +return f; +end| +select fac(1), fac(2), fac(5), fac(10)| +fac(1) fac(2) fac(5) fac(10) +1 2 120 3628800 +drop function if exists fun| +create function fun(d double, i int, u int unsigned) returns double +return mul(inc(i), fac(u)) / e()| +select fun(2.3, 3, 5)| +fun(2.3, 3, 5) +176.58213176229 +insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| +insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| +select * from t2 where s = append("a", "b")| +s i d +ab 24 1324.36598821719 +select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2)| +s i d +xxxyyy 12 2.71828182845905 +ab 24 1324.36598821719 +select * from t2 where d = e()| +s i d +xxxyyy 12 2.71828182845905 +select * from t2| +s i d +xxxyyy 12 2.71828182845905 +ab 24 1324.36598821719 +delete from t2| +drop function e| +drop function inc| +drop function mul| +drop function append| +drop function fun| +drop procedure if exists hndlr1| +create procedure hndlr1(val int) +begin +declare x int default 0; +declare foo condition for 1136; +declare bar condition for sqlstate '42S98'; # Just for testing syntax +declare zip condition for sqlstate value '42S99'; # Just for testing syntax +declare continue handler for foo set x = 1; +insert into test.t1 values ("hndlr1", val, 2); # Too many values +if (x) then +insert into test.t1 values ("hndlr1", val); # This instead then +end if; +end| +call hndlr1(42)| +select * from t1| +id data +hndlr1 42 +delete from t1| +drop procedure hndlr1| +drop procedure if exists hndlr2| +create procedure hndlr2(val int) +begin +declare x int default 0; +begin +declare exit handler for sqlstate '21S01' set x = 1; +insert into test.t1 values ("hndlr2", val, 2); # Too many values +end; +insert into test.t1 values ("hndlr2", x); +end| +call hndlr2(42)| +select * from t1| +id data +hndlr2 1 +delete from t1| +drop procedure hndlr2| +drop procedure if exists hndlr3| +create procedure hndlr3(val int) +begin +declare x int default 0; +declare continue handler for sqlexception # Any error +begin +declare z int; +set z = 2 * val; +set x = 1; +end; +if val < 10 then +begin +declare y int; +set y = val + 10; +insert into test.t1 values ("hndlr3", y, 2); # Too many values +if x then +insert into test.t1 values ("hndlr3", y); +end if; +end; +end if; +end| +call hndlr3(3)| +select * from t1| +id data +hndlr3 13 +delete from t1| +drop procedure hndlr3| +create table t3 ( id char(16), data int )| +drop procedure if exists hndlr4| +create procedure hndlr4() +begin +declare x int default 0; +declare val int; # No default +declare continue handler for sqlstate '02000' set x=1; +select data into val from test.t3 where id='z' limit 1; # No hits +insert into test.t3 values ('z', val); +end| +call hndlr4()| +select * from t3| +id data +z NULL +drop table t3| +drop procedure hndlr4| +drop procedure if exists cur1| +create procedure cur1() +begin +declare a char(16); +declare b int; +declare c double; +declare done int default 0; +declare c cursor for select * from test.t2; +declare continue handler for sqlstate '02000' set done = 1; +open c; +repeat +fetch c into a, b, c; +if not done then +insert into test.t1 values (a, b+c); +end if; +until done end repeat; +close c; +end| +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| +call cur1()| +select * from t1| +id data +foo 40 +bar 15 +zap 663 +drop procedure cur1| +create table t3 ( s char(16), i int )| +drop procedure if exists cur2| +create procedure cur2() +begin +declare done int default 0; +declare c1 cursor for select id,data from test.t1; +declare c2 cursor for select i from test.t2; +declare continue handler for sqlstate '02000' set done = 1; +open c1; +open c2; +repeat +begin +declare a char(16); +declare b,c int; +fetch from c1 into a, b; +fetch next from c2 into c; +if not done then +if b < c then +insert into test.t3 values (a, b); +else +insert into test.t3 values (a, c); +end if; +end if; +end; +until done end repeat; +close c1; +close c2; +end| +call cur2()| +select * from t3| +s i +foo 40 +bar 3 +zap 663 +delete from t1| +delete from t2| +drop table t3| +drop procedure cur2| +drop procedure if exists chistics| +create procedure chistics() +language sql +modifies sql data +not deterministic +sql security definer +comment 'Characteristics procedure test' + insert into t1 values ("chistics", 1)| +show create procedure chistics| +Procedure sql_mode Create Procedure +chistics CREATE PROCEDURE `chistics`() + MODIFIES SQL DATA + COMMENT 'Characteristics procedure test' +insert into t1 values ("chistics", 1) +call chistics()| +select * from t1| +id data +chistics 1 +delete from t1| +alter procedure chistics sql security invoker| +show create procedure chistics| +Procedure sql_mode Create Procedure +chistics CREATE PROCEDURE `chistics`() + MODIFIES SQL DATA + SQL SECURITY INVOKER + COMMENT 'Characteristics procedure test' +insert into t1 values ("chistics", 1) +drop procedure chistics| +drop function if exists chistics| +create function chistics() returns int +language sql +deterministic +sql security invoker +comment 'Characteristics procedure test' + return 42| +show create function chistics| +Function sql_mode Create Function +chistics CREATE FUNCTION `chistics`() RETURNS int(11) + DETERMINISTIC + SQL SECURITY INVOKER + COMMENT 'Characteristics procedure test' +return 42 +select chistics()| +chistics() +42 +alter function chistics +no sql +comment 'Characteristics function test'| +show create function chistics| +Function sql_mode Create Function +chistics CREATE FUNCTION `chistics`() RETURNS int(11) + NO SQL + DETERMINISTIC + SQL SECURITY INVOKER + COMMENT 'Characteristics function test' +return 42 +drop function chistics| +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| +set @@sql_mode = 'ANSI'| +drop procedure if exists modes$ +create procedure modes(out c1 int, out c2 int) +begin +declare done int default 0; +declare x int; +declare c cursor for select data from t1; +declare continue handler for sqlstate '02000' set done = 1; +select 1 || 2 into c1; +set c2 = 0; +open c; +repeat +fetch c into x; +if not done then +set c2 = c2 + 1; +end if; +until done end repeat; +close c; +end$ +set @@sql_mode = ''| +set sql_select_limit = 1| +call modes(@c1, @c2)| +set sql_select_limit = default| +select @c1, @c2| +@c1 @c2 +12 3 +delete from t1| +drop procedure modes| +create database sp_db1| +drop database sp_db1| +create database sp_db2| +use sp_db2| +create table t3 ( s char(4), t int )| +insert into t3 values ("abcd", 42), ("dcba", 666)| +use test| +drop database sp_db2| +create database sp_db3| +use sp_db3| +drop procedure if exists dummy| +create procedure dummy(out x int) +set x = 42| +use test| +drop database sp_db3| +select type,db,name from mysql.proc where db = 'sp_db3'| +type db name +drop procedure if exists rc| +create procedure rc() +begin +delete from t1; +insert into t1 values ("a", 1), ("b", 2), ("c", 3); +end| +call rc()| +select row_count()| +row_count() +3 +update t1 set data=42 where id = "b"; +select row_count()| +row_count() +1 +delete from t1| +select row_count()| +row_count() +3 +delete from t1| +select row_count()| +row_count() +0 +select * from t1| +id data +select row_count()| +row_count() +-1 +drop procedure rc| +drop function if exists f0| +drop function if exists f1| +drop function if exists f2| +drop function if exists f3| +drop function if exists f4| +drop function if exists f5| +drop function if exists f6| +drop function if exists f7| +drop function if exists f8| +drop function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| +drop view if exists v0| +drop view if exists v1| +drop view if exists v2| +delete from t1| +delete from t2| +insert into t1 values ("a", 1), ("b", 2) | +insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | +create function f1() returns int +return (select sum(data) from t1)| +select f1()| +f1() +3 +select id, f1() from t1| +id f1() +a 3 +b 3 +create function f2() returns int +return (select data from t1 where data <= (select sum(data) from t1) limit 1)| +select f2()| +f2() +1 +select id, f2() from t1| +id f2() +a 1 +b 1 +create function f3() returns int +begin +declare n int; +declare m int; +set n:= (select min(data) from t1); +set m:= (select max(data) from t1); +return n < m; +end| +select f3()| +f3() +1 +select id, f3() from t1| +id f3() +a 1 +b 1 +select f1(), f3()| +f1() f3() +3 1 +select id, f1(), f3() from t1| +id f1() f3() +a 3 1 +b 3 1 +create function f4() returns double +return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| +select f4()| +f4() +2 +select s, f4() from t2| +s f4() +a 2 +b 2 +c 2 +create function f5(i int) returns int +begin +if i <= 0 then +return 0; +elseif i = 1 then +return (select count(*) from t1 where data = i); +else +return (select count(*) + f5( i - 1) from t1 where data = i); +end if; +end| +select f5(1)| +f5(1) +1 +select f5(2)| +ERROR HY000: Recursive stored functions and triggers are not allowed. +select f5(3)| +ERROR HY000: Recursive stored functions and triggers are not allowed. +create function f6() returns int +begin +declare n int; +set n:= f1(); +return (select count(*) from t1 where data <= f7() and data <= n); +end| +create function f7() returns int +return (select sum(data) from t1 where data <= f1())| +select f6()| +f6() +2 +select id, f6() from t1| +id f6() +a 2 +b 2 +create view v1 (a) as select f1()| +select * from v1| +a +3 +select id, a from t1, v1| +id a +a 3 +b 3 +select * from v1, v1 as v| +a a +3 3 +create view v2 (a) as select a*10 from v1| +select * from v2| +a +30 +select id, a from t1, v2| +id a +a 30 +b 30 +select * from v1, v2| +a a +3 30 +create function f8 () returns int +return (select count(*) from v2)| +select *, f8() from v1| +a f8() +3 1 +drop function f1| +select * from v1| +ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +create function f1() returns int +return (select sum(data) from t1) + (select sum(data) from v1)| +select f1()| +ERROR HY000: Recursive stored functions and triggers are not allowed. +select * from v1| +ERROR HY000: Recursive stored functions and triggers are not allowed. +select * from v2| +ERROR HY000: Recursive stored functions and triggers are not allowed. +drop function f1| +create function f1() returns int +return (select sum(data) from t1)| +create function f0() returns int +return (select * from (select 100) as r)| +select f0()| +f0() +100 +select *, f0() from (select 1) as t| +1 f0() +1 100 +create view v0 as select f0()| +select * from v0| +f0() +100 +select *, f0() from v0| +f0() f0() +100 100 +lock tables t1 read, t1 as t11 read| +select f3()| +f3() +1 +select id, f3() from t1 as t11| +id f3() +a 1 +b 1 +select f0()| +f0() +100 +select * from v0| +f0() +100 +select *, f0() from v0, (select 123) as d1| +f0() 123 f0() +100 123 100 +select id, f3() from t1| +ERROR HY000: Table 't1' was not locked with LOCK TABLES +select f4()| +ERROR HY000: Table 't2' was not locked with LOCK TABLES +unlock tables| +lock tables v2 read, mysql.proc read| +select * from v2| +a +30 +select * from v1| +a +3 +select * from v1, t1| +ERROR HY000: Table 't1' was not locked with LOCK TABLES +select f4()| +ERROR HY000: Table 't2' was not locked with LOCK TABLES +unlock tables| +create function f9() returns int +begin +declare a, b int; +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +set a:= (select count(*) from t3); +set b:= (select count(*) from t3 t3_alias); +return a + b; +end| +select f9()| +f9() +6 +Warnings: +Note 1051 Unknown table 't3' +select f9() from t1 limit 1| +f9() +6 +create function f10() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 select id from t4; +return (select count(*) from t3); +end| +select f10()| +ERROR 42S02: Table 'test.t4' doesn't exist +create table t4 as select 1 as id| +select f10()| +f10() +1 +create function f11() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +return (select count(*) from t3 as a, t3 as b); +end| +select f11()| +ERROR HY000: Can't reopen table: 'a' +select f11() from t1| +ERROR HY000: Can't reopen table: 'a' +create function f12_1() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +return f12_2(); +end| +create function f12_2() returns int +return (select count(*) from t3)| +drop temporary table t3| +select f12_1()| +ERROR 42S02: Table 'test.t3' doesn't exist +select f12_1() from t1 limit 1| +ERROR 42S02: Table 'test.t3' doesn't exist +drop function f0| +drop function f1| +drop function f2| +drop function f3| +drop function f4| +drop function f5| +drop function f6| +drop function f7| +drop function f8| +drop function f9| +drop function f10| +drop function f11| +drop function f12_1| +drop function f12_2| +drop view v0| +drop view v1| +drop view v2| +delete from t1 | +delete from t2 | +drop table t4| +drop table if exists t3| +create table t3 (n int unsigned not null primary key, f bigint unsigned)| +drop procedure if exists ifac| +create procedure ifac(n int unsigned) +begin +declare i int unsigned default 1; +if n > 20 then +set n = 20; # bigint overflow otherwise +end if; +while i <= n do +begin +insert into test.t3 values (i, fac(i)); +set i = i + 1; +end; +end while; +end| +call ifac(20)| +select * from t3| +n f +1 1 +2 2 +3 6 +4 24 +5 120 +6 720 +7 5040 +8 40320 +9 362880 +10 3628800 +11 39916800 +12 479001600 +13 6227020800 +14 87178291200 +15 1307674368000 +16 20922789888000 +17 355687428096000 +18 6402373705728000 +19 121645100408832000 +20 2432902008176640000 +drop table t3| +show function status like '%f%'| +Db Name Type Definer Modified Created Security_type Comment +test fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +drop procedure ifac| +drop function fac| +show function status like '%f%'| +Db Name Type Definer Modified Created Security_type Comment +drop table if exists t3| +create table t3 ( +i int unsigned not null primary key, +p bigint unsigned not null +)| +insert into t3 values +( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), +( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), +(10, 37), (11, 41), (12, 43), (13, 47), (14, 53), +(15, 59), (16, 61), (17, 67), (18, 71), (19, 73), +(20, 79), (21, 83), (22, 89), (23, 97), (24, 101), +(25, 103), (26, 107), (27, 109), (28, 113), (29, 127), +(30, 131), (31, 137), (32, 139), (33, 149), (34, 151), +(35, 157), (36, 163), (37, 167), (38, 173), (39, 179), +(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| +drop procedure if exists opp| +create procedure opp(n bigint unsigned, out pp bool) +begin +declare r double; +declare b, s bigint unsigned default 0; +set r = sqrt(n); +again: +loop +if s = 45 then +set b = b+200, s = 0; +else +begin +declare p bigint unsigned; +select t.p into p from test.t3 t where t.i = s; +if b+p > r then +set pp = 1; +leave again; +end if; +if mod(n, b+p) = 0 then +set pp = 0; +leave again; +end if; +set s = s+1; +end; +end if; +end loop; +end| +drop procedure if exists ip| +create procedure ip(m int unsigned) +begin +declare p bigint unsigned; +declare i int unsigned; +set i=45, p=201; +while i < m do +begin +declare pp bool default 0; +call opp(p, pp); +if pp then +insert into test.t3 values (i, p); +set i = i+1; +end if; +set p = p+2; +end; +end while; +end| +show create procedure opp| +Procedure sql_mode Create Procedure +opp CREATE PROCEDURE `opp`(n bigint unsigned, out pp bool) +begin +declare r double; +declare b, s bigint unsigned default 0; +set r = sqrt(n); +again: +loop +if s = 45 then +set b = b+200, s = 0; +else +begin +declare p bigint unsigned; +select t.p into p from test.t3 t where t.i = s; +if b+p > r then +set pp = 1; +leave again; +end if; +if mod(n, b+p) = 0 then +set pp = 0; +leave again; +end if; +set s = s+1; +end; +end if; +end loop; +end +show procedure status like '%p%'| +Db Name Type Definer Modified Created Security_type Comment +test ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +call ip(200)| +select * from t3 where i=45 or i=100 or i=199| +i p +45 211 +100 557 +199 1229 +drop table t3| +drop procedure opp| +drop procedure ip| +show procedure status like '%p%'| +Db Name Type Definer Modified Created Security_type Comment +drop table if exists t3| +create table t3 ( f bigint unsigned not null )| +drop procedure if exists fib| +create procedure fib(n int unsigned) +begin +if n > 1 then +begin +declare x, y bigint unsigned; +declare c cursor for select f from t3 order by f desc limit 2; +open c; +fetch c into y; +fetch c into x; +close c; +insert into t3 values (x+y); +call fib(n-1); +end; +end if; +end| +set @@max_sp_recursion_depth= 20| +insert into t3 values (0), (1)| +call fib(3)| +select * from t3 order by f asc| +f +0 +1 +1 +2 +delete from t3| +insert into t3 values (0), (1)| +call fib(10)| +select * from t3 order by f asc| +f +0 +1 +1 +2 +3 +5 +8 +13 +21 +34 +55 +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| +drop procedure if exists bar| +create procedure bar(x char(16), y int) +comment "111111111111" sql security invoker +insert into test.t1 values (x, y)| +show procedure status like 'bar'| +Db Name Type Definer Modified Created Security_type Comment +test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER 111111111111 +alter procedure bar comment "2222222222" sql security definer| +alter procedure bar comment "3333333333"| +alter procedure bar| +show create procedure bar| +Procedure sql_mode Create Procedure +bar CREATE PROCEDURE `bar`(x char(16), y int) + COMMENT '3333333333' +insert into test.t1 values (x, y) +show procedure status like 'bar'| +Db Name Type Definer Modified Created Security_type Comment +test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 3333333333 +drop procedure bar| +drop procedure if exists p1| +create procedure p1 () +select (select s1 from t3) from t3| +create table t3 (s1 int)| +call p1()| +(select s1 from t3) +insert into t3 values (1)| +call p1()| +(select s1 from t3) +1 +drop procedure p1| +drop table t3| +drop function if exists foo| +create function `foo` () returns int +return 5| +select `foo` ()| +`foo` () +5 +drop function `foo`| +drop function if exists t1max| +create function t1max() returns int +begin +declare x int; +select max(data) into x from t1; +return x; +end| +insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| +select t1max()| +t1max() +5 +drop function t1max| +create table t3 ( +v char(16) not null primary key, +c int unsigned not null +)| +create function getcount(s char(16)) returns int +begin +declare x int; +select count(*) into x from t3 where v = s; +if x = 0 then +insert into t3 values (s, 1); +else +update t3 set c = c+1 where v = s; +end if; +return x; +end| +select * from t1 where data = getcount("bar")| +id data +zap 1 +select * from t3| +v c +bar 4 +select getcount("zip")| +getcount("zip") +0 +select getcount("zip")| +getcount("zip") +1 +select * from t3| +v c +bar 4 +zip 2 +select getcount(id) from t1 where data = 3| +getcount(id) +0 +select getcount(id) from t1 where data = 5| +getcount(id) +1 +select * from t3| +v c +bar 4 +zip 3 +foo 1 +drop table t3| +drop function getcount| +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +create table t3 (a smallint primary key)| +insert into t3 (a) values (1)| +create procedure h_ee() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (bad)' as 'h_ee'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_ee'; +insert into t3 values (1); +end; +end| +create procedure h_es() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (good)' as 'h_es'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' + select 'Inner (bad)' as 'h_es'; +insert into t3 values (1); +end; +end| +create procedure h_en() +deterministic +begin +declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA +select 'Outer (good)' as 'h_en'; +begin +declare x int; +declare continue handler for sqlstate '02000' -- no data +select 'Inner (bad)' as 'h_en'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_ew() +deterministic +begin +declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE +select 'Outer (good)' as 'h_ew'; +begin +declare continue handler for sqlwarning +select 'Inner (bad)' as 'h_ew'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ex() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (good)' as 'h_ex'; +begin +declare continue handler for sqlexception +select 'Inner (bad)' as 'h_ex'; +insert into t3 values (1); +end; +end| +create procedure h_se() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_se'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_se'; +insert into t3 values (1); +end; +end| +create procedure h_ss() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_ss'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Inner (good)' as 'h_ss'; +insert into t3 values (1); +end; +end| +create procedure h_sn() +deterministic +begin +-- Note: '02000' is more specific than NOT FOUND ; +-- there might be other not found states +declare continue handler for sqlstate '02000' -- no data +select 'Outer (good)' as 'h_sn'; +begin +declare x int; +declare continue handler for not found +select 'Inner (bad)' as 'h_sn'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_sw() +deterministic +begin +-- data exception - numeric value out of range +declare continue handler for sqlstate '22003' + select 'Outer (good)' as 'h_sw'; +begin +declare continue handler for sqlwarning +select 'Inner (bad)' as 'h_sw'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_sx() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (good)' as 'h_sx'; +begin +declare continue handler for sqlexception +select 'Inner (bad)' as 'h_sx'; +insert into t3 values (1); +end; +end| +create procedure h_ne() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_ne'; +begin +declare x int; +declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA +select 'Inner (good)' as 'h_ne'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_ns() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_ns'; +begin +declare x int; +declare continue handler for sqlstate '02000' -- no data +select 'Inner (good)' as 'h_ns'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_nn() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_nn'; +begin +declare x int; +declare continue handler for not found +select 'Inner (good)' as 'h_nn'; +select a into x from t3 where a = 42; +end; +end| +create procedure h_we() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_we'; +begin +declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE +select 'Inner (good)' as 'h_we'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ws() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_ws'; +begin +-- data exception - numeric value out of range +declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ww() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_ww'; +begin +declare continue handler for sqlwarning +select 'Inner (good)' as 'h_ww'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_xe() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xe'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_xe'; +insert into t3 values (1); +end; +end| +create procedure h_xs() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xs'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; +insert into t3 values (1); +end; +end| +create procedure h_xx() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xx'; +begin +declare continue handler for sqlexception +select 'Inner (good)' as 'h_xx'; +insert into t3 values (1); +end; +end| +call h_ee()| +h_ee +Inner (good) +call h_es()| +h_es +Outer (good) +call h_en()| +h_en +Outer (good) +call h_ew()| +h_ew +Outer (good) +call h_ex()| +h_ex +Outer (good) +call h_se()| +h_se +Inner (good) +call h_ss()| +h_ss +Inner (good) +call h_sn()| +h_sn +Outer (good) +call h_sw()| +h_sw +Outer (good) +call h_sx()| +h_sx +Outer (good) +call h_ne()| +h_ne +Inner (good) +call h_ns()| +h_ns +Inner (good) +call h_nn()| +h_nn +Inner (good) +call h_we()| +h_we +Inner (good) +call h_ws()| +h_ws +Inner (good) +call h_ww()| +h_ww +Inner (good) +call h_xe()| +h_xe +Inner (good) +call h_xs()| +h_xs +Inner (good) +call h_xx()| +h_xx +Inner (good) +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| +drop procedure if exists bug822| +create procedure bug822(a_id char(16), a_data int) +begin +declare n int; +select count(*) into n from t1 where id = a_id and data = a_data; +if n = 0 then +insert into t1 (id, data) values (a_id, a_data); +end if; +end| +delete from t1| +call bug822('foo', 42)| +call bug822('foo', 42)| +call bug822('bar', 666)| +select * from t1| +id data +foo 42 +bar 666 +delete from t1| +drop procedure bug822| +drop procedure if exists bug1495| +create procedure bug1495() +begin +declare x int; +select data into x from t1 order by id limit 1; +if x > 10 then +insert into t1 values ("less", x-10); +else +insert into t1 values ("more", x+10); +end if; +end| +insert into t1 values ('foo', 12)| +call bug1495()| +delete from t1 where id='foo'| +insert into t1 values ('bar', 7)| +call bug1495()| +delete from t1 where id='bar'| +select * from t1| +id data +less 2 +more 17 +delete from t1| +drop procedure bug1495| +drop procedure if exists bug1547| +create procedure bug1547(s char(16)) +begin +declare x int; +select data into x from t1 where s = id limit 1; +if x > 10 then +insert into t1 values ("less", x-10); +else +insert into t1 values ("more", x+10); +end if; +end| +insert into t1 values ("foo", 12), ("bar", 7)| +call bug1547("foo")| +call bug1547("bar")| +select * from t1| +id data +foo 12 +bar 7 +less 2 +more 17 +delete from t1| +drop procedure bug1547| +drop table if exists t70| +create table t70 (s1 int,s2 int)| +insert into t70 values (1,2)| +drop procedure if exists bug1656| +create procedure bug1656(out p1 int, out p2 int) +select * into p1, p1 from t70| +call bug1656(@1, @2)| +select @1, @2| +@1 @2 +2 NULL +drop table t70| +drop procedure bug1656| +create table t3(a int)| +drop procedure if exists bug1862| +create procedure bug1862() +begin +insert into t3 values(2); +flush tables; +end| +call bug1862()| +call bug1862()| +select * from t3| +a +2 +2 +drop table t3| +drop procedure bug1862| +drop procedure if exists bug1874| +create procedure bug1874() +begin +declare x int; +declare y double; +select max(data) into x from t1; +insert into t2 values ("max", x, 0); +select min(data) into x from t1; +insert into t2 values ("min", x, 0); +select sum(data) into x from t1; +insert into t2 values ("sum", x, 0); +select avg(data) into y from t1; +insert into t2 values ("avg", 0, y); +end| +insert into t1 (data) values (3), (1), (5), (9), (4)| +call bug1874()| +select * from t2| +s i d +max 9 0 +min 1 0 +sum 22 0 +avg 0 4.4 +delete from t1| +delete from t2| +drop procedure bug1874| +drop procedure if exists bug2260| +create procedure bug2260() +begin +declare v1 int; +declare c1 cursor for select data from t1; +declare continue handler for not found set @x2 = 1; +open c1; +fetch c1 into v1; +set @x2 = 2; +close c1; +end| +call bug2260()| +select @x2| +@x2 +2 +drop procedure bug2260| +drop procedure if exists bug2267_1| +create procedure bug2267_1() +begin +show procedure status; +end| +drop procedure if exists bug2267_2| +create procedure bug2267_2() +begin +show function status; +end| +drop procedure if exists bug2267_3| +create procedure bug2267_3() +begin +show create procedure bug2267_1; +end| +drop procedure if exists bug2267_4| +drop function if exists bug2267_4| +create procedure bug2267_4() +begin +show create function bug2267_4; +end| +create function bug2267_4() returns int return 100| +call bug2267_1()| +Db Name Type Definer Modified Created Security_type Comment +test bug2267_1 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +test bug2267_2 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +test bug2267_3 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +test bug2267_4 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +call bug2267_2()| +Db Name Type Definer Modified Created Security_type Comment +test bug2267_4 FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER +call bug2267_3()| +Procedure sql_mode Create Procedure +bug2267_1 CREATE PROCEDURE `bug2267_1`() +begin +show procedure status; +end +call bug2267_4()| +Function sql_mode Create Function +bug2267_4 CREATE FUNCTION `bug2267_4`() RETURNS int(11) +return 100 +drop procedure bug2267_1| +drop procedure bug2267_2| +drop procedure bug2267_3| +drop procedure bug2267_4| +drop function bug2267_4| +drop procedure if exists bug2227| +create procedure bug2227(x int) +begin +declare y float default 2.6; +declare z char(16) default "zzz"; +select 1.3, x, y, 42, z; +end| +call bug2227(9)| +1.3 x y 42 z +1.3 9 2.6 42 zzz +drop procedure bug2227| +drop procedure if exists bug2614| +create procedure bug2614() +begin +drop table if exists t3; +create table t3 (id int default '0' not null); +insert into t3 select 12; +insert into t3 select * from t3; +end| +call bug2614()| +call bug2614()| +drop table t3| +drop procedure bug2614| +drop function if exists bug2674| +create function bug2674() returns int +return @@sort_buffer_size| +set @osbs = @@sort_buffer_size| +set @@sort_buffer_size = 262000| +select bug2674()| +bug2674() +262000 +drop function bug2674| +set @@sort_buffer_size = @osbs| +drop procedure if exists bug3259_1 | +create procedure bug3259_1 () begin end| +drop procedure if exists BUG3259_2 | +create procedure BUG3259_2 () begin end| +drop procedure if exists Bug3259_3 | +create procedure Bug3259_3 () begin end| +call BUG3259_1()| +call BUG3259_1()| +call bug3259_2()| +call Bug3259_2()| +call bug3259_3()| +call bUG3259_3()| +drop procedure bUg3259_1| +drop procedure BuG3259_2| +drop procedure BUG3259_3| +drop function if exists bug2772| +create function bug2772() returns char(10) character set latin2 +return 'a'| +select bug2772()| +bug2772() +a +drop function bug2772| +drop procedure if exists bug2776_1| +create procedure bug2776_1(out x int) +begin +declare v int; +set v = default; +set x = v; +end| +drop procedure if exists bug2776_2| +create procedure bug2776_2(out x int) +begin +declare v int default 42; +set v = default; +set x = v; +end| +set @x = 1| +call bug2776_1(@x)| +select @x| +@x +NULL +call bug2776_2(@x)| +select @x| +@x +42 +drop procedure bug2776_1| +drop procedure bug2776_2| +create table t3 (s1 smallint)| +insert into t3 values (123456789012)| +Warnings: +Warning 1264 Out of range value adjusted for column 's1' at row 1 +drop procedure if exists bug2780| +create procedure bug2780() +begin +declare exit handler for sqlwarning set @x = 1; +set @x = 0; +insert into t3 values (123456789012); +insert into t3 values (0); +end| +call bug2780()| +select @x| +@x +1 +select * from t3| +s1 +32767 +32767 +drop procedure bug2780| +drop table t3| +create table t3 (content varchar(10) )| +insert into t3 values ("test1")| +insert into t3 values ("test2")| +create table t4 (f1 int, rc int, t3 int)| +drop procedure if exists bug1863| +create procedure bug1863(in1 int) +begin +declare ind int default 0; +declare t1 int; +declare t2 int; +declare t3 int; +declare rc int default 0; +declare continue handler for 1065 set rc = 1; +drop temporary table if exists temp_t1; +create temporary table temp_t1 ( +f1 int auto_increment, f2 varchar(20), primary key (f1) +); +insert into temp_t1 (f2) select content from t3; +select f2 into t3 from temp_t1 where f1 = 10; +if (rc) then +insert into t4 values (1, rc, t3); +end if; +insert into t4 values (2, rc, t3); +end| +call bug1863(10)| +Warnings: +Note 1051 Unknown table 'temp_t1' +Warning 1329 No data - zero rows fetched, selected, or processed +call bug1863(10)| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +select * from t4| +f1 rc t3 +2 0 NULL +2 0 NULL +drop procedure bug1863| +drop temporary table temp_t1; +drop table t3, t4| +create table t3 ( +OrderID int not null, +MarketID int, +primary key (OrderID) +)| +create table t4 ( +MarketID int not null, +Market varchar(60), +Status char(1), +primary key (MarketID) +)| +insert t3 (OrderID,MarketID) values (1,1)| +insert t3 (OrderID,MarketID) values (2,2)| +insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| +insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| +drop procedure if exists bug2656_1| +create procedure bug2656_1() +begin +select +m.Market +from t4 m JOIN t3 o +ON o.MarketID != 1 and o.MarketID = m.MarketID; +end | +drop procedure if exists bug2656_2| +create procedure bug2656_2() +begin +select +m.Market +from +t4 m, t3 o +where +m.MarketID != 1 and m.MarketID = o.MarketID; +end | +call bug2656_1()| +Market +MarketID Two +call bug2656_1()| +Market +MarketID Two +call bug2656_2()| +Market +MarketID Two +call bug2656_2()| +Market +MarketID Two +drop procedure bug2656_1| +drop procedure bug2656_2| +drop table t3, t4| +drop procedure if exists bug3426| +create procedure bug3426(in_time int unsigned, out x int) +begin +if in_time is null then +set @stamped_time=10; +set x=1; +else +set @stamped_time=in_time; +set x=2; +end if; +end| +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +2 01-01-1970 03:16:40 +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +1 01-01-1970 03:00:10 +alter procedure bug3426 sql security invoker| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +1 01-01-1970 03:00:10 +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +2 01-01-1970 03:16:40 +drop procedure bug3426| +create table t3 ( +a int primary key, +ach char(1) +) engine = innodb| +create table t4 ( +b int primary key , +bch char(1) +) engine = innodb| +insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')| +Warnings: +Warning 1265 Data truncated for column 'ach' at row 1 +Warning 1265 Data truncated for column 'ach' at row 2 +insert into t4 values (1 , 'bCh1' )| +Warnings: +Warning 1265 Data truncated for column 'bch' at row 1 +drop procedure if exists bug3448| +create procedure bug3448() +select * from t3 inner join t4 on t3.a = t4.b| +select * from t3 inner join t4 on t3.a = t4.b| +a ach b bch +1 a 1 b +call bug3448()| +a ach b bch +1 a 1 b +call bug3448()| +a ach b bch +1 a 1 b +drop procedure bug3448| +drop table t3, t4| +create table t3 ( +id int unsigned auto_increment not null primary key, +title VARCHAR(200), +body text, +fulltext (title,body) +)| +insert into t3 (title,body) values +('MySQL Tutorial','DBMS stands for DataBase ...'), +('How To Use MySQL Well','After you went through a ...'), +('Optimizing MySQL','In this tutorial we will show ...'), +('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), +('MySQL vs. YourSQL','In the following database comparison ...'), +('MySQL Security','When configured properly, MySQL ...')| +drop procedure if exists bug3734 | +create procedure bug3734 (param1 varchar(100)) +select * from t3 where match (title,body) against (param1)| +call bug3734('database')| +id title body +5 MySQL vs. YourSQL In the following database comparison ... +1 MySQL Tutorial DBMS stands for DataBase ... +call bug3734('Security')| +id title body +6 MySQL Security When configured properly, MySQL ... +drop procedure bug3734| +drop table t3| +drop procedure if exists bug3863| +create procedure bug3863() +begin +set @a = 0; +while @a < 5 do +set @a = @a + 1; +end while; +end| +call bug3863()| +select @a| +@a +5 +call bug3863()| +select @a| +@a +5 +drop procedure bug3863| +create table t3 ( +id int(10) unsigned not null default 0, +rid int(10) unsigned not null default 0, +msg text not null, +primary key (id), +unique key rid (rid, id) +)| +drop procedure if exists bug2460_1| +create procedure bug2460_1(in v int) +begin +( select n0.id from t3 as n0 where n0.id = v ) +union +( select n0.id from t3 as n0, t3 as n1 +where n0.id = n1.rid and n1.id = v ) +union +( select n0.id from t3 as n0, t3 as n1, t3 as n2 +where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ); +end| +call bug2460_1(2)| +id +call bug2460_1(2)| +id +insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| +call bug2460_1(2)| +id +2 +1 +call bug2460_1(2)| +id +2 +1 +drop procedure if exists bug2460_2| +create procedure bug2460_2() +begin +drop table if exists t3; +create temporary table t3 (s1 int); +insert into t3 select 1 union select 1; +end| +call bug2460_2()| +call bug2460_2()| +select * from t3| +s1 +1 +drop procedure bug2460_1| +drop procedure bug2460_2| +drop table t3| +set @@sql_mode = ''| +drop procedure if exists bug2564_1| +create procedure bug2564_1() +comment 'Joe''s procedure' + insert into `t1` values ("foo", 1)| +set @@sql_mode = 'ANSI_QUOTES'| +drop procedure if exists bug2564_2| +create procedure bug2564_2() +insert into "t1" values ('foo', 1)| +set @@sql_mode = ''$ +drop function if exists bug2564_3$ +create function bug2564_3(x int, y int) returns int +return x || y$ +set @@sql_mode = 'ANSI'$ +drop function if exists bug2564_4$ +create function bug2564_4(x int, y int) returns int +return x || y$ +set @@sql_mode = ''| +show create procedure bug2564_1| +Procedure sql_mode Create Procedure +bug2564_1 CREATE PROCEDURE `bug2564_1`() + COMMENT 'Joe''s procedure' +insert into `t1` values ("foo", 1) +show create procedure bug2564_2| +Procedure sql_mode Create Procedure +bug2564_2 ANSI_QUOTES CREATE PROCEDURE "bug2564_2"() +insert into "t1" values ('foo', 1) +show create function bug2564_3| +Function sql_mode Create Function +bug2564_3 CREATE FUNCTION `bug2564_3`(x int, y int) RETURNS int(11) +return x || y +show create function bug2564_4| +Function sql_mode Create Function +bug2564_4 REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI CREATE FUNCTION "bug2564_4"(x int, y int) RETURNS int(11) +return x || y +drop procedure bug2564_1| +drop procedure bug2564_2| +drop function bug2564_3| +drop function bug2564_4| +drop function if exists bug3132| +create function bug3132(s char(20)) returns char(50) +return concat('Hello, ', s, '!')| +select bug3132('Bob') union all select bug3132('Judy')| +bug3132('Bob') +Hello, Bob! +Hello, Judy! +drop function bug3132| +drop procedure if exists bug3843| +create procedure bug3843() +analyze table t1| +call bug3843()| +Table Op Msg_type Msg_text +test.t1 analyze status OK +call bug3843()| +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +select 1+2| +1+2 +3 +drop procedure bug3843| +create table t3 ( s1 char(10) )| +insert into t3 values ('a'), ('b')| +drop procedure if exists bug3368| +create procedure bug3368(v char(10)) +begin +select group_concat(v) from t3; +end| +call bug3368('x')| +group_concat(v) +x,x +call bug3368('yz')| +group_concat(v) +yz,yz +drop procedure bug3368| +drop table t3| +create table t3 (f1 int, f2 int)| +insert into t3 values (1,1)| +drop procedure if exists bug4579_1| +create procedure bug4579_1 () +begin +declare sf1 int; +select f1 into sf1 from t3 where f1=1 and f2=1; +update t3 set f2 = f2 + 1 where f1=1 and f2=1; +call bug4579_2(); +end| +drop procedure if exists bug4579_2| +create procedure bug4579_2 () +begin +end| +call bug4579_1()| +call bug4579_1()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call bug4579_1()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +drop procedure bug4579_1| +drop procedure bug4579_2| +drop table t3| +drop procedure if exists bug2773| +create function bug2773() returns int return null| +create table t3 as select bug2773()| +show create table t3| +Table Create Table +t3 CREATE TABLE `t3` ( + `bug2773()` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t3| +drop function bug2773| +drop procedure if exists bug3788| +create function bug3788() returns date return cast("2005-03-04" as date)| +select bug3788()| +bug3788() +2005-03-04 +drop function bug3788| +create function bug3788() returns binary(1) return 5| +select bug3788()| +bug3788() +5 +drop function bug3788| +create table t3 (f1 int, f2 int, f3 int)| +insert into t3 values (1,1,1)| +drop procedure if exists bug4726| +create procedure bug4726() +begin +declare tmp_o_id INT; +declare tmp_d_id INT default 1; +while tmp_d_id <= 2 do +begin +select f1 into tmp_o_id from t3 where f2=1 and f3=1; +set tmp_d_id = tmp_d_id + 1; +end; +end while; +end| +call bug4726()| +call bug4726()| +call bug4726()| +drop procedure bug4726| +drop table t3| +drop procedure if exists bug4902| +create procedure bug4902() +begin +show charset like 'foo'; +show collation like 'foo'; +show column types; +show create table t1; +show create database test; +show databases like 'foo'; +show errors; +show columns from t1; +show grants for 'root'@'localhost'; +show keys from t1; +show open tables like 'foo'; +show privileges; +show status like 'foo'; +show tables like 'foo'; +show variables like 'foo'; +show warnings; +end| +call bug4902()| +Charset Description Default collation Maxlen +Collation Charset Id Default Compiled Sortlen +Type Size Min_Value Max_Value Prec Scale Nullable Auto_Increment Unsigned Zerofill Searchable Case_Sensitive Default Comment +tinyint 1 -128 127 0 0 YES YES NO YES YES NO NULL,0 A very small integer +tinyint unsigned 1 0 255 0 0 YES YES YES YES YES NO NULL,0 A very small integer +Table Create Table +t1 CREATE TABLE `t1` ( + `id` char(16) NOT NULL default '', + `data` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +Database Create Database +test CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ +Database (foo) +Level Code Message +Field Type Null Key Default Extra +id char(16) NO +data int(11) NO +Grants for root@localhost +GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +Database Table In_use Name_locked +Privilege Context Comment +Alter Tables To alter the table +Alter routine Functions,Procedures To alter or drop stored functions/procedures +Create Databases,Tables,Indexes To create new databases and tables +Create routine Functions,Procedures To use CREATE FUNCTION/PROCEDURE +Create temporary tables Databases To use CREATE TEMPORARY TABLE +Create view Tables To create new views +Create user Server Admin To create new users +Delete Tables To delete existing rows +Drop Databases,Tables To drop databases, tables, and views +Execute Functions,Procedures To execute stored routines +File File access on server To read and write files on the server +Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess +Index Tables To create or drop indexes +Insert Tables To insert data into tables +Lock tables Databases To use LOCK TABLES (together with SELECT privilege) +Process Server Admin To view the plain text of currently executing queries +References Databases,Tables To have references on tables +Reload Server Admin To reload or refresh tables, logs and privileges +Replication client Server Admin To ask where the slave or master servers are +Replication slave Server Admin To read binary log events from the master +Select Tables To retrieve rows from table +Show databases Server Admin To see all databases with SHOW DATABASES +Show view Tables To see views with SHOW CREATE VIEW +Shutdown Server Admin To shut down the server +Super Server Admin To use KILL thread, SET GLOBAL, CHANGE MASTER, etc. +Update Tables To update existing rows +Usage Server Admin No privileges - allow connect only +Variable_name Value +Tables_in_test (foo) +Variable_name Value +Level Code Message +call bug4902()| +Charset Description Default collation Maxlen +Collation Charset Id Default Compiled Sortlen +Type Size Min_Value Max_Value Prec Scale Nullable Auto_Increment Unsigned Zerofill Searchable Case_Sensitive Default Comment +tinyint 1 -128 127 0 0 YES YES NO YES YES NO NULL,0 A very small integer +tinyint unsigned 1 0 255 0 0 YES YES YES YES YES NO NULL,0 A very small integer +Table Create Table +t1 CREATE TABLE `t1` ( + `id` char(16) NOT NULL default '', + `data` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +Database Create Database +test CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ +Database (foo) +Level Code Message +Field Type Null Key Default Extra +id char(16) NO +data int(11) NO +Grants for root@localhost +GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +Database Table In_use Name_locked +Privilege Context Comment +Alter Tables To alter the table +Alter routine Functions,Procedures To alter or drop stored functions/procedures +Create Databases,Tables,Indexes To create new databases and tables +Create routine Functions,Procedures To use CREATE FUNCTION/PROCEDURE +Create temporary tables Databases To use CREATE TEMPORARY TABLE +Create view Tables To create new views +Create user Server Admin To create new users +Delete Tables To delete existing rows +Drop Databases,Tables To drop databases, tables, and views +Execute Functions,Procedures To execute stored routines +File File access on server To read and write files on the server +Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess +Index Tables To create or drop indexes +Insert Tables To insert data into tables +Lock tables Databases To use LOCK TABLES (together with SELECT privilege) +Process Server Admin To view the plain text of currently executing queries +References Databases,Tables To have references on tables +Reload Server Admin To reload or refresh tables, logs and privileges +Replication client Server Admin To ask where the slave or master servers are +Replication slave Server Admin To read binary log events from the master +Select Tables To retrieve rows from table +Show databases Server Admin To see all databases with SHOW DATABASES +Show view Tables To see views with SHOW CREATE VIEW +Shutdown Server Admin To shut down the server +Super Server Admin To use KILL thread, SET GLOBAL, CHANGE MASTER, etc. +Update Tables To update existing rows +Usage Server Admin No privileges - allow connect only +Variable_name Value +Tables_in_test (foo) +Variable_name Value +Level Code Message +drop procedure bug4902| +drop procedure if exists bug4902_2| +create procedure bug4902_2() +begin +show processlist; +end| +call bug4902_2()| +Id User Host db Command Time State Info +# root localhost test Query # NULL show processlist +call bug4902_2()| +Id User Host db Command Time State Info +# root localhost test Query # NULL show processlist +drop procedure bug4902_2| +drop procedure if exists bug4904| +create procedure bug4904() +begin +declare continue handler for sqlstate 'HY000' begin end; +create table t2 as select * from t3; +end| +call bug4904()| +ERROR 42S02: Table 'test.t3' doesn't exist +drop procedure bug4904| +create table t3 (s1 char character set latin1, s2 char character set latin2)| +drop procedure if exists bug4904| +create procedure bug4904 () +begin +declare continue handler for sqlstate 'HY000' begin end; +select s1 from t3 union select s2 from t3; +end| +call bug4904()| +drop procedure bug4904| +drop table t3| +drop procedure if exists bug336| +create procedure bug336(out y int) +begin +declare x int; +set x = (select sum(t.data) from test.t1 t); +set y = x; +end| +insert into t1 values ("a", 2), ("b", 3)| +call bug336(@y)| +select @y| +@y +5 +delete from t1| +drop procedure bug336| +drop procedure if exists bug3157| +create procedure bug3157() +begin +if exists(select * from t1) then +set @n= @n + 1; +end if; +if (select count(*) from t1) then +set @n= @n + 1; +end if; +end| +set @n = 0| +insert into t1 values ("a", 1)| +call bug3157()| +select @n| +@n +2 +delete from t1| +drop procedure bug3157| +drop procedure if exists bug5251| +create procedure bug5251() +begin +end| +select created into @c1 from mysql.proc +where db='test' and name='bug5251'| +alter procedure bug5251 comment 'foobar'| +select count(*) from mysql.proc +where db='test' and name='bug5251' and created = @c1| +count(*) +1 +drop procedure bug5251| +drop procedure if exists bug5251| +create procedure bug5251() +checksum table t1| +call bug5251()| +Table Checksum +test.t1 0 +call bug5251()| +Table Checksum +test.t1 0 +drop procedure bug5251| +drop procedure if exists bug5287| +create procedure bug5287(param1 int) +label1: +begin +declare c cursor for select 5; +loop +if param1 >= 0 then +leave label1; +end if; +end loop; +end| +call bug5287(1)| +drop procedure bug5287| +drop procedure if exists bug5307| +create procedure bug5307() +begin +end; set @x = 3| +call bug5307()| +select @x| +@x +3 +drop procedure bug5307| +drop procedure if exists bug5258| +create procedure bug5258() +begin +end| +drop procedure if exists bug5258_aux| +create procedure bug5258_aux() +begin +declare c, m char(19); +select created,modified into c,m from mysql.proc where name = 'bug5258'; +if c = m then +select 'Ok'; +else +select c, m; +end if; +end| +call bug5258_aux()| +Ok +Ok +drop procedure bug5258| +drop procedure bug5258_aux| +drop function if exists bug4487| +create function bug4487() returns char +begin +declare v char; +return v; +end| +select bug4487()| +bug4487() +NULL +drop function bug4487| +drop procedure if exists bug4941| +drop procedure if exists bug4941| +create procedure bug4941(out x int) +begin +declare c cursor for select i from t2 limit 1; +open c; +fetch c into x; +close c; +end| +insert into t2 values (null, null, null)| +set @x = 42| +call bug4941(@x)| +select @x| +@x +NULL +delete from t1| +drop procedure bug4941| +drop procedure if exists bug3583| +drop procedure if exists bug3583| +create procedure bug3583() +begin +declare c int; +select * from t1; +select count(*) into c from t1; +select c; +end| +insert into t1 values ("x", 3), ("y", 5)| +set @x = @@query_cache_size| +set global query_cache_size = 10*1024*1024| +flush status| +flush query cache| +show status like 'Qcache_hits'| +Variable_name Value +Qcache_hits 0 +call bug3583()| +id data +x 3 +y 5 +c +2 +show status like 'Qcache_hits'| +Variable_name Value +Qcache_hits 0 +call bug3583()| +id data +x 3 +y 5 +c +2 +call bug3583()| +id data +x 3 +y 5 +c +2 +show status like 'Qcache_hits'| +Variable_name Value +Qcache_hits 2 +set global query_cache_size = @x| +flush status| +flush query cache| +delete from t1| +drop procedure bug3583| +drop procedure if exists bug4905| +create table t3 (s1 int,primary key (s1))| +drop procedure if exists bug4905| +create procedure bug4905() +begin +declare v int; +declare continue handler for sqlstate '23000' set v = 5; +insert into t3 values (1); +end| +call bug4905()| +select row_count()| +row_count() +1 +call bug4905()| +select row_count()| +row_count() +0 +call bug4905()| +select row_count()| +row_count() +0 +select * from t3| +s1 +1 +drop procedure bug4905| +drop table t3| +drop procedure if exists bug6029| +drop procedure if exists bug6029| +create procedure bug6029() +begin +declare exit handler for 1136 select '1136'; +declare exit handler for sqlstate '23000' select 'sqlstate 23000'; +declare continue handler for sqlexception select 'sqlexception'; +insert into t3 values (1); +insert into t3 values (1,2); +end| +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1)| +call bug6029()| +sqlstate 23000 +sqlstate 23000 +delete from t3| +call bug6029()| +1136 +1136 +drop procedure bug6029| +drop table t3| +drop procedure if exists bug8540| +create procedure bug8540() +begin +declare x int default 1; +select x as y, x+0 as z; +end| +call bug8540()| +y z +1 1 +drop procedure bug8540| +create table t3 (s1 int)| +drop procedure if exists bug6642| +create procedure bug6642() +select abs(count(s1)) from t3| +call bug6642()| +abs(count(s1)) +0 +call bug6642()| +abs(count(s1)) +0 +drop procedure bug6642| +insert into t3 values (0),(1)| +drop procedure if exists bug7013| +create procedure bug7013() +select s1,count(s1) from t3 group by s1 with rollup| +call bug7013()| +s1 count(s1) +0 1 +1 1 +NULL 2 +call bug7013()| +s1 count(s1) +0 1 +1 1 +NULL 2 +drop procedure bug7013| +drop table if exists t4| +create table t4 ( +a mediumint(8) unsigned not null auto_increment, +b smallint(5) unsigned not null, +c char(32) not null, +primary key (a) +) engine=myisam default charset=latin1| +insert into t4 values (1, 2, 'oneword')| +insert into t4 values (2, 2, 'anotherword')| +drop procedure if exists bug7743| +create procedure bug7743 ( searchstring char(28) ) +begin +declare var mediumint(8) unsigned; +select a into var from t4 where b = 2 and c = binary searchstring limit 1; +select var; +end| +call bug7743("oneword")| +var +1 +call bug7743("OneWord")| +var +NULL +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call bug7743("anotherword")| +var +2 +call bug7743("AnotherWord")| +var +NULL +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +drop procedure bug7743| +drop table t4| +delete from t3| +insert into t3 values(1)| +drop procedure if exists bug7992_1| +Warnings: +Note 1305 PROCEDURE bug7992_1 does not exist +drop procedure if exists bug7992_2| +Warnings: +Note 1305 PROCEDURE bug7992_2 does not exist +create procedure bug7992_1() +begin +declare i int; +select max(s1)+1 into i from t3; +end| +create procedure bug7992_2() +insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| +call bug7992_1()| +call bug7992_1()| +call bug7992_2()| +call bug7992_2()| +drop procedure bug7992_1| +drop procedure bug7992_2| +drop table t3| +create table t3 ( userid bigint(20) not null default 0 )| +drop procedure if exists bug8116| +create procedure bug8116(in _userid int) +select * from t3 where userid = _userid| +call bug8116(42)| +userid +call bug8116(42)| +userid +drop procedure bug8116| +drop table t3| +drop procedure if exists bug6857| +create procedure bug6857(counter int) +begin +declare t0, t1 int; +declare plus bool default 0; +set t0 = current_time(); +while counter > 0 do +set counter = counter - 1; +end while; +set t1 = current_time(); +if t1 > t0 then +set plus = 1; +end if; +select plus; +end| +drop procedure bug6857| +drop procedure if exists bug8757| +create procedure bug8757() +begin +declare x int; +declare c1 cursor for select data from t1 limit 1; +begin +declare y int; +declare c2 cursor for select i from t2 limit 1; +open c2; +fetch c2 into y; +close c2; +select 2,y; +end; +open c1; +fetch c1 into x; +close c1; +select 1,x; +end| +delete from t1| +delete from t2| +insert into t1 values ("x", 1)| +insert into t2 values ("y", 2, 0.0)| +call bug8757()| +2 y +2 2 +1 x +1 1 +delete from t1| +delete from t2| +drop procedure bug8757| +drop procedure if exists bug8762| +drop procedure if exists bug8762; create procedure bug8762() begin end| +drop procedure if exists bug8762; create procedure bug8762() begin end| +drop procedure bug8762| +drop function if exists bug5240| +create function bug5240 () returns int +begin +declare x int; +declare c cursor for select data from t1 limit 1; +open c; +fetch c into x; +close c; +return x; +end| +delete from t1| +insert into t1 values ("answer", 42)| +select id, bug5240() from t1| +id bug5240() +answer 42 +drop function bug5240| +drop function if exists bug5278| +create function bug5278 () returns char +begin +SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass'); +return 'okay'; +end| +select bug5278()| +ERROR 42000: Can't find any matching row in the user table +select bug5278()| +ERROR 42000: Can't find any matching row in the user table +drop function bug5278| +drop procedure if exists p1| +create table t3(id int)| +insert into t3 values(1)| +create procedure bug7992() +begin +declare i int; +select max(id)+1 into i from t3; +end| +call bug7992()| +call bug7992()| +drop procedure bug7992| +drop table t3| +create table t3 ( +lpitnumber int(11) default null, +lrecordtype int(11) default null +)| +create table t4 ( +lbsiid int(11) not null default '0', +ltradingmodeid int(11) not null default '0', +ltradingareaid int(11) not null default '0', +csellingprice decimal(19,4) default null, +primary key (lbsiid,ltradingmodeid,ltradingareaid) +)| +create table t5 ( +lbsiid int(11) not null default '0', +ltradingareaid int(11) not null default '0', +primary key (lbsiid,ltradingareaid) +)| +drop procedure if exists bug8849| +create procedure bug8849() +begin +insert into t5 +( +t5.lbsiid, +t5.ltradingareaid +) +select distinct t3.lpitnumber, t4.ltradingareaid +from +t4 join t3 on +t3.lpitnumber = t4.lbsiid +and t3.lrecordtype = 1 +left join t4 as price01 on +price01.lbsiid = t4.lbsiid and +price01.ltradingmodeid = 1 and +t4.ltradingareaid = price01.ltradingareaid; +end| +call bug8849()| +call bug8849()| +call bug8849()| +drop procedure bug8849| +drop tables t3,t4,t5| +drop procedure if exists bug8937| +create procedure bug8937() +begin +declare s,x,y,z int; +declare a float; +select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1; +select s,x,y,z; +select avg(data) into a from t1; +select a; +end| +delete from t1| +insert into t1 (data) values (1), (2), (3), (4), (6)| +call bug8937()| +s x y z +16 3 1 6 +a +3.2 +drop procedure bug8937| +delete from t1| +drop procedure if exists bug6900| +drop procedure if exists bug9074| +drop procedure if exists bug6900_9074| +create table t3 (w char unique, x char)| +insert into t3 values ('a', 'b')| +create procedure bug6900() +begin +declare exit handler for sqlexception select '1'; +begin +declare exit handler for sqlexception select '2'; +insert into t3 values ('x', 'y', 'z'); +end; +end| +create procedure bug9074() +begin +declare x1, x2, x3, x4, x5, x6 int default 0; +begin +declare continue handler for sqlstate '23000' set x5 = 1; +insert into t3 values ('a', 'b'); +set x6 = 1; +end; +begin1_label: +begin +declare continue handler for sqlstate '23000' set x1 = 1; +insert into t3 values ('a', 'b'); +set x2 = 1; +begin2_label: +begin +declare exit handler for sqlstate '23000' set x3 = 1; +set x4= 1; +insert into t3 values ('a','b'); +set x4= 0; +end begin2_label; +end begin1_label; +select x1, x2, x3, x4, x5, x6; +end| +create procedure bug6900_9074(z int) +begin +declare exit handler for sqlstate '23000' select '23000'; +begin +declare exit handler for sqlexception select 'sqlexception'; +if z = 1 then +insert into t3 values ('a', 'b'); +else +insert into t3 values ('x', 'y', 'z'); +end if; +end; +end| +call bug6900()| +2 +2 +call bug9074()| +x1 x2 x3 x4 x5 x6 +1 1 1 1 1 1 +call bug6900_9074(0)| +sqlexception +sqlexception +call bug6900_9074(1)| +23000 +23000 +drop procedure bug6900| +drop procedure bug9074| +drop procedure bug6900_9074| +drop table t3| +drop procedure if exists avg| +create procedure avg () +begin +end| +call avg ()| +drop procedure avg| +drop procedure if exists bug6129| +set @old_mode= @@sql_mode; +set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO"; +create procedure bug6129() +select @@sql_mode| +call bug6129()| +@@sql_mode +ERROR_FOR_DIVISION_BY_ZERO +set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"| +call bug6129()| +@@sql_mode +ERROR_FOR_DIVISION_BY_ZERO +set @@sql_mode= "NO_ZERO_IN_DATE"| +call bug6129()| +@@sql_mode +ERROR_FOR_DIVISION_BY_ZERO +set @@sql_mode=@old_mode; +drop procedure bug6129| +drop procedure if exists bug9856| +create procedure bug9856() +begin +declare v int; +declare c cursor for select data from t1; +declare exit handler for sqlexception, not found select '16'; +open c; +fetch c into v; +select v; +end| +delete from t1| +call bug9856()| +16 +16 +call bug9856()| +16 +16 +drop procedure bug9856| +drop procedure if exists bug9674_1| +drop procedure if exists bug9674_2| +create procedure bug9674_1(out arg int) +begin +declare temp_in1 int default 0; +declare temp_fl1 int default 0; +set temp_in1 = 100; +set temp_fl1 = temp_in1/10; +set arg = temp_fl1; +end| +create procedure bug9674_2() +begin +declare v int default 100; +select v/10; +end| +call bug9674_1(@sptmp)| +call bug9674_1(@sptmp)| +select @sptmp| +@sptmp +10 +call bug9674_2()| +v/10 +10.0000 +call bug9674_2()| +v/10 +10.0000 +drop procedure bug9674_1| +drop procedure bug9674_2| +drop procedure if exists bug9598_1| +drop procedure if exists bug9598_2| +create procedure bug9598_1(in var_1 char(16), +out var_2 integer, out var_3 integer) +begin +set var_2 = 50; +set var_3 = 60; +end| +create procedure bug9598_2(in v1 char(16), +in v2 integer, +in v3 integer, +in v4 integer, +in v5 integer) +begin +select v1,v2,v3,v4,v5; +call bug9598_1(v1,@tmp1,@tmp2); +select v1,v2,v3,v4,v5; +end| +call bug9598_2('Test',2,3,4,5)| +v1 v2 v3 v4 v5 +Test 2 3 4 5 +v1 v2 v3 v4 v5 +Test 2 3 4 5 +select @tmp1, @tmp2| +@tmp1 @tmp2 +50 60 +drop procedure bug9598_1| +drop procedure bug9598_2| +drop procedure if exists bug9902| +create function bug9902() returns int(11) +begin +set @x = @x + 1; +return @x; +end| +set @qcs1 = @@query_cache_size| +set global query_cache_size = 100000| +set @x = 1| +insert into t1 values ("qc", 42)| +select bug9902() from t1| +bug9902() +2 +select bug9902() from t1| +bug9902() +3 +select @x| +@x +3 +set global query_cache_size = @qcs1| +delete from t1| +drop function bug9902| +drop function if exists bug9102| +create function bug9102() returns blob return 'a'| +select bug9102()| +bug9102() +a +drop function bug9102| +drop function if exists bug7648| +create function bug7648() returns bit(8) return 'a'| +select bug7648()| +bug7648() +a +drop function bug7648| +drop function if exists bug9775| +create function bug9775(v1 char(1)) returns enum('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('c')| +bug9775('a') bug9775('b') bug9775('c') +a b +Warnings: +Warning 1265 Data truncated for column 'bug9775('c')' at row 1 +drop function bug9775| +create function bug9775(v1 int) returns enum('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3)| +bug9775(1) bug9775(2) bug9775(3) +a b +Warnings: +Warning 1265 Data truncated for column 'bug9775(3)' at row 1 +drop function bug9775| +create function bug9775(v1 char(1)) returns set('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| +bug9775('a') bug9775('b') bug9775('a,b') bug9775('c') +a b a +Warnings: +Warning 1265 Data truncated for column 'v1' at row 1 +Warning 1265 Data truncated for column 'bug9775('c')' at row 1 +drop function bug9775| +create function bug9775(v1 int) returns set('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| +bug9775(1) bug9775(2) bug9775(3) bug9775(4) +a b a,b +Warnings: +Warning 1265 Data truncated for column 'bug9775(4)' at row 1 +drop function bug9775| +drop function if exists bug8861| +create function bug8861(v1 int) returns year return v1| +select bug8861(05)| +bug8861(05) +2005 +set @x = bug8861(05)| +select @x| +@x +2005 +drop function bug8861| +drop procedure if exists bug9004_1| +drop procedure if exists bug9004_2| +create procedure bug9004_1(x char(16)) +begin +insert into t1 values (x, 42); +insert into t1 values (x, 17); +end| +create procedure bug9004_2(x char(16)) +call bug9004_1(x)| +call bug9004_1('12345678901234567')| +Warnings: +Warning 1265 Data truncated for column 'x' at row 1 +call bug9004_2('12345678901234567890')| +Warnings: +Warning 1265 Data truncated for column 'x' at row 1 +delete from t1| +drop procedure bug9004_1| +drop procedure bug9004_2| +drop procedure if exists bug7293| +insert into t1 values ('secret', 0)| +create procedure bug7293(p1 varchar(100)) +begin +if exists (select id from t1 where soundex(p1)=soundex(id)) then +select 'yes'; +end if; +end;| +call bug7293('secret')| +yes +yes +call bug7293 ('secrete')| +yes +yes +drop procedure bug7293| +delete from t1| +drop procedure if exists bug9841| +drop view if exists v1| +create view v1 as select * from t1, t2 where id = s| +create procedure bug9841 () +update v1 set data = 10| +call bug9841()| +drop view v1| +drop procedure bug9841| +drop procedure if exists bug5963| +create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| +create table t3 (s1 int)| +insert into t3 values (5)| +call bug5963_1()| +v +5 +call bug5963_1()| +v +5 +drop procedure bug5963_1| +drop table t3| +create procedure bug5963_2 (cfk_value int) +begin +if cfk_value in (select cpk from t3) then +set @x = 5; +end if; +end; +| +create table t3 (cpk int)| +insert into t3 values (1)| +call bug5963_2(1)| +call bug5963_2(1)| +drop procedure bug5963_2| +drop table t3| +drop function if exists bug9559| +create function bug9559() +returns int +begin +set @y = -6/2; +return @y; +end| +select bug9559()| +bug9559() +-3 +drop function bug9559| +drop procedure if exists bug10961| +create procedure bug10961() +begin +declare v char; +declare x int; +declare c cursor for select * from dual; +declare continue handler for sqlexception select x; +set x = 1; +open c; +set x = 2; +fetch c into v; +set x = 3; +close c; +end| +call bug10961()| +x +1 +x +2 +x +3 +call bug10961()| +x +1 +x +2 +x +3 +drop procedure bug10961| +DROP PROCEDURE IF EXISTS bug6866| +DROP VIEW IF EXISTS tv| +Warnings: +Note 1051 Unknown table 'test.tv' +DROP TABLE IF EXISTS tt1,tt2,tt3| +Warnings: +Note 1051 Unknown table 'tt1' +Note 1051 Unknown table 'tt2' +Note 1051 Unknown table 'tt3' +CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| +CREATE TABLE tt2 (a2 int, data2 varchar(10))| +CREATE TABLE tt3 (a3 int, data3 varchar(10))| +INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| +INSERT INTO tt2 VALUES (1, 'a')| +INSERT INTO tt2 VALUES (2, 'b')| +INSERT INTO tt2 VALUES (3, 'c')| +INSERT INTO tt3 VALUES (4, 'd')| +INSERT INTO tt3 VALUES (5, 'e')| +INSERT INTO tt3 VALUES (6, 'f')| +CREATE VIEW tv AS +SELECT tt1.*, tt2.data2, tt3.data3 +FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 +LEFT JOIN tt3 ON tt1.a3 = tt3.a3 +ORDER BY tt1.a1, tt2.a2, tt3.a3| +CREATE PROCEDURE bug6866 (_a1 int) +BEGIN +SELECT * FROM tv WHERE a1 = _a1; +END| +CALL bug6866(1)| +a1 a2 a3 data data2 data3 +1 1 4 xx a d +CALL bug6866(1)| +a1 a2 a3 data data2 data3 +1 1 4 xx a d +CALL bug6866(1)| +a1 a2 a3 data data2 data3 +1 1 4 xx a d +DROP PROCEDURE bug6866; +DROP VIEW tv| +DROP TABLE tt1, tt2, tt3| +DROP PROCEDURE IF EXISTS bug10136| +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin +declare done int default 3; +repeat +select * from t3; +set done = done - 1; +until done <= 0 end repeat; +end| +call bug10136()| +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +call bug10136()| +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +call bug10136()| +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +drop procedure bug10136| +drop table t3| +drop procedure if exists bug11529| +create procedure bug11529() +begin +declare c cursor for select id, data from t1 where data in (10,13); +open c; +begin +declare vid char(16); +declare vdata int; +declare exit handler for not found begin end; +while true do +fetch c into vid, vdata; +end while; +end; +close c; +end| +insert into t1 values +('Name1', 10), +('Name2', 11), +('Name3', 12), +('Name4', 13), +('Name5', 14)| +call bug11529()| +call bug11529()| +delete from t1| +drop procedure bug11529| +drop procedure if exists bug6063| +drop procedure if exists bug7088_1| +drop procedure if exists bug7088_2| +drop procedure if exists bug9565_sub| +drop procedure if exists bug9565| +create procedure bug9565_sub() +begin +select * from t1; +end| +create procedure bug9565() +begin +insert into t1 values ("one", 1); +call bug9565_sub(); +end| +call bug9565()| +id data +one 1 +delete from t1| +drop procedure bug9565_sub| +drop procedure bug9565| +drop procedure if exists bug9538| +create procedure bug9538() +set @@sort_buffer_size = 1000000| +set @x = @@sort_buffer_size| +set @@sort_buffer_size = 2000000| +select @@sort_buffer_size| +@@sort_buffer_size +2000000 +call bug9538()| +select @@sort_buffer_size| +@@sort_buffer_size +1000000 +set @@sort_buffer_size = @x| +drop procedure bug9538| +drop procedure if exists bug8692| +create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| +insert into t3 values ('', '', '', '', '', '', NULL)| +Warnings: +Warning 1265 Data truncated for column 'c3' at row 1 +create procedure bug8692() +begin +declare v1 VARCHAR(10); +declare v2 VARCHAR(10); +declare v3 VARCHAR(10); +declare v4 VARCHAR(10); +declare v5 VARCHAR(10); +declare v6 VARCHAR(10); +declare v7 VARCHAR(10); +declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; +open c8692; +fetch c8692 into v1,v2,v3,v4,v5,v6,v7; +select v1, v2, v3, v4, v5, v6, v7; +end| +call bug8692()| +v1 v2 v3 v4 v5 v6 v7 + NULL +drop procedure bug8692| +drop table t3| +drop function if exists bug10055| +create function bug10055(v char(255)) returns char(255) return lower(v)| +select t.column_name, bug10055(t.column_name) +from information_schema.columns as t +where t.table_schema = 'test' and t.table_name = 't1'| +column_name bug10055(t.column_name) +id id +data data +drop function bug10055| +drop procedure if exists bug12297| +create procedure bug12297(lim int) +begin +set @x = 0; +repeat +insert into t1(id,data) +values('aa', @x); +set @x = @x + 1; +until @x >= lim +end repeat; +end| +call bug12297(10)| +drop procedure bug12297| +drop function if exists f_bug11247| +drop procedure if exists p_bug11247| +create function f_bug11247(param int) +returns int +return param + 1| +create procedure p_bug11247(lim int) +begin +declare v int default 0; +while v < lim do +set v= f_bug11247(v); +end while; +end| +call p_bug11247(10)| +drop function f_bug11247| +drop procedure p_bug11247| +drop procedure if exists bug12168| +drop table if exists t3, t4| +create table t3 (a int)| +insert into t3 values (1),(2),(3),(4)| +create table t4 (a int)| +create procedure bug12168(arg1 char(1)) +begin +declare b, c integer; +if arg1 = 'a' then +begin +declare c1 cursor for select a from t3 where a % 2; +declare continue handler for not found set b = 1; +set b = 0; +open c1; +c1_repeat: repeat +fetch c1 into c; +if (b = 1) then +leave c1_repeat; +end if; +insert into t4 values (c); +until b = 1 +end repeat; +end; +end if; +if arg1 = 'b' then +begin +declare c2 cursor for select a from t3 where not a % 2; +declare continue handler for not found set b = 1; +set b = 0; +open c2; +c2_repeat: repeat +fetch c2 into c; +if (b = 1) then +leave c2_repeat; +end if; +insert into t4 values (c); +until b = 1 +end repeat; +end; +end if; +end| +call bug12168('a')| +select * from t4| +a +1 +3 +truncate t4| +call bug12168('b')| +select * from t4| +a +2 +4 +truncate t4| +call bug12168('a')| +select * from t4| +a +1 +3 +truncate t4| +call bug12168('b')| +select * from t4| +a +2 +4 +truncate t4| +drop table t3, t4| +drop procedure if exists bug12168| +drop table if exists t3| +drop procedure if exists bug11333| +create table t3 (c1 char(128))| +insert into t3 values +('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| +create procedure bug11333(i int) +begin +declare tmp varchar(128); +set @x = 0; +repeat +select c1 into tmp from t3 +where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; +set @x = @x + 1; +until @x >= i +end repeat; +end| +call bug11333(10)| +drop procedure bug11333| +drop table t3| +drop function if exists bug9048| +create function bug9048(f1 char binary) returns char binary +begin +set f1= concat( 'hello', f1 ); +return f1; +end| +drop function bug9048| +drop procedure if exists bug12849_1| +create procedure bug12849_1(inout x char) select x into x| +set @var='a'| +call bug12849_1(@var)| +select @var| +@var +a +drop procedure bug12849_1| +drop procedure if exists bug12849_2| +create procedure bug12849_2(inout foo varchar(15)) +begin +select concat(foo, foo) INTO foo; +end| +set @var='abcd'| +call bug12849_2(@var)| +select @var| +@var +abcdabcd +drop procedure bug12849_2| +drop procedure if exists bug131333| +drop function if exists bug131333| +create procedure bug131333() +begin +begin +declare a int; +select a; +set a = 1; +select a; +end; +begin +declare b int; +select b; +end; +end| +create function bug131333() +returns int +begin +begin +declare a int; +set a = 1; +end; +begin +declare b int; +return b; +end; +end| +call bug131333()| +a +NULL +a +1 +b +NULL +select bug131333()| +bug131333() +NULL +drop procedure bug131333| +drop function bug131333| +drop function if exists bug12379| +drop procedure if exists bug12379_1| +drop procedure if exists bug12379_2| +drop procedure if exists bug12379_3| +drop table if exists t3| +create table t3 (c1 char(1) primary key not null)| +create function bug12379() +returns integer +begin +insert into t3 values('X'); +insert into t3 values('X'); +return 0; +end| +create procedure bug12379_1() +begin +declare exit handler for sqlexception select 42; +select bug12379(); +END| +create procedure bug12379_2() +begin +declare exit handler for sqlexception begin end; +select bug12379(); +end| +create procedure bug12379_3() +begin +select bug12379(); +end| +select bug12379()| +ERROR 23000: Duplicate entry 'X' for key 1 +select 1| +1 +1 +call bug12379_1()| +bug12379() +42 +42 +select 2| +2 +2 +call bug12379_2()| +bug12379() +select 3| +3 +3 +call bug12379_3()| +ERROR 23000: Duplicate entry 'X' for key 1 +select 4| +4 +4 +drop function bug12379| +drop procedure bug12379_1| +drop procedure bug12379_2| +drop procedure bug12379_3| +drop table t3| +drop procedure if exists bug13124| +create procedure bug13124() +begin +declare y integer; +set @x=y; +end| +call bug13124()| +drop procedure bug13124| +drop procedure if exists bug12979_1| +create procedure bug12979_1(inout d decimal(5)) set d = d / 2| +set @bug12979_user_var = NULL| +call bug12979_1(@bug12979_user_var)| +drop procedure bug12979_1| +drop procedure if exists bug12979_2| +create procedure bug12979_2() +begin +declare internal_var decimal(5); +set internal_var= internal_var / 2; +select internal_var; +end| +call bug12979_2()| +internal_var +NULL +drop procedure bug12979_2| +drop table if exists t3| +drop procedure if exists bug6127| +create table t3 (s1 int unique)| +set @sm=@@sql_mode| +set sql_mode='traditional'| +create procedure bug6127() +begin +declare continue handler for sqlstate '23000' + begin +declare continue handler for sqlstate '22003' + insert into t3 values (0); +insert into t3 values (1000000000000000); +end; +insert into t3 values (1); +insert into t3 values (1); +end| +call bug6127()| +select * from t3| +s1 +0 +1 +call bug6127()| +ERROR 23000: Duplicate entry '0' for key 1 +select * from t3| +s1 +0 +1 +set sql_mode=@sm| +drop table t3| +drop procedure bug6127| +drop procedure if exists bug12589_1| +drop procedure if exists bug12589_2| +drop procedure if exists bug12589_3| +create procedure bug12589_1() +begin +declare spv1 decimal(3,3); +set spv1= 123.456; +set spv1 = 'test'; +create temporary table tm1 as select spv1; +show create table tm1; +drop temporary table tm1; +end| +create procedure bug12589_2() +begin +declare spv1 decimal(6,3); +set spv1= 123.456; +create temporary table tm1 as select spv1; +show create table tm1; +drop temporary table tm1; +end| +create procedure bug12589_3() +begin +declare spv1 decimal(6,3); +set spv1= -123.456; +create temporary table tm1 as select spv1; +show create table tm1; +drop temporary table tm1; +end| +call bug12589_1()| +Table Create Table +tm1 CREATE TEMPORARY TABLE `tm1` ( + `spv1` decimal(3,3) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +Warnings: +Warning 1264 Out of range value adjusted for column 'spv1' at row 1 +Warning 1366 Incorrect decimal value: 'test' for column 'spv1' at row 1 +call bug12589_2()| +Table Create Table +tm1 CREATE TEMPORARY TABLE `tm1` ( + `spv1` decimal(6,3) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +call bug12589_3()| +Table Create Table +tm1 CREATE TEMPORARY TABLE `tm1` ( + `spv1` decimal(6,3) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop procedure bug12589_1| +drop procedure bug12589_2| +drop procedure bug12589_3| +drop table if exists t3| +drop procedure if exists bug7049_1| +drop procedure if exists bug7049_2| +drop procedure if exists bug7049_3| +drop procedure if exists bug7049_4| +drop function if exists bug7049_1| +drop function if exists bug7049_2| +create table t3 ( x int unique )| +create procedure bug7049_1() +begin +insert into t3 values (42); +insert into t3 values (42); +end| +create procedure bug7049_2() +begin +declare exit handler for sqlexception +select 'Caught it' as 'Result'; +call bug7049_1(); +select 'Missed it' as 'Result'; +end| +create procedure bug7049_3() +call bug7049_1()| +create procedure bug7049_4() +begin +declare exit handler for sqlexception +select 'Caught it' as 'Result'; +call bug7049_3(); +select 'Missed it' as 'Result'; +end| +create function bug7049_1() +returns int +begin +insert into t3 values (42); +insert into t3 values (42); +return 42; +end| +create function bug7049_2() +returns int +begin +declare x int default 0; +declare continue handler for sqlexception +set x = 1; +set x = bug7049_1(); +return x; +end| +call bug7049_2()| +Result +Caught it +select * from t3| +x +42 +delete from t3| +call bug7049_4()| +Result +Caught it +select * from t3| +x +42 +select bug7049_2()| +bug7049_2() +1 +drop table t3| +drop procedure bug7049_1| +drop procedure bug7049_2| +drop procedure bug7049_3| +drop procedure bug7049_4| +drop function bug7049_1| +drop function bug7049_2| +drop function if exists bug13941| +drop procedure if exists bug13941| +create function bug13941(p_input_str text) +returns text +begin +declare p_output_str text; +set p_output_str = p_input_str; +set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); +set p_output_str = replace(p_output_str, 'test', 'prova'); +set p_output_str = replace(p_output_str, 'this', 'questo'); +set p_output_str = replace(p_output_str, ' a ', 'una '); +set p_output_str = replace(p_output_str, 'is', ''); +return p_output_str; +end| +create procedure bug13941(out sout varchar(128)) +begin +set sout = 'Local'; +set sout = ifnull(sout, 'DEF'); +end| +select bug13941('this is a test')| +bug13941('this is a test') +questo una prova +call bug13941(@a)| +select @a| +@a +Local +drop function bug13941| +drop procedure bug13941| +DROP PROCEDURE IF EXISTS bug13095; +DROP TABLE IF EXISTS bug13095_t1; +DROP VIEW IF EXISTS bug13095_v1; +CREATE PROCEDURE bug13095(tbl_name varchar(32)) +BEGIN +SET @str = +CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); +SELECT @str; +PREPARE stmt FROM @str; +EXECUTE stmt; +SET @str = +CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); +SELECT @str; +PREPARE stmt FROM @str; +EXECUTE stmt; +SET @str = +CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); +SELECT @str; +PREPARE stmt FROM @str; +EXECUTE stmt; +SELECT * FROM bug13095_v1; +SET @str = +"DROP VIEW bug13095_v1"; +SELECT @str; +PREPARE stmt FROM @str; +EXECUTE stmt; +END| +CALL bug13095('bug13095_t1'); +@str +CREATE TABLE bug13095_t1(stuff char(15)) +@str +INSERT INTO bug13095_t1 VALUES('row1'),('row2'),('row3') +@str +CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM bug13095_t1 +c1 +row1 +row2 +row3 +@str +DROP VIEW bug13095_v1 +DROP PROCEDURE IF EXISTS bug13095; +DROP VIEW IF EXISTS bug13095_v1; +DROP TABLE IF EXISTS bug13095_t1; +drop procedure if exists bug14210| +set @@session.max_heap_table_size=16384| +select @@session.max_heap_table_size| +@@session.max_heap_table_size +16384 +create table t3 (a char(255)) engine=InnoDB| +create procedure bug14210_fill_table() +begin +declare table_size, max_table_size int default 0; +select @@session.max_heap_table_size into max_table_size; +delete from t3; +insert into t3 (a) values (repeat('a', 255)); +repeat +insert into t3 select a from t3; +select count(*)*255 from t3 into table_size; +until table_size > max_table_size*2 end repeat; +end| +call bug14210_fill_table()| +drop procedure bug14210_fill_table| +create table t4 like t3| +create procedure bug14210() +begin +declare a char(255); +declare done int default 0; +declare c cursor for select * from t3; +declare continue handler for sqlstate '02000' set done = 1; +open c; +repeat +fetch c into a; +if not done then +insert into t4 values (upper(a)); +end if; +until done end repeat; +close c; +end| +call bug14210()| +select count(*) from t4| +count(*) +256 +drop table t3, t4| +drop procedure bug14210| +set @@session.max_heap_table_size=default| +drop function if exists bug14723| +drop procedure if exists bug14723| +/*!50003 create function bug14723() +returns bigint(20) +main_loop: begin +return 42; +end */;; +show create function bug14723;; +Function sql_mode Create Function +bug14723 CREATE FUNCTION `bug14723`() RETURNS bigint(20) +main_loop: begin +return 42; +end +select bug14723();; +bug14723() +42 +/*!50003 create procedure bug14723() +main_loop: begin +select 42; +end */;; +show create procedure bug14723;; +Procedure sql_mode Create Procedure +bug14723 CREATE PROCEDURE `bug14723`() +main_loop: begin +select 42; +end +call bug14723();; +42 +42 +drop function bug14723| +drop procedure bug14723| +create procedure bug14845() +begin +declare a char(255); +declare done int default 0; +declare c cursor for select count(*) from t1 where 1 = 0; +declare continue handler for sqlstate '02000' set done = 1; +open c; +repeat +fetch c into a; +if not done then +select a; +end if; +until done end repeat; +close c; +end| +call bug14845()| +a +0 +drop procedure bug14845| +drop procedure if exists bug13549_1| +drop procedure if exists bug13549_2| +CREATE PROCEDURE `bug13549_2`() +begin +call bug13549_1(); +end| +CREATE PROCEDURE `bug13549_1`() +begin +declare done int default 0; +set done= not done; +end| +CALL bug13549_2()| +drop procedure bug13549_2| +drop procedure bug13549_1| +drop function if exists bug10100f| +drop procedure if exists bug10100p| +drop procedure if exists bug10100t| +drop procedure if exists bug10100pt| +drop procedure if exists bug10100pv| +drop procedure if exists bug10100pd| +drop procedure if exists bug10100pc| +create function bug10100f(prm int) returns int +begin +if prm > 1 then +return prm * bug10100f(prm - 1); +end if; +return 1; +end| +create procedure bug10100p(prm int, inout res int) +begin +set res = res * prm; +if prm > 1 then +call bug10100p(prm - 1, res); +end if; +end| +create procedure bug10100t(prm int) +begin +declare res int; +set res = 1; +call bug10100p(prm, res); +select res; +end| +create table t3 (a int)| +insert into t3 values (0)| +create view v1 as select a from t3; +create procedure bug10100pt(level int, lim int) +begin +if level < lim then +update t3 set a=level; +FLUSH TABLES; +call bug10100pt(level+1, lim); +else +select * from t3; +end if; +end| +create procedure bug10100pv(level int, lim int) +begin +if level < lim then +update v1 set a=level; +FLUSH TABLES; +call bug10100pv(level+1, lim); +else +select * from v1; +end if; +end| +prepare stmt2 from "select * from t3;"; +create procedure bug10100pd(level int, lim int) +begin +if level < lim then +select level; +prepare stmt1 from "update t3 set a=a+2"; +execute stmt1; +FLUSH TABLES; +execute stmt1; +FLUSH TABLES; +execute stmt1; +FLUSH TABLES; +deallocate prepare stmt1; +execute stmt2; +select * from t3; +call bug10100pd(level+1, lim); +else +execute stmt2; +end if; +end| +create procedure bug10100pc(level int, lim int) +begin +declare lv int; +declare c cursor for select a from t3; +open c; +if level < lim then +select level; +fetch c into lv; +select lv; +update t3 set a=level+lv; +FLUSH TABLES; +call bug10100pc(level+1, lim); +else +select * from t3; +end if; +close c; +end| +set @@max_sp_recursion_depth=4| +select @@max_sp_recursion_depth| +@@max_sp_recursion_depth +4 +select bug10100f(3)| +ERROR HY000: Recursive stored functions and triggers are not allowed. +select bug10100f(6)| +ERROR HY000: Recursive stored functions and triggers are not allowed. +call bug10100t(5)| +res +120 +call bug10100pt(1,5)| +a +4 +call bug10100pv(1,5)| +a +4 +update t3 set a=1| +call bug10100pd(1,5)| +level +1 +a +7 +a +7 +level +2 +a +13 +a +13 +level +3 +a +19 +a +19 +level +4 +a +25 +a +25 +a +25 +select * from t3| +a +25 +update t3 set a=1| +call bug10100pc(1,5)| +level +1 +lv +1 +level +2 +lv +2 +level +3 +lv +4 +level +4 +lv +7 +a +11 +select * from t3| +a +11 +set @@max_sp_recursion_depth=0| +select @@max_sp_recursion_depth| +@@max_sp_recursion_depth +0 +select bug10100f(5)| +ERROR HY000: Recursive stored functions and triggers are not allowed. +call bug10100t(5)| +ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine bug10100p +set @@max_sp_recursion_depth=255| +set @var=1| +call bug10100p(255, @var)| +call bug10100pt(1,255)| +call bug10100pv(1,255)| +call bug10100pd(1,255)| +call bug10100pc(1,255)| +set @@max_sp_recursion_depth=0| +deallocate prepare stmt2| +drop function bug10100f| +drop procedure bug10100p| +drop procedure bug10100t| +drop procedure bug10100pt| +drop procedure bug10100pv| +drop procedure bug10100pd| +drop procedure bug10100pc| +drop view v1| +drop procedure if exists bug13729| +drop table if exists t3| +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1),(2)| +create procedure bug13729() +begin +declare continue handler for sqlexception select 55; +update t3 set s1 = 1; +end| +call bug13729()| +55 +55 +select * from t3| +s1 +1 +2 +drop procedure bug13729| +drop table t3| +drop procedure if exists bug14643_1| +drop procedure if exists bug14643_2| +create procedure bug14643_1() +begin +declare continue handler for sqlexception select 'boo' as 'Handler'; +begin +declare v int default undefined_var; +if v = 1 then +select 1; +else +select v, isnull(v); +end if; +end; +end| +create procedure bug14643_2() +begin +declare continue handler for sqlexception select 'boo' as 'Handler'; +case undefined_var +when 1 then +select 1; +else +select 2; +end case; +select undefined_var; +end| +call bug14643_1()| +Handler +boo +v isnull(v) +NULL 1 +call bug14643_2()| +Handler +boo +Handler +boo +drop procedure bug14643_1| +drop procedure bug14643_2| +drop procedure if exists bug14304| +drop table if exists t3, t4| +create table t3(a int primary key auto_increment)| +create table t4(a int primary key auto_increment)| +create procedure bug14304() +begin +insert into t3 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 select null as a; +insert into t3 set a=null; +insert into t3 set a=null; +select * from t3; +end| +call bug14304()| +a +1 +2 +3 +drop procedure bug14304| +drop table t3, t4| +drop procedure if exists bug14376| +create procedure bug14376() +begin +declare x int default x; +end| +call bug14376()| +ERROR 42S22: Unknown column 'x' in 'field list' +drop procedure bug14376| +create procedure bug14376() +begin +declare x int default 42; +begin +declare x int default x; +select x; +end; +end| +call bug14376()| +x +42 +drop procedure bug14376| +create procedure bug14376(x int) +begin +declare x int default x; +select x; +end| +call bug14376(4711)| +x +4711 +drop procedure bug14376| +drop procedure if exists bug5967| +drop table if exists t3| +create table t3 (a varchar(255))| +insert into t3 (a) values ("a - table column")| +create procedure bug5967(a varchar(255)) +begin +declare i varchar(255); +declare c cursor for select a from t3; +select a; +select a from t3 into i; +select i as 'Parameter takes precedence over table column'; open c; +fetch c into i; +close c; +select i as 'Parameter takes precedence over table column in cursors'; +begin +declare a varchar(255) default 'a - local variable'; +declare c1 cursor for select a from t3; +select a as 'A local variable takes precedence over parameter'; +open c1; +fetch c1 into i; +close c1; +select i as 'A local variable takes precedence over parameter in cursors'; +begin +declare a varchar(255) default 'a - local variable in a nested compound statement'; +declare c2 cursor for select a from t3; +select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; +select a from t3 into i; +select i as 'A local variable in a nested compound statement takes precedence over table column'; +open c2; +fetch c2 into i; +close c2; +select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; +end; +end; +end| +call bug5967("a - stored procedure parameter")| +a +a - stored procedure parameter +Parameter takes precedence over table column +a - stored procedure parameter +Parameter takes precedence over table column in cursors +a - stored procedure parameter +A local variable takes precedence over parameter +a - local variable +A local variable takes precedence over parameter in cursors +a - local variable +A local variable in a nested compound statement takes precedence over a local variable in the outer statement +a - local variable in a nested compound statement +A local variable in a nested compound statement takes precedence over table column +a - local variable in a nested compound statement +A local variable in a nested compound statement takes precedence over table column in cursors +a - local variable in a nested compound statement +drop procedure bug5967| +drop procedure if exists bug13012| +create procedure bug13012() +BEGIN +REPAIR TABLE t1; +BACKUP TABLE t1 to '../tmp'; +DROP TABLE t1; +RESTORE TABLE t1 FROM '../tmp'; +END| +call bug13012()| +Table Op Msg_type Msg_text +test.t1 repair status OK +Table Op Msg_type Msg_text +test.t1 backup status OK +Table Op Msg_type Msg_text +test.t1 restore status OK +drop procedure bug13012| +create view v1 as select * from t1| +create procedure bug13012() +BEGIN +REPAIR TABLE t1,t2,t3,v1; +OPTIMIZE TABLE t1,t2,t3,v1; +ANALYZE TABLE t1,t2,t3,v1; +END| +call bug13012()| +Table Op Msg_type Msg_text +test.t1 repair status OK +test.t2 repair status OK +test.t3 repair status OK +test.v1 repair error 'test.v1' is not BASE TABLE +Table Op Msg_type Msg_text +test.t1 optimize status OK +test.t2 optimize status OK +test.t3 optimize status OK +test.v1 optimize error 'test.v1' is not BASE TABLE +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +test.t2 analyze status Table is already up to date +test.t3 analyze status Table is already up to date +test.v1 analyze error 'test.v1' is not BASE TABLE +Warnings: +Error 1347 'test.v1' is not BASE TABLE +call bug13012()| +Table Op Msg_type Msg_text +test.t1 repair status OK +test.t2 repair status OK +test.t3 repair status OK +test.v1 repair error 'test.v1' is not BASE TABLE +Table Op Msg_type Msg_text +test.t1 optimize status OK +test.t2 optimize status OK +test.t3 optimize status OK +test.v1 optimize error 'test.v1' is not BASE TABLE +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +test.t2 analyze status Table is already up to date +test.t3 analyze status Table is already up to date +test.v1 analyze error 'test.v1' is not BASE TABLE +Warnings: +Error 1347 'test.v1' is not BASE TABLE +call bug13012()| +Table Op Msg_type Msg_text +test.t1 repair status OK +test.t2 repair status OK +test.t3 repair status OK +test.v1 repair error 'test.v1' is not BASE TABLE +Table Op Msg_type Msg_text +test.t1 optimize status OK +test.t2 optimize status OK +test.t3 optimize status OK +test.v1 optimize error 'test.v1' is not BASE TABLE +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +test.t2 analyze status Table is already up to date +test.t3 analyze status Table is already up to date +test.v1 analyze error 'test.v1' is not BASE TABLE +Warnings: +Error 1347 'test.v1' is not BASE TABLE +drop procedure bug13012| +drop view v1; +select * from t1| +id data +aa 0 +aa 1 +aa 2 +aa 3 +aa 4 +aa 5 +aa 6 +aa 7 +aa 8 +aa 9 +drop schema if exists mysqltest1| +Warnings: +Note 1008 Can't drop database 'mysqltest1'; database doesn't exist +drop schema if exists mysqltest2| +Warnings: +Note 1008 Can't drop database 'mysqltest2'; database doesn't exist +drop schema if exists mysqltest3| +Warnings: +Note 1008 Can't drop database 'mysqltest3'; database doesn't exist +create schema mysqltest1| +create schema mysqltest2| +create schema mysqltest3| +use mysqltest3| +create procedure mysqltest1.p1 (out prequestid varchar(100)) +begin +call mysqltest2.p2('call mysqltest3.p3(1, 2)'); +end| +create procedure mysqltest2.p2(in psql text) +begin +declare lsql text; +set @lsql= psql; +prepare lstatement from @lsql; +execute lstatement; +deallocate prepare lstatement; +end| +create procedure mysqltest3.p3(in p1 int) +begin +select p1; +end| +call mysqltest1.p1(@rs)| +ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2 +call mysqltest1.p1(@rs)| +ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2 +call mysqltest1.p1(@rs)| +ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2 +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +use test| +drop table if exists t3| +drop procedure if exists bug15441| +create table t3 (id int not null primary key, county varchar(25))| +insert into t3 (id, county) values (1, 'York')| +create procedure bug15441(c varchar(25)) +begin +update t3 set id=2, county=values(c); +end| +call bug15441('county')| +ERROR 42S22: Unknown column 'c' in 'field list' +drop procedure bug15441| +create procedure bug15441(county varchar(25)) +begin +declare c varchar(25) default "hello"; +insert into t3 (id, county) values (1, county) +on duplicate key update county= values(county); +select * from t3; +update t3 set id=2, county=values(id); +select * from t3; +end| +call bug15441('Yale')| +id county +1 Yale +id county +2 NULL +drop table t3| +drop procedure bug15441| +drop procedure if exists bug14498_1| +drop procedure if exists bug14498_2| +drop procedure if exists bug14498_3| +drop procedure if exists bug14498_4| +drop procedure if exists bug14498_5| +create procedure bug14498_1() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +if v then +select 'yes' as 'v'; +else +select 'no' as 'v'; +end if; +select 'done' as 'End'; +end| +create procedure bug14498_2() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +while v do +select 'yes' as 'v'; +end while; +select 'done' as 'End'; +end| +create procedure bug14498_3() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +repeat +select 'maybe' as 'v'; +until v end repeat; +select 'done' as 'End'; +end| +create procedure bug14498_4() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +case v +when 1 then +select '1' as 'v'; +when 2 then +select '2' as 'v'; +else +select '?' as 'v'; +end case; +select 'done' as 'End'; +end| +create procedure bug14498_5() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +case +when v = 1 then +select '1' as 'v'; +when v = 2 then +select '2' as 'v'; +else +select '?' as 'v'; +end case; +select 'done' as 'End'; +end| +call bug14498_1()| +Handler +error +End +done +call bug14498_2()| +Handler +error +End +done +call bug14498_3()| +v +maybe +Handler +error +End +done +call bug14498_4()| +Handler +error +End +done +call bug14498_5()| +Handler +error +End +done +drop procedure bug14498_1| +drop procedure bug14498_2| +drop procedure bug14498_3| +drop procedure bug14498_4| +drop procedure bug14498_5| +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| +create table t3 (id int not null)| +create procedure bug15231_1() +begin +declare xid integer; +declare xdone integer default 0; +declare continue handler for not found set xdone = 1; +set xid=null; +call bug15231_2(xid); +select xid, xdone; +end| +create procedure bug15231_2(inout ioid integer) +begin +select "Before NOT FOUND condition is triggered" as '1'; +select id into ioid from t3 where id=ioid; +select "After NOT FOUND condtition is triggered" as '2'; +if ioid is null then +set ioid=1; +end if; +end| +create procedure bug15231_3() +begin +declare exit handler for sqlwarning +select 'Caught it (wrong)' as 'Result'; +call bug15231_4(); +end| +create procedure bug15231_4() +begin +declare x decimal(2,1); +set x = 'zap'; +select 'Missed it (correct)' as 'Result'; +end| +call bug15231_1()| +1 +Before NOT FOUND condition is triggered +2 +After NOT FOUND condtition is triggered +xid xdone +1 0 +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call bug15231_3()| +Result +Missed it (correct) +Warnings: +Warning 1366 Incorrect decimal value: 'zap' for column 'x' at row 1 +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| +drop procedure if exists bug15011| +create table t3 (c1 int primary key)| +insert into t3 values (1)| +create procedure bug15011() +deterministic +begin +declare continue handler for 1062 +select 'Outer' as 'Handler'; +begin +declare continue handler for 1062 +select 'Inner' as 'Handler'; +insert into t3 values (1); +end; +end| +call bug15011()| +Handler +Inner +drop procedure bug15011| +drop table t3| +drop table t1,t2; diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result index bdd32647f9d..d434f5c32ce 100644 --- a/mysql-test/r/sp_notembedded.result +++ b/mysql-test/r/sp_notembedded.result @@ -117,7 +117,7 @@ create procedure bug10100p(prm int, inout res int) begin set res = res * prm; if prm > 1 then -call bug10100p(prm - 1, res); +call bug10100p(prm - 1, res); end if; end| create procedure bug10100t(prm int) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 93ad18a4de0..7def4cdcf9d 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2987,7 +2987,6 @@ select * from (select max(fld) from t1) as foo; max(fld) 1 drop table t1; -purge master logs before (select adddate(current_timestamp(), interval -4 day)); CREATE TABLE t1 (a int, b int); CREATE TABLE t2 (c int, d int); CREATE TABLE t3 (e int); diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index a0a51013caa..edb5dee41be 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -1,4 +1,4 @@ -drop table if exists t1, t2, t3; +drop table if exists t1, t2, t3, t4; drop view if exists v1; drop database if exists mysqltest; drop function if exists f1; @@ -785,6 +785,107 @@ create trigger test.t1_bi before insert on t1 for each row set @a:=0; ERROR 3D000: No database selected drop trigger t1_bi; ERROR 3D000: No database selected +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +insert into t1 values (101); +select @a; +@a +101 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +test t1_bi test t1 set @a:=new.id +rename table t1 to t2; +insert into t2 values (102); +select @a; +@a +102 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +test t1_bi test t2 set @a:=new.id +alter table t2 rename to t3; +insert into t3 values (103); +select @a; +@a +103 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +test t1_bi test t3 set @a:=new.id +alter table t3 rename to t4, add column val int default 0; +insert into t4 values (104, 1); +select @a; +@a +104 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +test t1_bi test t4 set @a:=new.id +drop trigger t1_bi; +drop table t4; +create database mysqltest; +use mysqltest; +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +insert into t1 values (101); +select @a; +@a +101 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +mysqltest t1_bi mysqltest t1 set @a:=new.id +rename table t1 to test.t2; +ERROR HY000: Trigger in wrong schema +insert into t1 values (102); +select @a; +@a +102 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +mysqltest t1_bi mysqltest t1 set @a:=new.id +drop trigger test.t1_bi; +ERROR HY000: Trigger does not exist +drop trigger t1_bi; +drop table t1; +drop database mysqltest; +use test; +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +create trigger t1_ai after insert on t1 for each row set @b:=new.id; +insert into t1 values (101); +select @a, @b; +@a @b +101 101 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +test t1_bi test t1 set @a:=new.id +test t1_ai test t1 set @b:=new.id +rename table t1 to t2; +ERROR HY000: Can't create/write to file './test/t1_ai.TRN~' (Errcode: 13) +insert into t1 values (102); +select @a, @b; +@a @b +102 102 +select trigger_schema, trigger_name, event_object_schema, +event_object_table, action_statement from information_schema.triggers +where event_object_schema = 'test'; +trigger_schema trigger_name event_object_schema event_object_table action_statement +test t1_bi test t1 set @a:=new.id +test t1_ai test t1 set @b:=new.id +drop trigger t1_bi; +drop trigger t1_ai; +drop table t1; create table t1 (i int); create trigger t1_bi before insert on t1 for each row return 0; ERROR 42000: RETURN is only allowed in a FUNCTION diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result index 38f8ce08368..a718ddb9a1b 100644 --- a/mysql-test/r/type_timestamp.result +++ b/mysql-test/r/type_timestamp.result @@ -100,13 +100,13 @@ create table t1 (t2 timestamp(2), t4 timestamp(4), t6 timestamp(6), t8 timestamp(8), t10 timestamp(10), t12 timestamp(12), t14 timestamp(14)); Warnings: -Warning 1287 'TIMESTAMP(2)' is deprecated; use 'TIMESTAMP' instead -Warning 1287 'TIMESTAMP(4)' is deprecated; use 'TIMESTAMP' instead -Warning 1287 'TIMESTAMP(6)' is deprecated; use 'TIMESTAMP' instead -Warning 1287 'TIMESTAMP(8)' is deprecated; use 'TIMESTAMP' instead -Warning 1287 'TIMESTAMP(10)' is deprecated; use 'TIMESTAMP' instead -Warning 1287 'TIMESTAMP(12)' is deprecated; use 'TIMESTAMP' instead -Warning 1287 'TIMESTAMP(14)' is deprecated; use 'TIMESTAMP' instead +Warning 1540 The syntax 'TIMESTAMP(2)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. +Warning 1540 The syntax 'TIMESTAMP(4)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. +Warning 1540 The syntax 'TIMESTAMP(6)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. +Warning 1540 The syntax 'TIMESTAMP(8)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. +Warning 1540 The syntax 'TIMESTAMP(10)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. +Warning 1540 The syntax 'TIMESTAMP(12)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. +Warning 1540 The syntax 'TIMESTAMP(14)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead. insert t1 values (0,0,0,0,0,0,0), ("1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59", diff --git a/mysql-test/r/upgrade.result b/mysql-test/r/upgrade.result index f7c8e8cdfa0..bd60b02cb6a 100644 --- a/mysql-test/r/upgrade.result +++ b/mysql-test/r/upgrade.result @@ -1,43 +1,43 @@ -drop database if exists `testdb1`; -drop database if exists `testdb-1`; -drop database if exists `#mysql50#testdb-1`; -create database `testdb1`; -create database `#mysql50#testdb-1`; -create table `testdb1`.`t1` (a int); -create table `testdb1`.`#mysql50#t-1` (a int); -create table `#mysql50#testdb-1`.`t1` (a int); -create table `#mysql50#testdb-1`.`#mysql50#t-1` (a int); -show create database `testdb1`; +drop database if exists `mysqltest1`; +drop database if exists `mysqltest-1`; +drop database if exists `#mysql50#mysqltest-1`; +create database `mysqltest1`; +create database `#mysql50#mysqltest-1`; +create table `mysqltest1`.`t1` (a int); +create table `mysqltest1`.`#mysql50#t-1` (a int); +create table `#mysql50#mysqltest-1`.`t1` (a int); +create table `#mysql50#mysqltest-1`.`#mysql50#t-1` (a int); +show create database `mysqltest1`; Database Create Database -testdb1 CREATE DATABASE `testdb1` /*!40100 DEFAULT CHARACTER SET latin1 */ -show create database `testdb-1`; -ERROR 42000: Unknown database 'testdb-1' -show create database `#mysql50#testdb-1`; +mysqltest1 CREATE DATABASE `mysqltest1` /*!40100 DEFAULT CHARACTER SET latin1 */ +show create database `mysqltest-1`; +ERROR 42000: Unknown database 'mysqltest-1' +show create database `#mysql50#mysqltest-1`; Database Create Database -#mysql50#testdb-1 CREATE DATABASE `#mysql50#testdb-1` /*!40100 DEFAULT CHARACTER SET latin1 */ -show tables in `testdb1`; -Tables_in_testdb1 +#mysql50#mysqltest-1 CREATE DATABASE `#mysql50#mysqltest-1` /*!40100 DEFAULT CHARACTER SET latin1 */ +show tables in `mysqltest1`; +Tables_in_mysqltest1 #mysql50#t-1 t1 -show tables in `#mysql50#testdb-1`; -Tables_in_#mysql50#testdb-1 +show tables in `#mysql50#mysqltest-1`; +Tables_in_#mysql50#mysqltest-1 #mysql50#t-1 t1 -show create database `testdb1`; +show create database `mysqltest1`; Database Create Database -testdb1 CREATE DATABASE `testdb1` /*!40100 DEFAULT CHARACTER SET latin1 */ -show create database `testdb-1`; +mysqltest1 CREATE DATABASE `mysqltest1` /*!40100 DEFAULT CHARACTER SET latin1 */ +show create database `mysqltest-1`; Database Create Database -testdb-1 CREATE DATABASE `testdb-1` /*!40100 DEFAULT CHARACTER SET latin1 */ -show create database `#mysql50#testdb-1`; -ERROR 42000: Unknown database '#mysql50#testdb-1' -show tables in `testdb1`; -Tables_in_testdb1 +mysqltest-1 CREATE DATABASE `mysqltest-1` /*!40100 DEFAULT CHARACTER SET latin1 */ +show create database `#mysql50#mysqltest-1`; +ERROR 42000: Unknown database '#mysql50#mysqltest-1' +show tables in `mysqltest1`; +Tables_in_mysqltest1 t1 t-1 -show tables in `testdb-1`; -Tables_in_testdb-1 +show tables in `mysqltest-1`; +Tables_in_mysqltest-1 t1 t-1 -drop database `testdb1`; -drop database `testdb-1`; +drop database `mysqltest1`; +drop database `mysqltest-1`; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 5396db82965..e3d683a58dc 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2529,3 +2529,13 @@ Warnings: Warning 1052 Column 'x' in group statement is ambiguous DROP VIEW v1; DROP TABLE t1; +drop table if exists t1; +drop view if exists v1; +create table t1 (id int); +create view v1 as select * from t1; +drop table t1; +show create view v1; +drop view v1; +// +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select sql_no_cache `test`.`t1`.`id` AS `id` from `t1` diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result index 9f9d3b53063..99ed14951a4 100644 --- a/mysql-test/r/warnings.result +++ b/mysql-test/r/warnings.result @@ -168,7 +168,7 @@ max_error_count 10 drop table t1; set table_type=MYISAM; Warnings: -Warning 1287 'table_type' is deprecated; use 'storage_engine' instead +Warning 1540 The syntax 'table_type' is deprecated and will be removed in MySQL 5.2. Please use 'storage_engine' instead. create table t1 (a int); insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); update t1 set a='abc'; diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result index 4d66e034964..18516277c3c 100644 --- a/mysql-test/r/xml.result +++ b/mysql-test/r/xml.result @@ -65,6 +65,9 @@ c1 SELECT extractValue(@xml,'/a/child::*'); extractValue(@xml,'/a/child::*') b1 b2 +SELECT extractValue(@xml,'/a/self::*'); +extractValue(@xml,'/a/self::*') +a1 a2 SELECT extractValue(@xml,'/a/descendant::*'); extractValue(@xml,'/a/descendant::*') b1 c1 b2 @@ -542,3 +545,31 @@ a select extractvalue('<a>a<b>B</b></a>','a|/b'); extractvalue('<a>a<b>B</b></a>','a|/b') a +select extractvalue('<a>A</a>','/<a>'); +ERROR HY000: XPATH syntax error: '>' +select extractvalue('<a><b>b</b><b!>b!</b!></a>','//b!'); +ERROR HY000: XPATH syntax error: '!' +select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant::*'); +extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant::*') +B C +select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/self::*'); +extractvalue('<a>A<b>B<c>C</c></b></a>','/a/self::*') +A +select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant-or-self::*'); +extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant-or-self::*') +A B C +select extractvalue('<A_B>A</A_B>','/A_B'); +extractvalue('<A_B>A</A_B>','/A_B') +A +select extractvalue('<a>Jack</a>','/a[contains(../a,"J")]'); +extractvalue('<a>Jack</a>','/a[contains(../a,"J")]') +Jack +select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]'); +extractvalue('<a>Jack</a>','/a[contains(../a,"j")]') +Jack +select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin); +extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin) + +select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]'); +extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]') + diff --git a/mysql-test/t/bigint.test b/mysql-test/t/bigint.test index 7871b3647e3..35cda11646a 100644 --- a/mysql-test/t/bigint.test +++ b/mysql-test/t/bigint.test @@ -270,3 +270,12 @@ VALUES (9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, SELECT * FROM t1; DROP TABLE t1; + +#bug #9088 BIGINT WHERE CLAUSE +create table t1 (bigint_col bigint unsigned); +insert into t1 values (17666000000000000000); +select * from t1 where bigint_col=17666000000000000000; +select * from t1 where bigint_col='17666000000000000000'; +drop table t1; + + diff --git a/mysql-test/t/binary.test b/mysql-test/t/binary.test index 1ac0cfebb28..4ab6ee9eaf1 100644 --- a/mysql-test/t/binary.test +++ b/mysql-test/t/binary.test @@ -89,3 +89,15 @@ show create table t1; drop table t1; # End of 4.1 tests + +# +# Bug#16857 +# +create table t1 (col1 binary(4)); +insert into t1 values ('a'),('a '); +select hex(col1) from t1; +alter table t1 modify col1 binary(10); +select hex(col1) from t1; +insert into t1 values ('b'),('b '); +select hex(col1) from t1; +drop table t1; diff --git a/mysql-test/t/mix_innodb_myisam_binlog-master.opt b/mysql-test/t/binlog_row_mix_innodb_myisam-master.opt index cb48f1aaf60..cb48f1aaf60 100644 --- a/mysql-test/t/mix_innodb_myisam_binlog-master.opt +++ b/mysql-test/t/binlog_row_mix_innodb_myisam-master.opt diff --git a/mysql-test/t/binlog_stm_mix_innodb_myisam-master.opt b/mysql-test/t/binlog_stm_mix_innodb_myisam-master.opt new file mode 100644 index 00000000000..cb48f1aaf60 --- /dev/null +++ b/mysql-test/t/binlog_stm_mix_innodb_myisam-master.opt @@ -0,0 +1 @@ +--loose-innodb_lock_wait_timeout=2 diff --git a/mysql-test/t/case.test b/mysql-test/t/case.test index 555e34d5cf2..42536ce8a3b 100644 --- a/mysql-test/t/case.test +++ b/mysql-test/t/case.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1; +drop table if exists t1,t2; --enable_warnings select CASE "b" when "a" then 1 when "b" then 2 END; diff --git a/mysql-test/t/client_xml.test b/mysql-test/t/client_xml.test index 58e9178ef3a..017b7a1569a 100644 --- a/mysql-test/t/client_xml.test +++ b/mysql-test/t/client_xml.test @@ -9,13 +9,13 @@ create table t1 ( `a>b` text ); insert into t1 values (1, 2, 'a&b a<b a>b'); ---exec $MYSQL --xml test -e 'select * from t1' +--exec $MYSQL --xml test -e "select * from t1" --exec $MYSQL_DUMP --xml --skip-create test ---exec $MYSQL --xml test -e 'select count(*) from t1' ---exec $MYSQL --xml test -e 'select 1 < 2 from dual' ---exec $MYSQL --xml test -e 'select 1 > 2 from dual' ---exec $MYSQL --xml test -e 'select 1 & 3 from dual' ---exec $MYSQL --xml test -e 'select null from dual' +--exec $MYSQL --xml test -e "select count(*) from t1" +--exec $MYSQL --xml test -e "select 1 < 2 from dual" +--exec $MYSQL --xml test -e "select 1 > 2 from dual" +--exec $MYSQL --xml test -e "select 1 & 3 from dual" +--exec $MYSQL --xml test -e "select null from dual" drop table t1; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index d8f23b1e875..c5d1b881896 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -661,4 +661,12 @@ alter table t1 max_rows=100000000000; show create table t1; drop table t1; +# +# Bug#17530: Incorrect key truncation on table creation caused server crash. +# +create table t1(f1 varchar(800) binary not null, key(f1)) engine = innodb + character set utf8 collate utf8_general_ci; +insert into t1 values('aaa'); +drop table t1; + # End of 5.0 tests diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index 30b298ece34..c32750d89e4 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -10,27 +10,32 @@ # ############################################################################## #ndb_alter_table_row : sometimes wrong error 1015!=1046 +events_bugs : test case unstable (race conditions). andrey will fix +events_stress : test case unstable. andrey will fix +events : test case unstable. andrey will fix ndb_autodiscover : Needs to be fixed w.r.t binlog ndb_autodiscover2 : Needs to be fixed w.r.t binlog ndb_binlog_basic : Results are not deterministic, Tomas will fix ndb_binlog_ddl_multi : Bug#17038 [PATCH PENDING] -ndb_dd_backuprestore : Bug#17045 NdbDictionaryImpl::fix_blob_events causes core ndb_load : Bug#17233 partition_03ndb : Bug#16385 ps_7ndb : dbug assert in RBR mode when executing test suite -rpl_bit_npk : Bug#13418 +#rpl_bit_npk : Bug#13418 rpl_ddl : Bug#15963 SBR does not show "Definer" correctly +rpl_ndb_2innodb : Bugs#17400: delete & update of rows in table without pk fails +rpl_ndb_2myisam : Bugs#17400: delete & update of rows in table without pk fails rpl_ndb_auto_inc : Bug#17086 rpl_ndb_basic : Bug#16228 [IN REVIEW] rpl_ndb_charset : Bug#17246 rpl_ndb_ddl : Bug#17400: delete & update of rows in table without pk fails rpl_ndb_delete_nowhere : Bug#17400: delete & update of rows in table without pk fails +rpl_ndb_innodb2ndb : Bugs#17400: delete & update of rows in table without pk fails rpl_ndb_insert_ignore : Bugs: #17431: INSERT IGNORE INTO returns failed: 1296 -#rpl_ndb_log : result not deterministic +rpl_ndb_myisam2ndb : Bugs#17400: delete & update of rows in table without pk fails +rpl_ndb_log : result not deterministic rpl_ndb_relay_space : Bug#16993 rpl_ndb_multi_update3 : Bug#17400: delete & update of rows in table without pk fails rpl_ndb_sp007 : Bug #17290 rpl_sp : Bug#16456 rpl_until : Unstable test case, bug#15886 sp-goto : GOTO is currently is disabled - will be fixed in the future -rpl_ndb_log : results are not deterministic diff --git a/mysql-test/t/events.test b/mysql-test/t/events.test index bde8747a4ef..a261b3c0c11 100644 --- a/mysql-test/t/events.test +++ b/mysql-test/t/events.test @@ -48,6 +48,38 @@ drop event event2; create event event2 on schedule every 2 second starts now() ends date_add(now(), interval 5 hour) comment "some" DO begin end; drop event event2; +# BUG #16537 (Events: mysql.event.starts is null) +CREATE EVENT event_starts_test ON SCHEDULE EVERY 10 SECOND COMMENT "" DO SELECT 1; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +ALTER EVENT event_starts_test ON SCHEDULE AT '2020-02-02 20:00:02'; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +ALTER EVENT event_starts_test COMMENT "non-empty comment"; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +ALTER EVENT event_starts_test COMMENT ""; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +DROP EVENT event_starts_test; +CREATE EVENT event_starts_test ON SCHEDULE EVERY 20 SECOND STARTS '2020-02-02 20:00:02' ENDS '2022-02-02 20:00:02' DO SELECT 2; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +ALTER EVENT event_starts_test COMMENT "non-empty comment"; +--replace_column 8 # 9 # +SHOW EVENTS; +SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test'; +ALTER EVENT event_starts_test COMMENT ""; +--replace_column 8 # 9 # +SHOW EVENTS; +DROP EVENT event_starts_test; +# +# create event e_43 on schedule every 1 second do set @a = 5; set global event_scheduler = 1; --sleep 2 diff --git a/mysql-test/t/events_logs_tests-master.opt b/mysql-test/t/events_logs_tests-master.opt new file mode 100644 index 00000000000..35ff7911705 --- /dev/null +++ b/mysql-test/t/events_logs_tests-master.opt @@ -0,0 +1 @@ +--log-slow-queries diff --git a/mysql-test/t/events_logs_tests.test b/mysql-test/t/events_logs_tests.test new file mode 100644 index 00000000000..e586184c9e4 --- /dev/null +++ b/mysql-test/t/events_logs_tests.test @@ -0,0 +1,89 @@ +create database if not exists events_test; +use events_test; +--echo "We use procedure here because its statements won't be logged into the general log" +--echo "If we had used normal select that are logged in different ways depending on whether" +--echo "the test suite is run in normal mode or with --ps-protocol" +delimiter |; +CREATE procedure select_general_log() +BEGIN + SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%'; +END| +delimiter ;| +--echo "Check General Query Log" +SET GLOBAL event_scheduler=0; +create event log_general on schedule every 1 minute do SELect 'alabala', sleep(3) from dual; +TRUNCATE mysql.general_log; +--echo "1 row, the current statement!" +call select_general_log(); +SET GLOBAL event_scheduler=1; +--echo "Wait the scheduler to start" +--echo "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" +--sleep 2 +call select_general_log(); +DROP PROCEDURE select_general_log; +DROP EVENT log_general; +SET GLOBAL event_scheduler=0; +--sleep 1 + +--echo "Check slow query log" +--disable_query_log +DELIMITER |; +CREATE FUNCTION get_value() + returns INT + deterministic +BEGIN + DECLARE var_name CHAR(255); + DECLARE var_val INT; + DECLARE done INT DEFAULT 0; + DECLARE cur1 CURSOR FOR SHOW GLOBAL VARIABLES LIKE 'long_query_time'; + DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; + OPEN cur1; + FETCH cur1 INTO var_name, var_val; + CLOSE cur1; + RETURN var_val; +end| +DELIMITER ;| +--enable_query_log +--echo "Save the values" +SET @old_global_long_query_time:=(select get_value()); +SET @old_session_long_query_time:=@@long_query_time; +SHOW VARIABLES LIKE 'log_slow_queries'; +DROP FUNCTION get_value; +TRUNCATE mysql.slow_log; +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +--echo "Set new values" +SET GLOBAL long_query_time=4; +SET SESSION long_query_time=2; +--echo "Check that logging is working" +SELECT SLEEP(3); +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +TRUNCATE mysql.slow_log; +CREATE TABLE slow_event_test (slo_val tinyint, val tinyint); +--echo "This won't go to the slow log" +CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(3); +SELECT * FROM slow_event_test; +SET GLOBAL event_scheduler=1; +--echo "Sleep some more time than the actual event run will take" +--sleep 5 +SHOW VARIABLES LIKE 'event_scheduler'; +--echo "Check our table. Should see 1 row" +SELECT * FROM slow_event_test; +--echo "Check slow log. Should not see anything because 3 is under the threshold of 4 for GLOBAL, though over SESSION which is 2" +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +--echo "This should go to the slow log" +SET SESSION long_query_time=10; +DROP EVENT long_event; +CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(5); +--echo "Sleep some more time than the actual event run will take" +--sleep 7 +--echo "Check our table. Should see 2 rows" +SELECT * FROM slow_event_test; +--echo "Check slow log. Should see 1 row because 5 is over the threshold of 4 for GLOBAL, though under SESSION which is 10" +SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; +DROP EVENT long_event2; +SET GLOBAL long_query_time =@old_global_long_query_time; +SET SESSION long_query_time =@old_session_long_query_time; +TRUNCATE mysql.slow_log; +DROP TABLE slow_event_test; + +drop database events_test; diff --git a/mysql-test/t/events_microsec.test b/mysql-test/t/events_microsec.test new file mode 100644 index 00000000000..34855fdadff --- /dev/null +++ b/mysql-test/t/events_microsec.test @@ -0,0 +1,55 @@ +create database if not exists events_test; +use events_test; + +--error 1235 +CREATE EVENT micro_test ON SCHEDULE EVERY 100 MICROSECOND DO SELECT 1; +--error 1235 +CREATE EVENT micro_test ON SCHEDULE EVERY 100 DAY_MICROSECOND DO SELECT 1; +--error 1235 +CREATE EVENT micro_test ON SCHEDULE EVERY 100 HOUR_MICROSECOND DO SELECT 1; +--error 1235 +CREATE EVENT micro_test ON SCHEDULE EVERY 100 MINUTE_MICROSECOND DO SELECT 1; +--error 1235 +CREATE EVENT micro_test ON SCHEDULE EVERY 100 SECOND_MICROSECOND DO SELECT 1; + +--echo "Now create normal event and change it on SQL level" +CREATE EVENT micro_test2 ON SCHEDULE EVERY 1 MONTH DO SELECT 1; +UPDATE mysql.event SET interval_field='MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +--error 1235 +SHOW CREATE EVENT micro_test2; +SET GLOBAL event_scheduler=0; +--sleep 1 +--echo "Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +UPDATE mysql.event SET interval_field='DAY_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +--error 1235 +SHOW CREATE EVENT micro_test2; +SET GLOBAL event_scheduler=0; +--sleep 1 +--echo "Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +UPDATE mysql.event SET interval_field='SECOND_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +--error 1235 +SHOW CREATE EVENT micro_test2; +SET GLOBAL event_scheduler=0; +--sleep 1 +--echo "Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +UPDATE mysql.event SET interval_field='HOUR_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +--error 1235 +SHOW CREATE EVENT micro_test2; +SET GLOBAL event_scheduler=0; +--sleep 1 +--echo "Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +UPDATE mysql.event SET interval_field='MINUTE_MICROSECOND' WHERE db=database() AND definer=user() AND name='micro_test2'; +--error 1235 +SHOW CREATE EVENT micro_test2; +SET GLOBAL event_scheduler=0; +--sleep 1 +--echo "Should not be running:" +SHOW VARIABLES like 'event_scheduler'; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='event_scheduler'; +DROP EVENT micro_test2; + +drop database events_test; diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test index 4a526935491..a5041a83623 100644 --- a/mysql-test/t/func_system.test +++ b/mysql-test/t/func_system.test @@ -19,7 +19,7 @@ select version()>=_latin1"3.23.29"; select charset(version()); explain extended select database(), user(); -create table t1 (version char(40)) select database(), user(), version() as 'version'; +create table t1 (version char(60)) select database(), user(), version() as 'version'; show create table t1; drop table t1; diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test index 430a3a5dd4a..ce1d0fb2271 100644 --- a/mysql-test/t/grant2.test +++ b/mysql-test/t/grant2.test @@ -429,3 +429,36 @@ disconnect con2root; disconnect con3root; # End of 4.1 tests + +# +# Bug#17279 user with no global privs and with create +# priv in db can create databases +# + +create database TESTDB; +create table t2(a int); +create temporary table t1 as select * from mysql.user; +delete from mysql.user where host='localhost'; +INSERT INTO mysql.user (host, user, password) VALUES +('%','mysqltest_1',password('password')); +INSERT INTO mysql.db (host, db, user, select_priv) VALUES +('%','TESTDB','mysqltest_1','Y'); +FLUSH PRIVILEGES; + +connect (con1,localhost,mysqltest_1,password,TESTDB); + +# The user mysqltest_1 should only be allowed access to +# database TESTDB, not TEStdb +# On system with "lowercase names" we get error "1007: Can't create db..." +--error 1044, 1007 +create database TEStdb; + +# Clean-up +connection default; +delete from mysql.user; +delete from mysql.db where host='%' and user='mysqltest_1' and db='TESTDB'; +insert into mysql.user select * from t1; +drop table t1, t2; +drop database TESTDB; +flush privileges; + diff --git a/mysql-test/t/index_merge.test b/mysql-test/t/index_merge.test index 10512902409..3da5711bf7a 100644 --- a/mysql-test/t/index_merge.test +++ b/mysql-test/t/index_merge.test @@ -357,3 +357,29 @@ explain select * from t1 WHERE cola = 'foo' AND colb = 'bar'; explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar'; drop table t1; +# +# BUG#17314: Index_merge/intersection not choosen by the optimizer for MERGE tables +# +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 ( + a int, b int, + filler1 char(200), filler2 char(200), + key(a),key(b) +); +insert into t1 select @v:= A.a, @v, 't1', 'filler2' from t0 A, t0 B, t0 C; +create table t2 like t1; + +create table t3 ( + a int, b int, + filler1 char(200), filler2 char(200), + key(a),key(b) +) engine=merge union=(t1,t2); + +--replace_column 9 # +explain select * from t1 where a=1 and b=1; +--replace_column 9 # +explain select * from t3 where a=1 and b=1; + +drop table t3; +drop table t0, t1, t2; diff --git a/mysql-test/t/innodb_notembedded.test b/mysql-test/t/innodb_notembedded.test index 1d8a590be78..53332d9fda4 100644 --- a/mysql-test/t/innodb_notembedded.test +++ b/mysql-test/t/innodb_notembedded.test @@ -1,6 +1,10 @@ -- source include/not_embedded.inc -- source include/have_innodb.inc +--disable_warnings +drop table if exists t1; +--enable_warnings + connect (a,localhost,root,,); connect (b,localhost,root,,); diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test index 553aaf987bb..90abc61ca07 100644 --- a/mysql-test/t/join.test +++ b/mysql-test/t/join.test @@ -523,6 +523,12 @@ select t1.b from v1a; -- error 1054 select * from v1a join v1b on t1.b = t2.b; +# +# Bug #17523 natural join and information_schema +# +select * from information_schema.statistics join information_schema.columns + using(table_name,column_name) where table_name='user'; + drop table t1; drop table t2; drop table t3; diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test index 34d2e7dbd54..fcd127e3e98 100644 --- a/mysql-test/t/loaddata.test +++ b/mysql-test/t/loaddata.test @@ -135,6 +135,6 @@ select @@character_set_filesystem; LOAD DATA INFILE 't@002d1' INTO TABLE t1; SELECT * FROM t1; DROP TABLE t1; ---exec rm $MYSQL_TEST_DIR/var/master-data/test/t@002d1 +--exec rm $MYSQLTEST_VARDIR/master-data/test/t@002d1 SET character_set_filesystem=default; select @@character_set_filesystem; diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test index 797d667b0a3..b61deeac001 100644 --- a/mysql-test/t/mysql_client_test.test +++ b/mysql-test/t/mysql_client_test.test @@ -9,7 +9,6 @@ # var/log/mysql_client_test.trace --disable_result_log ---exec echo $MYSQL_CLIENT_TEST --getopt-ll-test=25600M --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M # End of 4.1 tests diff --git a/mysql-test/t/mysql_protocols.test b/mysql-test/t/mysql_protocols.test index 0253c2b5d17..5eba780420c 100644 --- a/mysql-test/t/mysql_protocols.test +++ b/mysql-test/t/mysql_protocols.test @@ -1,5 +1,7 @@ # Embedded server doesn't support external clients --source include/not_embedded.inc +# Windows does not have SOCKET, but will try to create a PIPE as well as MEMORY +--source include/not_windows.inc # test for Bug #4998 "--protocol doesn't reject bad values" diff --git a/mysql-test/t/mysqlbinlog_base64.test b/mysql-test/t/mysqlbinlog_base64.test index 3aab767f9fa..66aaff83254 100644 --- a/mysql-test/t/mysqlbinlog_base64.test +++ b/mysql-test/t/mysqlbinlog_base64.test @@ -10,19 +10,19 @@ update t1 set a=a+2 where a=2; update t1 set a=a+2 where a=3; create table t2 (word varchar(20)); -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; # # Save binlog # ---exec $MYSQL_BINLOG --hexdump $MYSQL_TEST_DIR/var/log/master-bin.000001 > $MYSQL_TEST_DIR/var/tmp/mysqlbinlog_base64.sql +--exec $MYSQL_BINLOG --hexdump $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_base64.sql # # Clear database and restore from binlog # drop table t1; drop table t2; ---exec $MYSQL test < $MYSQL_TEST_DIR/var/tmp/mysqlbinlog_base64.sql +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqlbinlog_base64.sql # # Verify that all binlog events have been executed @@ -33,6 +33,6 @@ select * from t2; # # Test cleanup # ---exec rm $MYSQL_TEST_DIR/var/tmp/mysqlbinlog_base64.sql +--exec rm $MYSQLTEST_VARDIR/tmp/mysqlbinlog_base64.sql drop table t1; drop table t2; diff --git a/mysql-test/t/mysqlcheck.test b/mysql-test/t/mysqlcheck.test index 167ef435bee..61d64c733d7 100644 --- a/mysql-test/t/mysqlcheck.test +++ b/mysql-test/t/mysqlcheck.test @@ -5,6 +5,8 @@ # depends on the presence of the log tables (which are CSV-based). --source include/have_csv.inc +DROP SCHEMA test; +CREATE SCHEMA test; # # Bug #13783 mysqlcheck tries to optimize and analyze information_schema # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index dc711975569..b1ddfc97c70 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -840,11 +840,11 @@ DROP TABLE t1, t2; # Bugs #9136, #12917: problems with --defaults-extra-file option # ---exec echo "[mysqltest1]" > $MYSQLTEST_VARDIR/tmp/tmp.cnf ---exec echo "port=1234" >> $MYSQLTEST_VARDIR/tmp/tmp.cnf +--system echo "[mysqltest1]" > $MYSQLTEST_VARDIR/tmp/tmp.cnf +--system echo "port=1234" >> $MYSQLTEST_VARDIR/tmp/tmp.cnf --exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 --exec $MYSQL_MY_PRINT_DEFAULTS -e $MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 mysqltest1 ---exec rm $MYSQLTEST_VARDIR/tmp/tmp.cnf +--system rm $MYSQLTEST_VARDIR/tmp/tmp.cnf # # Test of fix to BUG 12597 @@ -960,15 +960,16 @@ set time_zone=default; # --disable_warnings DROP TABLE IF EXISTS `t1 test`; +DROP TABLE IF EXISTS `t2 test`; +--enable_warnings + CREATE TABLE `t1 test` ( `a1` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -DROP TABLE IF EXISTS `t2 test`; CREATE TABLE `t2 test` ( `a2` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ---enable_warnings DELIMITER //; CREATE TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN @@ -983,11 +984,10 @@ SELECT * FROM `t2 test`; # quoted --exec $MYSQL_DUMP --skip-comments --compatible=ansi --triggers test ---disable_warnings DROP TRIGGER `test trig`; DROP TABLE `t1 test`; DROP TABLE `t2 test`; ---enable_warnings + # # BUG# 12838 mysqldump -x with views exits with error # @@ -1050,6 +1050,84 @@ DROP TRIGGER tr1; DROP TABLE t1; # + +# +# Bug 14871 Invalid view dump output +# + +create table t1 (a int); +insert into t1 values (289), (298), (234), (456), (789); +create definer = CURRENT_USER view v1 as select * from t1; +create SQL SECURITY INVOKER view v2 as select * from t1; +create view v3 as select * from t1 with local check option; +create algorithm=merge view v4 as select * from t1 with cascaded check option; +create algorithm =temptable view v5 as select * from t1; + +# dump tables and views +--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug14871.sql + +# drop the db, tables and views +drop table t1; +drop view v1, v2, v3, v4, v5; + +# Reload dump +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug14871.sql + +# check that all tables and views could be created +show tables; +select * from v3 order by a; + +drop table t1; +drop view v1, v2, v3, v4, v5; + + +# +# Bug #16878 dump of trigger +# + +create table t1 (a int, created datetime); +create table t2 (b int, created datetime); +create trigger tr1 before insert on t1 for each row set +new.created=now(); +delimiter |; +create trigger tr2 after insert on t1 +for each row +begin + insert into t2 set b=new.a and created=new.created; +end| +delimiter ;| + +# dump table and trigger +--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug16878.sql +drop trigger tr1; +drop trigger tr2; +drop table t1, t2; + +# reload dump +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug16878.sql +--replace_column 6 # +show triggers; +drop trigger tr1; +drop trigger tr2; +drop table t1, t2; + + +# +# Bug#14857 Reading dump files with single statement stored routines fails. +# fixed by patch for bug#16878 +# +# +DELIMITER |; +/*!50003 CREATE FUNCTION `f`() RETURNS bigint(20) +return 42 */| +/*!50003 CREATE PROCEDURE `p`() +select 42 */| +DELIMITER ;| +show create function f; +show create procedure p; +drop function f; +drop procedure p; + # Added for use-thread option # create table t1 (a text , b text); diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index f78becc6868..f10e28327f5 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -431,7 +431,7 @@ echo ; # Illegal use of echo --error 1 ---exec echo "echo $;" | $MYSQL_TEST 2>&1 +--exec echo "echo \$;" | $MYSQL_TEST 2>&1 # ---------------------------------------------------------------------------- @@ -518,19 +518,19 @@ echo $novar1; --exec echo "let ;" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "let $=hi;" | $MYSQL_TEST 2>&1 +--exec echo "let \$=hi;" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "let $1 hi;" | $MYSQL_TEST 2>&1 +--exec echo "let \$1 hi;" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "let $m hi;" | $MYSQL_TEST 2>&1 +--exec echo "let \$m hi;" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "let $hi;" | $MYSQL_TEST 2>&1 +--exec echo "let \$hi;" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "let $ hi;" | $MYSQL_TEST 2>&1 +--exec echo "let \$ hi;" | $MYSQL_TEST 2>&1 --error 1 --exec echo "let =hi;" | $MYSQL_TEST 2>&1 @@ -664,10 +664,14 @@ real_sleep 1; # Missing parameter --error 1 --exec echo "sleep ;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "real_sleep ;" | $MYSQL_TEST 2>&1 # Illegal parameter --error 1 --exec echo "sleep abc;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "real_sleep abc;" | $MYSQL_TEST 2>&1 # ---------------------------------------------------------------------------- # Test inc diff --git a/mysql-test/t/ndb_alter_table_row.test b/mysql-test/t/ndb_alter_table_row.test index 5dbfa26289b..9c834e0dd20 100644 --- a/mysql-test/t/ndb_alter_table_row.test +++ b/mysql-test/t/ndb_alter_table_row.test @@ -13,10 +13,12 @@ engine=ndb; insert into t1 values (1,'one','one'), (2,'two','two'), (3,'three','three'); create index c on t1(c); connection server2; +show indexes from t1; select * from t1 where c = 'two'; connection server1; alter table t1 drop index c; connection server2; +show indexes from t1; select * from t1 where c = 'two'; connection server1; drop table t1; diff --git a/mysql-test/t/ndb_binlog_basic.test b/mysql-test/t/ndb_binlog_basic.test index 86443dcd831..640fac40bb6 100644 --- a/mysql-test/t/ndb_binlog_basic.test +++ b/mysql-test/t/ndb_binlog_basic.test @@ -19,7 +19,7 @@ create table t1 (a int primary key) engine=ndb; insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); save_master_pos; --replace_column 1 # -select @max_epoch:=max(epoch)-1 from cluster_replication.binlog_index; +select @max_epoch:=max(epoch)-1 from cluster.binlog_index; delete from t1; alter table t1 add (b int); @@ -38,12 +38,12 @@ drop table t2; # (save_master_pos waits for last gcp to complete, ensuring that we have # the expected data in the binlog) save_master_pos; -select inserts from cluster_replication.binlog_index where epoch > @max_epoch and inserts > 5; -select deletes from cluster_replication.binlog_index where epoch > @max_epoch and deletes > 5; +select inserts from cluster.binlog_index where epoch > @max_epoch and inserts > 5; +select deletes from cluster.binlog_index where epoch > @max_epoch and deletes > 5; select inserts,updates,deletes from - cluster_replication.binlog_index where epoch > @max_epoch and updates > 0; + cluster.binlog_index where epoch > @max_epoch and updates > 0; select schemaops from - cluster_replication.binlog_index where epoch > @max_epoch and schemaops > 0; + cluster.binlog_index where epoch > @max_epoch and schemaops > 0; # # check that purge clears the binlog_index @@ -51,7 +51,7 @@ select schemaops from flush logs; --sleep 1 purge master logs before now(); -select count(*) from cluster_replication.binlog_index; +select count(*) from cluster.binlog_index; # # several tables in different databases @@ -66,11 +66,11 @@ use test; insert into mysqltest.t1 values (2,1),(2,2); save_master_pos; --replace_column 1 # -select @max_epoch:=max(epoch)-1 from cluster_replication.binlog_index; +select @max_epoch:=max(epoch)-1 from cluster.binlog_index; drop table t1; drop database mysqltest; select inserts,updates,deletes from - cluster_replication.binlog_index where epoch > @max_epoch and inserts > 0; + cluster.binlog_index where epoch > @max_epoch and inserts > 0; select schemaops from - cluster_replication.binlog_index where epoch > @max_epoch and schemaops > 0; + cluster.binlog_index where epoch > @max_epoch and schemaops > 0; diff --git a/mysql-test/t/ndb_binlog_basic2.test b/mysql-test/t/ndb_binlog_basic2.test new file mode 100644 index 00000000000..9fa9f2f965a --- /dev/null +++ b/mysql-test/t/ndb_binlog_basic2.test @@ -0,0 +1,14 @@ +-- source include/have_ndb.inc + +--error ER_NDB_CANT_SWITCH_BINLOG_FORMAT +set session binlog_format=row; +--error ER_NDB_CANT_SWITCH_BINLOG_FORMAT +set session binlog_format=statement; +--error ER_NDB_CANT_SWITCH_BINLOG_FORMAT +set global binlog_format=row; +--error ER_NDB_CANT_SWITCH_BINLOG_FORMAT +set global binlog_format=statement; +--error ER_NDB_CANT_SWITCH_BINLOG_FORMAT +set session binlog_format=default; +--error ER_NDB_CANT_SWITCH_BINLOG_FORMAT +set global binlog_format=default; diff --git a/mysql-test/t/ndb_binlog_multi.test b/mysql-test/t/ndb_binlog_multi.test index 71edd70c14f..4bdc89fa3bd 100644 --- a/mysql-test/t/ndb_binlog_multi.test +++ b/mysql-test/t/ndb_binlog_multi.test @@ -14,7 +14,7 @@ drop table if exists t1,t2; # and sets up the replication correctly # -# no tables and nothing in cluster_replication.binlog_index; +# no tables and nothing in cluster.binlog_index; connection server1; SHOW TABLES; @@ -33,7 +33,7 @@ select * from t2 order by a; save_master_pos; --replace_column 1 <the_epoch> SELECT @the_epoch:=epoch,inserts,updates,deletes,schemaops FROM - cluster_replication.binlog_index ORDER BY epoch DESC LIMIT 1; + cluster.binlog_index ORDER BY epoch DESC LIMIT 1; let $the_epoch= `SELECT @the_epoch`; # see if we got something on server1 @@ -41,7 +41,7 @@ connection server1; SELECT * FROM t2 ORDER BY a; --replace_result $the_epoch <the_epoch> eval SELECT inserts,updates,deletes,schemaops FROM - cluster_replication.binlog_index WHERE epoch=$the_epoch; + cluster.binlog_index WHERE epoch=$the_epoch; # drop the table on server1 DROP TABLE t2; @@ -50,12 +50,12 @@ INSERT INTO t1 VALUES (1),(2); save_master_pos; --replace_column 1 <the_epoch2> SELECT @the_epoch2:=epoch,inserts,updates,deletes,schemaops FROM - cluster_replication.binlog_index ORDER BY epoch DESC LIMIT 1; + cluster.binlog_index ORDER BY epoch DESC LIMIT 1; let $the_epoch2= `SELECT @the_epoch2`; --replace_result $the_epoch <the_epoch> $the_epoch2 <the_epoch2> eval SELECT inserts,updates,deletes,schemaops FROM - cluster_replication.binlog_index WHERE epoch > $the_epoch AND epoch < $the_epoch2; + cluster.binlog_index WHERE epoch > $the_epoch AND epoch < $the_epoch2; drop table t1; # flush on server2 @@ -63,7 +63,7 @@ connection server2; SHOW TABLES; --replace_result $the_epoch <the_epoch> $the_epoch2 <the_epoch2> eval SELECT inserts,updates,deletes,schemaops FROM - cluster_replication.binlog_index WHERE epoch > $the_epoch AND epoch < $the_epoch2; + cluster.binlog_index WHERE epoch > $the_epoch AND epoch < $the_epoch2; # reset connection server1; diff --git a/mysql-test/t/ndb_cache_multi2.test b/mysql-test/t/ndb_cache_multi2.test index 5a78380097e..4abb537624a 100644 --- a/mysql-test/t/ndb_cache_multi2.test +++ b/mysql-test/t/ndb_cache_multi2.test @@ -10,6 +10,7 @@ drop table if exists t1, t2; # Turn on and reset query cache on server1 connection server1; +echo == Connected to server1 ==; set GLOBAL query_cache_type=on; set GLOBAL query_cache_size=1355776; set GLOBAL ndb_cache_check_time=1; @@ -18,6 +19,7 @@ flush status; # Turn on and reset query cache on server2 connection server2; +echo == Connected to server2 ==; set GLOBAL query_cache_type=on; set GLOBAL query_cache_size=1355776; set GLOBAL ndb_cache_check_time=1; @@ -27,11 +29,14 @@ flush status; # Create test tables in NDB and load them into cache # on server1 connection server1; +echo == Connected to server1 ==; create table t1 (a int) engine=ndbcluster; create table t2 (a int) engine=ndbcluster; insert into t1 value (2); insert into t2 value (3); select * from t1; +# Run the check query once to load it into qc on server1 +select a != 3 from t1; select * from t2; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; @@ -40,6 +45,7 @@ show status like "Qcache_hits"; # Connect server2, load table in to cache, then update the table connection server2; +echo == Connected to server2 ==; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; show status like "Qcache_hits"; @@ -49,12 +55,10 @@ show status like "Qcache_inserts"; show status like "Qcache_hits"; update t1 set a=3 where a=2; -# Connect to server1 and check that cache is invalidated +# Connect to server1 and check that cache is invalidated # and correct data is returned connection server1; -show status like "Qcache_queries_in_cache"; -show status like "Qcache_inserts"; -show status like "Qcache_hits"; +echo == Connected to server1 ==; # Loop and wait for max 10 seconds until query cache thread # has invalidated the cache and the column a in t1 is equal to 3 @@ -75,8 +79,6 @@ select * from t1; # There should now be three queries in the cache show status like "Qcache_queries_in_cache"; -# And inserts should be four -show status like "Qcache_inserts"; drop table t1, t2; diff --git a/mysql-test/t/ndb_config.test b/mysql-test/t/ndb_config.test index e40e89d76bd..4787abe86e2 100644 --- a/mysql-test/t/ndb_config.test +++ b/mysql-test/t/ndb_config.test @@ -4,7 +4,7 @@ --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=type,nodeid,host 2> /dev/null --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid,host,DataMemory,IndexMemory --type=ndbd 2> /dev/null ---exec $NDB_TOOLS_DIR/ndb_config --no-defaults -r \\n -f " " --query=nodeid,host,DataMemory,IndexMemory --type=ndbd 2> /dev/null +--exec $NDB_TOOLS_DIR/ndb_config --no-defaults -r \\\n -f " " --query=nodeid,host,DataMemory,IndexMemory --type=ndbd 2> /dev/null --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=nodeid --type=ndbd --host=localhost 2> /dev/null --exec $NDB_TOOLS_DIR/ndb_config --no-defaults --query=type,nodeid,host --config-file=$NDB_BACKUP_DIR/config.ini 2> /dev/null diff --git a/mysql-test/t/ndb_dd_dump.test b/mysql-test/t/ndb_dd_dump.test index e44822e83c4..13d4fd86396 100644 --- a/mysql-test/t/ndb_dd_dump.test +++ b/mysql-test/t/ndb_dd_dump.test @@ -177,7 +177,7 @@ INSERT INTO t2 VALUES INSERT INTO t3 VALUES (1,1,1); ---exec $MYSQL_DUMP --skip-comments --compact -Y test > var/tmp/ndb_dd_dump.sql +--exec $MYSQL_DUMP --skip-comments --compact -Y test > $MYSQLTEST_VARDIR/tmp/ndb_dd_dump.sql DROP TABLE t1; DROP TABLE t2; @@ -206,7 +206,7 @@ DROP TABLESPACE ts3 ENGINE = NDB; DROP LOGFILE GROUP lg1 ENGINE = NDB; DROP LOGFILE GROUP lg2 ENGINE = NDB; ---exec $MYSQL test < var/tmp/ndb_dd_dump.sql +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/ndb_dd_dump.sql SELECT DISTINCT LOGFILE_GROUP_NAME, diff --git a/mysql-test/t/ndb_load.test b/mysql-test/t/ndb_load.test index 72a5b53eaad..af2df70b74e 100644 --- a/mysql-test/t/ndb_load.test +++ b/mysql-test/t/ndb_load.test @@ -12,12 +12,12 @@ DROP TABLE IF EXISTS t1; # should give duplicate key CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB; --error 1022 -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1 ; DROP TABLE t1; # now without a primary key we should be ok CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=NDB; -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1 ; SELECT * FROM t1 ORDER BY word; DROP TABLE t1; diff --git a/mysql-test/t/ndb_partition_error.test b/mysql-test/t/ndb_partition_error.test index cf570cc0234..c84266b66f7 100644 --- a/mysql-test/t/ndb_partition_error.test +++ b/mysql-test/t/ndb_partition_error.test @@ -44,3 +44,15 @@ partitions 3 partition x3 values less than (20)); drop table t1; + +# +# Bug #17763 mysqld cores with list partitioning if update to missing partition +# +CREATE TABLE t1 (id INT) ENGINE=NDB + PARTITION BY LIST(id) + (PARTITION p0 VALUES IN (2, 4), + PARTITION p1 VALUES IN (42, 142)); +INSERT INTO t1 VALUES (2); +--error ER_NO_PARTITION_FOR_GIVEN_VALUE +UPDATE t1 SET id=5 WHERE id=2; +DROP TABLE t1; diff --git a/mysql-test/t/ndb_partition_range.test b/mysql-test/t/ndb_partition_range.test index 2eb324ccdcb..981467d4055 100644 --- a/mysql-test/t/ndb_partition_range.test +++ b/mysql-test/t/ndb_partition_range.test @@ -93,3 +93,168 @@ show create table t1; drop table t1; +# +# Bug #17499, #17687 +# Alter partitioned NDB table causes mysqld to core +# + +CREATE TABLE t1 + (id MEDIUMINT NOT NULL, + b1 BIT(8), + vc VARCHAR(255), + bc CHAR(255), + d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, + total BIGINT UNSIGNED, + y YEAR, + t DATE) ENGINE=NDB + PARTITION BY RANGE (YEAR(t)) + (PARTITION p0 VALUES LESS THAN (1901), + PARTITION p1 VALUES LESS THAN (1946), + PARTITION p2 VALUES LESS THAN (1966), + PARTITION p3 VALUES LESS THAN (1986), + PARTITION p4 VALUES LESS THAN (2005), + PARTITION p5 VALUES LESS THAN MAXVALUE); + +INSERT INTO t1 VALUES (0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); +SELECT * FROM t1; +ALTER TABLE t1 ENGINE=MYISAM; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE LOGFILE GROUP lg1 + ADD UNDOFILE 'undofile.dat' + INITIAL_SIZE 16M + UNDO_BUFFER_SIZE=1M + ENGINE=NDB; + +CREATE TABLESPACE ts1 + ADD DATAFILE 'datafile.dat' + USE LOGFILE GROUP lg1 + INITIAL_SIZE 12M + ENGINE NDB; + +CREATE TABLE test.t1 ( + a1 INT, + a2 TEXT NOT NULL, + a3 BIT NOT NULL, + a4 DECIMAL(8,3), + a5 INT NOT NULL, + a6 INT, + PRIMARY KEY(a1)) + TABLESPACE ts1 STORAGE DISK ENGINE=NDB + PARTITION BY LIST (a1) + (PARTITION p0 VALUES IN (1,2,3,4,5), + PARTITION p1 VALUES IN (6,7,8,9, 10), + PARTITION p2 VALUES IN (11, 12, 13, 14, 15)); + +# Alter table directly without any statements inbetween +ALTER TABLE test.t1 DROP COLUMN a6; +ALTER TABLE test.t1 ADD COLUMN a6 VARCHAR(255); + +let $j= 15; +--disable_query_log +while ($j) +{ +eval INSERT INTO test.t1 VALUES ($j, "Tested Remotely from Texas, USA", +b'1',$j.00,$j+1,"By NIK $j"); +dec $j; +} +--enable_query_log +SELECT COUNT(*) FROM test.t1; + +ALTER TABLE test.t1 DROP COLUMN a4; +SELECT COUNT(*) FROM test.t1; + +DROP TABLE t1; + +CREATE TABLE test.t1 ( + a1 INT, + a2 TEXT NOT NULL, + a3 BIT NOT NULL, + a4 DECIMAL(8,3), + a5 INT NOT NULL, + a6 VARCHAR(255), + PRIMARY KEY(a1)) + TABLESPACE ts1 STORAGE DISK ENGINE=NDB + PARTITION BY HASH(a1) + PARTITIONS 4; + +let $j= 15; +--disable_query_log +while ($j) +{ +eval INSERT INTO test.t1 VALUES ($j, "Tested Remotely from Texas, USA", +b'1',$j.00,$j+1,"By NIK $j"); +dec $j; +} +--enable_query_log +SELECT COUNT(*) FROM test.t1; + +ALTER TABLE test.t1 DROP COLUMN a4; +SELECT COUNT(*) FROM test.t1; + +DROP TABLE t1; + +ALTER TABLESPACE ts1 + DROP DATAFILE 'datafile.dat' + ENGINE=NDB; +DROP TABLESPACE ts1 ENGINE=NDB; +DROP LOGFILE GROUP lg1 ENGINE=NDB; + + +# +# Bug #17701 ALTER TABLE t1 ADD PARTITION for PARTITION BY LIST hangs test +# + +CREATE TABLE t1 + (id MEDIUMINT NOT NULL, + b1 BIT(8), + vc VARCHAR(255), + bc CHAR(255), + d DECIMAL(10,4) DEFAULT 0, + f FLOAT DEFAULT 0, + total BIGINT UNSIGNED, + y YEAR, + t DATE) ENGINE=NDB + PARTITION BY LIST(id) + (PARTITION p0 VALUES IN (2, 4), + PARTITION p1 VALUES IN (42, 142)); + +INSERT INTO t1 VALUES (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); +SELECT * FROM t1; +ALTER TABLE t1 ADD PARTITION + (PARTITION p2 VALUES IN (412)); +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug #17806 Update on NDB table with list partition causes mysqld to core +# Bug #16385 Partitions: crash when updating a range partitioned NDB table +# +CREATE TABLE t1 ( +a int not null, +b int not null, +c int not null) +partition by list(a) +partitions 2 +(partition x123 values in (1,5,6), + partition x234 values in (4,7,8)); +INSERT into t1 VALUES (5,1,1); +select * from t1; +UPDATE t1 SET a=8 WHERE a=5 AND b=1; +select * from t1; +drop table t1; + +CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) engine=ndb +PARTITION BY RANGE(f1) +( PARTITION part1 VALUES LESS THAN (2), +PARTITION part2 VALUES LESS THAN (1000)); +INSERT INTO t1 VALUES(1, '---1---'); +INSERT INTO t1 VALUES(2, '---2---'); +select * from t1 order by f1; +UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2; +select * from t1 order by f1; +UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1; +select * from t1 order by f1; +drop table t1; diff --git a/mysql-test/t/ndb_restore.test b/mysql-test/t/ndb_restore.test index f340b62adae..dc28a9f5408 100644 --- a/mysql-test/t/ndb_restore.test +++ b/mysql-test/t/ndb_restore.test @@ -143,10 +143,10 @@ create table t8 engine=myisam as select * from t8_c; create table t9 engine=myisam as select * from t9_c; ---exec $NDB_MGM --no-defaults -e "start backup" >> $NDB_TOOLS_OUTPUT +--source include/ndb_backup.inc drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 1 -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-1 >> $NDB_TOOLS_OUTPUT ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 1 -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-1 >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT # random output order?? #show tables; @@ -230,10 +230,10 @@ PARTITIONS 4; ALTER TABLE t7_c PARTITION BY LINEAR KEY (`dardtestard`); ---exec $NDB_MGM --no-defaults -e "start backup" >> $NDB_TOOLS_OUTPUT +--source include/ndb_backup.inc drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 2 -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-2 >> $NDB_TOOLS_OUTPUT ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 2 -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-2 >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT select count(*) from t1; select count(*) from t1_c; @@ -290,8 +290,8 @@ select count(*) select * from t9_c) a; drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 2 -n 1 -m -r --ndb-nodegroup_map '(0,0)' --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-2 >> $NDB_TOOLS_OUTPUT ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b 2 -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-2 >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -m -r --ndb-nodegroup_map '(0,0)' --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT select count(*) from t1; select count(*) from t1_c; @@ -348,7 +348,7 @@ select count(*) select * from t9_c) a; drop table t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; ---exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --core=0 -b 2 -n 1 -m -r --ndb-nodegroup_map '(0,1)' $NDB_BACKUP_DIR/BACKUP/BACKUP-2 2>&1 | grep Translate || true +--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --core=0 -b $the_backup_id -n 1 -m -r --ndb-nodegroup_map '(0,1)' $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id 2>&1 | grep Translate || true # # Cleanup @@ -363,6 +363,6 @@ drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c; # Test BUG#10287 # ---exec $NDB_TOOLS_DIR/ndb_select_all --no-defaults -d sys -D , SYSTAB_0 | grep 520093696 +--exec $NDB_TOOLS_DIR/ndb_select_all --no-defaults -d sys -D , SYSTAB_0 | grep 520093696, | sed "s/,$the_backup_id/,<the_backup_id>/" # End of 4.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 4760219c911..47c25652ae9 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -408,4 +408,79 @@ create table t1 (s1 int, unique (s1)) partition by list (s1) (partition x1 VALUE alter table t1 add partition (partition x3 values in (30)); drop table t1; +# +# Bug #17432: Partition functions containing NULL values should return +# LONGLONG_MIN +# +CREATE TABLE t1 ( + f_int1 INTEGER, f_int2 INTEGER, + f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000) + ) + PARTITION BY RANGE(f_int1 DIV 2) + SUBPARTITION BY HASH(f_int1) + SUBPARTITIONS 2 + (PARTITION parta VALUES LESS THAN (0), + PARTITION partb VALUES LESS THAN (5), + PARTITION parte VALUES LESS THAN (10), + PARTITION partf VALUES LESS THAN (2147483647)); +INSERT INTO t1 SET f_int1 = NULL , f_int2 = -20, f_char1 = CAST(-20 AS CHAR), + f_char2 = CAST(-20 AS CHAR), f_charbig = '#NULL#'; +SELECT * FROM t1 WHERE f_int1 IS NULL; +SELECT * FROM t1; +drop table t1; + +# +# Bug 17430: Crash when SELECT * from t1 where field IS NULL +# + +CREATE TABLE t1 ( + f_int1 INTEGER, f_int2 INTEGER, + f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000) ) + PARTITION BY LIST(MOD(f_int1,2)) + SUBPARTITION BY KEY(f_int1) + (PARTITION part1 VALUES IN (-1) (SUBPARTITION sp1, SUBPARTITION sp2), + PARTITION part2 VALUES IN (0) (SUBPARTITION sp3, SUBPARTITION sp5), + PARTITION part3 VALUES IN (1) (SUBPARTITION sp4, SUBPARTITION sp6)); + +INSERT INTO t1 SET f_int1 = 2, f_int2 = 2, f_char1 = '2', f_char2 = '2', f_charbig = '===2==='; +INSERT INTO t1 SET f_int1 = 2, f_int2 = 2, f_char1 = '2', f_char2 = '2', f_charbig = '===2==='; + +SELECT * FROM t1 WHERE f_int1 IS NULL; +drop table t1; + +# +# Bug#14363 Partitions: failure if create in stored procedure +# +delimiter //; + +create procedure p () +begin +create table t1 (s1 mediumint,s2 mediumint) +partition by list (s2) +(partition p1 values in (0), + partition p2 values in (1)); +end// + +call p()// +drop procedure p// +drop table t1; + +create procedure p () +begin +create table t1 (a int not null,b int not null,c int not null,primary key (a,b)) +partition by range (a) +subpartition by hash (a+b) +(partition x1 values less than (1) + (subpartition x11, + subpartition x12), + partition x2 values less than (5) + (subpartition x21, + subpartition x22)); +end// + +call p()// +drop procedure p// +drop table t1// +delimiter ;// + --echo End of 5.1 tests diff --git a/mysql-test/t/partition_charset.test b/mysql-test/t/partition_charset.test new file mode 100644 index 00000000000..27d0dc87b89 --- /dev/null +++ b/mysql-test/t/partition_charset.test @@ -0,0 +1,21 @@ +# +# Test for character set related things in combination +# with the partition storage engine +# +-- source include/have_partition.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +set names utf8; +create table t1 (s1 int) + partition by list (s1) + (partition c values in (1), + partition Ç values in (3)); +insert into t1 values (1),(3); +select * from t1; +flush tables; +set names latin1; +select * from t1; +drop table t1; diff --git a/mysql-test/t/partition_mgm_err.test b/mysql-test/t/partition_mgm_err.test index 1a24129bcf1..f72222feadd 100644 --- a/mysql-test/t/partition_mgm_err.test +++ b/mysql-test/t/partition_mgm_err.test @@ -169,23 +169,6 @@ ALTER TABLE t1 DROP PARTITION x0; DROP TABLE t1; # -# BUG: 14354 Partitions: data directory clause fails -# ---exec rm -rf $MYSQL_TEST_DIR/bug14354 ---exec mkdir $MYSQL_TEST_DIR/bug14354 -disable_query_log; -eval CREATE TABLE t1 (id int) PARTITION BY RANGE(id) ( -PARTITION p1 VALUES LESS THAN (20) ENGINE=myiasm -DATA DIRECTORY="$MYSQL_TEST_DIR/bug14354" -INDEX DIRECTORY="$MYSQL_TEST_DIR/bug14354"); -enable_query_log; -INSERT INTO t1 VALUES (15); ---exec test -f $MYSQL_TEST_DIR/bug14354/t1#P#p1.MYD ---exec test -f $MYSQL_TEST_DIR/bug14354/t1#P#p1.MYI -DROP TABLE t1; ---exec rm -rf $MYSQL_TEST_DIR/bug14354 - -# # Bug# 16534 - Trying to add multiple partitions crashes server # CREATE TABLE t1 ( id INT NOT NULL, @@ -216,3 +199,13 @@ DROP TABLE t1; # CREATE TABLE t1 (a INT) PARTITION BY HASH(a); ALTER TABLE t1 ADD PARTITION PARTITIONS 4; +DROP TABLE t1; + +# +#BUG 15408: Partitions: subpartition names are not unique +# +--error ER_SAME_NAME_PARTITION +CREATE TABLE t1 (s1 int, s2 int) PARTITION BY LIST (s1) ( +PARTITION p1 VALUES IN (0) (SUBPARTITION p1b), +PARTITION p2 VALUES IN (2) (SUBPARTITION p1b) +); diff --git a/mysql-test/t/partition_mgm_err2.test b/mysql-test/t/partition_mgm_err2.test new file mode 100644 index 00000000000..157ba4d70d2 --- /dev/null +++ b/mysql-test/t/partition_mgm_err2.test @@ -0,0 +1,25 @@ +# +# Test of partitions that require symlinks +# + +-- require r/have_symlink.require +disable_query_log; +show variables like "have_symlink"; +enable_query_log; + +# +# BUG: 14354 Partitions: data directory clause fails +# +--system rm -rf $MYSQLTEST_VARDIR/tmp/bug14354 +--system mkdir $MYSQLTEST_VARDIR/tmp/bug14354 +disable_query_log; +eval CREATE TABLE t1 (id int) PARTITION BY RANGE(id) ( +PARTITION p1 VALUES LESS THAN (20) ENGINE=myiasm +DATA DIRECTORY="$MYSQLTEST_VARDIR/tmp/bug14354" +INDEX DIRECTORY="$MYSQLTEST_VARDIR/tmp/bug14354"); +enable_query_log; +INSERT INTO t1 VALUES (15); +--system test -f $MYSQLTEST_VARDIR/tmp/bug14354/t1#P#p1.MYD +--system test -f $MYSQLTEST_VARDIR/tmp/bug14354/t1#P#p1.MYI +DROP TABLE t1; +--system rm -rf $MYSQLTEST_VARDIR/tmp/bug14354 diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 48a9f4c19f3..ffbba991fb6 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -900,6 +900,27 @@ execute stmt using @like; deallocate prepare stmt; drop table t1; +# +# Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is +# recreated with PS/SP" +# + +prepare stmt from 'create table t1 (a varchar(10) character set utf8)'; +execute stmt; +--disable_warnings +insert into t1 (a) values (repeat('a', 20)); +--enable_warnings +select length(a) from t1; +drop table t1; +execute stmt; +--disable_warnings +insert into t1 (a) values (repeat('a', 20)); +--enable_warnings +# Check that the data is truncated to the same length +select length(a) from t1; +drop table t1; +deallocate prepare stmt; + # End of 4.1 tests # diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index 15559d75d6c..7596a7ba708 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -12,7 +12,7 @@ flush query cache; # This crashed in some versions reset query cache; flush status; --disable_warnings -drop table if exists t1,t2,t3,t4,t11,t21; +drop table if exists t1,t2,t3,t4,t11,t21,t1_1,t1_2,t9,t9_1,t9_2; drop database if exists mysqltest; # Fix possible left overs from other tests diff --git a/mysql-test/t/rpl_000015.test b/mysql-test/t/rpl_000015.test index aa866e006e0..cf93beb2bfe 100644 --- a/mysql-test/t/rpl_000015.test +++ b/mysql-test/t/rpl_000015.test @@ -18,7 +18,7 @@ show slave status; change master to master_host='127.0.0.1'; # The following needs to be cleaned up when change master is fixed ---replace_result $MASTER_MYPORT MASTER_PORT $MYSQL_TCP_PORT MASTER_PORT +--replace_result $MYSQL_TCP_PORT MASTER_PORT --replace_column 1 # 8 # 9 # 23 # 33 # show slave status; --replace_result $MASTER_MYPORT MASTER_PORT diff --git a/mysql-test/t/rpl_LD_INFILE.test b/mysql-test/t/rpl_LD_INFILE.test index ae647ed6648..bace5d4c1f5 100644 --- a/mysql-test/t/rpl_LD_INFILE.test +++ b/mysql-test/t/rpl_LD_INFILE.test @@ -16,10 +16,10 @@ DROP TABLE IF EXISTS test.t1; # Section 1 test CREATE TABLE test.t1 (a VARCHAR(255), PRIMARY KEY(a)); -LOAD DATA INFILE '../../std_data/words2.dat' INTO TABLE test.t1; +LOAD DATA INFILE '../std_data_ln/words2.dat' INTO TABLE test.t1; DELETE FROM test.t1 WHERE a = 'abashed'; DELETE FROM test.t1; -LOAD DATA INFILE '../../std_data/words2.dat' INTO TABLE test.t1; +LOAD DATA INFILE '../std_data_ln/words2.dat' INTO TABLE test.t1; SELECT * FROM test.t1 ORDER BY a DESC; diff --git a/mysql-test/t/rpl_alter_db.test b/mysql-test/t/rpl_alter_db.test new file mode 100644 index 00000000000..5ac8a2f4018 --- /dev/null +++ b/mysql-test/t/rpl_alter_db.test @@ -0,0 +1,10 @@ +source include/master-slave.inc; +connection master; +use mysql; # to be different from initial `test' db of mysqltest client +alter database collate latin1_bin; +save_master_pos; + +connection slave; +sync_with_master; + + diff --git a/mysql-test/t/rpl_drop_db.test b/mysql-test/t/rpl_drop_db.test index df17ec88aaa..38ad07f72f1 100644 --- a/mysql-test/t/rpl_drop_db.test +++ b/mysql-test/t/rpl_drop_db.test @@ -46,7 +46,7 @@ show tables; use test; select * from t1; -system rm var/master-data/mysqltest1/f1.txt; +system rm $MYSQLTEST_VARDIR/master-data/mysqltest1/f1.txt; connection master; DROP DATABASE mysqltest1; sync_slave_with_master; diff --git a/mysql-test/t/rpl_load_table_from_master.test b/mysql-test/t/rpl_load_table_from_master.test index aad113878d3..b9cec3858a9 100644 --- a/mysql-test/t/rpl_load_table_from_master.test +++ b/mysql-test/t/rpl_load_table_from_master.test @@ -71,9 +71,9 @@ sync_with_master; connection master; set SQL_LOG_BIN=0; create table t1 (word char(20) not null, index(word))ENGINE=MyISAM; -load data infile '../../std_data/words.dat' into table t1; +load data infile '../std_data_ln/words.dat' into table t1; create table t2 (word char(20) not null)ENGINE=MyISAM; -load data infile '../../std_data/words.dat' into table t2; +load data infile '../std_data_ln/words.dat' into table t2; create table t3 (word char(20) not null primary key)ENGINE=MyISAM; connection slave; load table t1 from master; diff --git a/mysql-test/t/rpl_loaddata2.test b/mysql-test/t/rpl_loaddata2.test index 439c2b48ca5..9e908cac677 100644 --- a/mysql-test/t/rpl_loaddata2.test +++ b/mysql-test/t/rpl_loaddata2.test @@ -1,7 +1,7 @@ --source include/master-slave.inc CREATE TABLE t1 (word CHAR(20) NOT NULL); -LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; SELECT * FROM t1 ORDER BY word; sync_slave_with_master; diff --git a/mysql-test/t/rpl_loaddata_m.test b/mysql-test/t/rpl_loaddata_m.test index 42c3ad99f33..537d4c163ef 100644 --- a/mysql-test/t/rpl_loaddata_m.test +++ b/mysql-test/t/rpl_loaddata_m.test @@ -17,14 +17,14 @@ connection master; # 'test' database should be ignored by the slave USE test; CREATE TABLE t1(a INT, b INT, UNIQUE(b)); -LOAD DATA INFILE '../../std_data/rpl_loaddata.dat' INTO TABLE test.t1; +LOAD DATA INFILE '../std_data_ln/rpl_loaddata.dat' INTO TABLE test.t1; SELECT COUNT(*) FROM test.t1; # 'mysqltest' database should NOT be ignored by the slave CREATE DATABASE mysqltest; USE mysqltest; CREATE TABLE t1(a INT, b INT, UNIQUE(b)); -LOAD DATA INFILE '../../std_data/rpl_loaddata.dat' INTO TABLE mysqltest.t1; +LOAD DATA INFILE '../std_data_ln/rpl_loaddata.dat' INTO TABLE mysqltest.t1; SELECT COUNT(*) FROM mysqltest.t1; # Now lets check the slave to see what we have :-) diff --git a/mysql-test/t/rpl_loadfile.test b/mysql-test/t/rpl_loadfile.test index 598e89586b2..a671bab15bb 100644 --- a/mysql-test/t/rpl_loadfile.test +++ b/mysql-test/t/rpl_loadfile.test @@ -24,12 +24,12 @@ DROP TABLE IF EXISTS test.t1; CREATE TABLE test.t1 (a INT, blob_column LONGBLOB, PRIMARY KEY(a)); INSERT INTO test.t1 VALUES(1,'test'); -UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=1; +UPDATE test.t1 SET blob_column=LOAD_FILE('../std_data_ln/words2.dat') WHERE a=1; delimiter |; create procedure test.p1() begin INSERT INTO test.t1 VALUES(2,'test'); - UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=2; + UPDATE test.t1 SET blob_column=LOAD_FILE('../std_data_ln/words2.dat') WHERE a=2; end| delimiter ;| diff --git a/mysql-test/t/rpl_ndb_2innodb-master.opt b/mysql-test/t/rpl_ndb_2innodb-master.opt new file mode 100644 index 00000000000..f31d53c3cb1 --- /dev/null +++ b/mysql-test/t/rpl_ndb_2innodb-master.opt @@ -0,0 +1 @@ +--default-storage-engine=ndb --binlog-format=row diff --git a/mysql-test/t/rpl_ndb_2innodb-slave.opt b/mysql-test/t/rpl_ndb_2innodb-slave.opt new file mode 100644 index 00000000000..ee81186c513 --- /dev/null +++ b/mysql-test/t/rpl_ndb_2innodb-slave.opt @@ -0,0 +1 @@ +--innodb --default-storage-engine=innodb --binlog-format=row diff --git a/mysql-test/t/rpl_ndb_2innodb.test b/mysql-test/t/rpl_ndb_2innodb.test new file mode 100644 index 00000000000..e09d8b6685b --- /dev/null +++ b/mysql-test/t/rpl_ndb_2innodb.test @@ -0,0 +1,16 @@ +############################################################# +# Author: JBM +# Date: 2006-02-24 +# Purpose: Trying to test ability to replicate from cluster +# to innodb, or myisam, or replicate from innodb/myisam to +# cluster slave. Due to limitations I have created wrappers +# to be able to use the same code for all these different +# test and to have control over the tests. +############################################################## +-- source include/have_ndb.inc +-- source include/master-slave.inc +connection slave; +-- source include/have_innodb.inc +connection master; +SET storage_engine=ndb; +--source extra/rpl_tests/rpl_ndb_2multi_eng.test diff --git a/mysql-test/t/rpl_ndb_2myisam-master.opt b/mysql-test/t/rpl_ndb_2myisam-master.opt new file mode 100644 index 00000000000..f31d53c3cb1 --- /dev/null +++ b/mysql-test/t/rpl_ndb_2myisam-master.opt @@ -0,0 +1 @@ +--default-storage-engine=ndb --binlog-format=row diff --git a/mysql-test/t/rpl_ndb_2myisam-slave.opt b/mysql-test/t/rpl_ndb_2myisam-slave.opt new file mode 100644 index 00000000000..59de63c0da2 --- /dev/null +++ b/mysql-test/t/rpl_ndb_2myisam-slave.opt @@ -0,0 +1 @@ +--default-storage-engine=myisam --binlog-format=row diff --git a/mysql-test/t/rpl_ndb_2myisam.test b/mysql-test/t/rpl_ndb_2myisam.test new file mode 100644 index 00000000000..abbe419bc02 --- /dev/null +++ b/mysql-test/t/rpl_ndb_2myisam.test @@ -0,0 +1,13 @@ +############################################################# +# Author: JBM +# Date: 2006-02-24 +# Purpose: Trying to test ability to replicate from cluster +# to innodb, or myisam, or replicate from innodb/myisam to +# cluster slave. Due to limitations I have created wrappers +# to be able to use the same code for all these different +# test and to have control over the tests. +############################################################## +-- source include/have_ndb.inc +-- source include/master-slave.inc +SET storage_engine=ndb; +--source extra/rpl_tests/rpl_ndb_2multi_eng.test diff --git a/mysql-test/t/rpl_ndb_bank.test b/mysql-test/t/rpl_ndb_bank.test index 817f40f2fa3..102450fce91 100644 --- a/mysql-test/t/rpl_ndb_bank.test +++ b/mysql-test/t/rpl_ndb_bank.test @@ -117,12 +117,12 @@ RESET MASTER; --exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT # there is no neat way to find the backupid, this is a hack to find it... ---exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > var/tmp.dat -CREATE TABLE IF NOT EXISTS cluster_replication.backup_info (id INT, backup_id INT) ENGINE = HEAP; -DELETE FROM cluster_replication.backup_info; -LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE cluster_replication.backup_info FIELDS TERMINATED BY ','; +--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat +CREATE TABLE IF NOT EXISTS cluster.backup_info (id INT, backup_id INT) ENGINE = HEAP; +DELETE FROM cluster.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE cluster.backup_info FIELDS TERMINATED BY ','; --replace_column 1 <the_backup_id> -SELECT @the_backup_id:=backup_id FROM cluster_replication.backup_info; +SELECT @the_backup_id:=backup_id FROM cluster.backup_info; let the_backup_id=`select @the_backup_id`; # restore on slave, first check that nothing is there @@ -140,7 +140,7 @@ let the_backup_id=`select @the_backup_id`; # 1. --connection slave --replace_column 1 <the_epoch> -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; --let $the_epoch= `select @the_epoch` # 2. @@ -148,7 +148,7 @@ SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; --replace_result $the_epoch <the_epoch> --replace_column 1 <the_pos> eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) - FROM cluster_replication.binlog_index WHERE epoch > $the_epoch ORDER BY epoch ASC LIMIT 1; + FROM cluster.binlog_index WHERE epoch > $the_epoch ORDER BY epoch ASC LIMIT 1; --let $the_pos= `SELECT @the_pos` --let $the_file= `SELECT @the_file` @@ -191,17 +191,17 @@ while ($1) # 1. dump database BANK on both master and slave # 2. compare, there should be no difference # ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info BANK ACCOUNT_TYPE ACCOUNT GL TRANSACTION > ./var/tmp/master_BANK.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info BANK ACCOUNT_TYPE ACCOUNT GL TRANSACTION > $MYSQLTEST_VARDIR/tmp/master_BANK.sql --connection master use test; create table t1 (a int primary key) engine=ndb; insert into t1 values (1); --sync_slave_with_master ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info BANK ACCOUNT_TYPE ACCOUNT GL TRANSACTION > ./var/tmp/slave_BANK.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info BANK ACCOUNT_TYPE ACCOUNT GL TRANSACTION > $MYSQLTEST_VARDIR/tmp/slave_BANK.sql --connection master drop table t1; ---exec diff ./var/tmp/master_BANK.sql ./var/tmp/slave_BANK.sql +--exec diff $MYSQLTEST_VARDIR/tmp/master_BANK.sql $MYSQLTEST_VARDIR/tmp/slave_BANK.sql --dec $2 } diff --git a/mysql-test/t/rpl_ndb_idempotent.test b/mysql-test/t/rpl_ndb_idempotent.test index bb33dfaf701..1a2c29079b1 100644 --- a/mysql-test/t/rpl_ndb_idempotent.test +++ b/mysql-test/t/rpl_ndb_idempotent.test @@ -4,7 +4,7 @@ # # Currently test only works with ndb since it retrieves "old" -# binlog positions with cluster_replication.binlog_index and apply_status; +# binlog positions with cluster.binlog_index and apply_status; # # create a table with one row @@ -15,7 +15,7 @@ SELECT * FROM t1 ORDER BY c3; # sync slave and retrieve epoch sync_slave_with_master; --replace_column 1 <the_epoch> -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; let $the_epoch= `select @the_epoch` ; SELECT * FROM t1 ORDER BY c3; @@ -24,7 +24,7 @@ connection master; --replace_result $the_epoch <the_epoch> --replace_column 1 <the_pos> eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) - FROM cluster_replication.binlog_index WHERE epoch = $the_epoch ; + FROM cluster.binlog_index WHERE epoch = $the_epoch ; let $the_pos= `SELECT @the_pos` ; let $the_file= `SELECT @the_file` ; diff --git a/mysql-test/t/rpl_ndb_innodb2ndb-master.opt b/mysql-test/t/rpl_ndb_innodb2ndb-master.opt new file mode 100644 index 00000000000..248f9e60566 --- /dev/null +++ b/mysql-test/t/rpl_ndb_innodb2ndb-master.opt @@ -0,0 +1 @@ +--innodb --binlog-format=row diff --git a/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt b/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt new file mode 100644 index 00000000000..f47e5a7e98f --- /dev/null +++ b/mysql-test/t/rpl_ndb_innodb2ndb-slave.opt @@ -0,0 +1 @@ +--binlog-format=row --default-storage-engine=ndb diff --git a/mysql-test/t/rpl_ndb_innodb2ndb.test b/mysql-test/t/rpl_ndb_innodb2ndb.test new file mode 100644 index 00000000000..229ee11353b --- /dev/null +++ b/mysql-test/t/rpl_ndb_innodb2ndb.test @@ -0,0 +1,16 @@ +############################################################# +# Author: JBM +# Date: 2006-02-24 +# Purpose: Trying to test ability to replicate from cluster +# to innodb, or myisam, or replicate from innodb/myisam to +# cluster slave. Due to limitations I have created wrappers +# to be able to use the same code for all these different +# test and to have control over the tests. +############################################################## +-- source include/have_innodb.inc +-- source include/master-slave.inc +connection slave; +-- source include/have_ndb.inc +connection master; +SET storage_engine=innodb; +--source extra/rpl_tests/rpl_ndb_2multi_eng.test diff --git a/mysql-test/t/rpl_ndb_multi.test b/mysql-test/t/rpl_ndb_multi.test index 81f0f318505..fc7ecab00ac 100644 --- a/mysql-test/t/rpl_ndb_multi.test +++ b/mysql-test/t/rpl_ndb_multi.test @@ -7,7 +7,7 @@ # # Currently test only works with ndb since it retrieves "old" -# binlog positions with cluster_replication.binlog_index and apply_status; +# binlog positions with cluster.binlog_index and apply_status; # # create a table with one row, and make sure the other "master" gets it @@ -25,7 +25,7 @@ SELECT * FROM t1 ORDER BY c3; connection master; sync_slave_with_master; --replace_column 1 <the_epoch> -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; let $the_epoch= `select @the_epoch` ; SELECT * FROM t1 ORDER BY c3; stop slave; @@ -34,7 +34,7 @@ stop slave; connection server2; --replace_result $the_epoch <the_epoch> eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) - FROM cluster_replication.binlog_index WHERE epoch = $the_epoch ; + FROM cluster.binlog_index WHERE epoch = $the_epoch ; let $the_pos= `SELECT @the_pos` ; let $the_file= `SELECT @the_file` ; diff --git a/mysql-test/t/rpl_ndb_myisam2ndb-master.opt b/mysql-test/t/rpl_ndb_myisam2ndb-master.opt new file mode 100644 index 00000000000..83ed8522e72 --- /dev/null +++ b/mysql-test/t/rpl_ndb_myisam2ndb-master.opt @@ -0,0 +1 @@ +--binlog-format=row diff --git a/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt b/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt new file mode 100644 index 00000000000..f31d53c3cb1 --- /dev/null +++ b/mysql-test/t/rpl_ndb_myisam2ndb-slave.opt @@ -0,0 +1 @@ +--default-storage-engine=ndb --binlog-format=row diff --git a/mysql-test/t/rpl_ndb_myisam2ndb.test b/mysql-test/t/rpl_ndb_myisam2ndb.test new file mode 100644 index 00000000000..0c2df6441cb --- /dev/null +++ b/mysql-test/t/rpl_ndb_myisam2ndb.test @@ -0,0 +1,15 @@ +############################################################# +# Author: JBM +# Date: 2006-02-24 +# Purpose: Trying to test ability to replicate from cluster +# to innodb, or myisam, or replicate from innodb/myisam to +# cluster slave. Due to limitations I have created wrappers +# to be able to use the same code for all these different +# test and to have control over the tests. +############################################################## +-- source include/master-slave.inc +connection slave; +--source include/have_ndb.inc +connection master; +SET storage_engine=myisam; +--source extra/rpl_tests/rpl_ndb_2multi_eng.test diff --git a/mysql-test/t/rpl_ndb_sync.test b/mysql-test/t/rpl_ndb_sync.test index 5c990cd4842..d56f4a4ad03 100644 --- a/mysql-test/t/rpl_ndb_sync.test +++ b/mysql-test/t/rpl_ndb_sync.test @@ -4,7 +4,7 @@ # # Currently test only works with ndb since it retrieves "old" -# binlog positions with cluster_replication.binlog_index and apply_status; +# binlog positions with cluster.binlog_index and apply_status; # # stop the save @@ -26,14 +26,14 @@ SELECT hex(c2),hex(c3),c1 FROM t2 ORDER BY c1; # take a backup on master --exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT ---exec $NDB_TOOLS_DIR/ndb_select_all --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > var/tmp.dat -CREATE TEMPORARY TABLE IF NOT EXISTS cluster_replication.backup_info (id INT, backup_id INT)ENGINE=HEAP; -DELETE FROM cluster_replication.backup_info; -LOAD DATA INFILE '../../var/tmp.dat' INTO TABLE cluster_replication.backup_info FIELDS TERMINATED BY ','; +--exec $NDB_TOOLS_DIR/ndb_select_all --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat +CREATE TEMPORARY TABLE IF NOT EXISTS cluster.backup_info (id INT, backup_id INT)ENGINE=HEAP; +DELETE FROM cluster.backup_info; +LOAD DATA INFILE '../tmp.dat' INTO TABLE cluster.backup_info FIELDS TERMINATED BY ','; --replace_column 1 <the_backup_id> -SELECT @the_backup_id:=backup_id FROM cluster_replication.backup_info; +SELECT @the_backup_id:=backup_id FROM cluster.backup_info; let the_backup_id=`select @the_backup_id` ; -DROP TABLE cluster_replication.backup_info; +DROP TABLE cluster.backup_info; # update a row UPDATE t1 SET c2=0 WHERE c3="row2"; SELECT hex(c1),hex(c2),c3 FROM t1 ORDER BY c3; @@ -73,7 +73,7 @@ SELECT hex(c2),hex(c3),c1 FROM t2 ORDER BY c1; # 1. connection slave; --replace_column 1 <the_epoch> -SELECT @the_epoch:=MAX(epoch) FROM cluster_replication.apply_status; +SELECT @the_epoch:=MAX(epoch) FROM cluster.apply_status; let $the_epoch= `select @the_epoch` ; # 2. @@ -81,7 +81,7 @@ connection master; --replace_result $the_epoch <the_epoch> --replace_column 1 <the_pos> eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1) - FROM cluster_replication.binlog_index WHERE epoch > $the_epoch ORDER BY epoch ASC LIMIT 1; + FROM cluster.binlog_index WHERE epoch > $the_epoch ORDER BY epoch ASC LIMIT 1; let $the_pos= `SELECT @the_pos` ; let $the_file= `SELECT @the_file` ; @@ -124,11 +124,11 @@ STOP SLAVE; connection master; reset master; # should now contain nothing -select * from cluster_replication.binlog_index; +select * from cluster.binlog_index; connection slave; reset slave; # should now contain nothing -select * from cluster_replication.apply_status; +select * from cluster.apply_status; # End 5.1 Test diff --git a/mysql-test/t/rpl_row_4_bytes.test b/mysql-test/t/rpl_row_4_bytes.test index 26a4e2f5bfe..73ef6dd2345 100644 --- a/mysql-test/t/rpl_row_4_bytes.test +++ b/mysql-test/t/rpl_row_4_bytes.test @@ -29,5 +29,5 @@ select * from t1 order by a; select * from t2 order by a; connection master; -DROP TABLE t1,t2; +DROP DATABASE mysqltest1; sync_slave_with_master; diff --git a/mysql-test/t/rpl_row_NOW.test b/mysql-test/t/rpl_row_NOW.test index dba6fb16bb2..24a8774284a 100644 --- a/mysql-test/t/rpl_row_NOW.test +++ b/mysql-test/t/rpl_row_NOW.test @@ -50,8 +50,8 @@ sync_slave_with_master; connection master; ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > ./var/tmp/NOW_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > ./var/tmp/NOW_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/NOW_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/NOW_slave.sql # lets cleanup DROP TABLE IF EXISTS mysqltest1.t1; @@ -61,13 +61,13 @@ DROP FUNCTION mysqltest1.f1; # the test will show that the diff statement failed and not reject file # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) The failed dump -# files will be located in mysql-test/var/tmp +# files will be located in $MYSQLTEST_VARDIR/tmp -exec diff ./var/tmp/NOW_master.sql ./var/tmp/NOW_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/NOW_master.sql $MYSQLTEST_VARDIR/tmp/NOW_slave.sql; # If all is good, when can cleanup our dump files. -system rm ./var/tmp/NOW_master.sql; -system rm ./var/tmp/NOW_slave.sql; +system rm $MYSQLTEST_VARDIR/tmp/NOW_master.sql; +system rm $MYSQLTEST_VARDIR/tmp/NOW_slave.sql; sync_slave_with_master; # End of 5.1 test case diff --git a/mysql-test/t/rpl_row_drop.test b/mysql-test/t/rpl_row_drop.test index 816bd108b88..dd6ef331508 100644 --- a/mysql-test/t/rpl_row_drop.test +++ b/mysql-test/t/rpl_row_drop.test @@ -31,8 +31,8 @@ connection master; # Should drop the non-temporary table t1 and the temporary table t2 DROP TABLE t1,t2; let $VERSION=`select version()`; ---replace_result $VERSION VERSION -SHOW BINLOG EVENTS; +#--replace_result $VERSION VERSION +#SHOW BINLOG EVENTS; SHOW TABLES; sync_slave_with_master; --echo **** On Slave **** diff --git a/mysql-test/t/rpl_row_func002.test b/mysql-test/t/rpl_row_func002.test index 966124ce035..46767abd529 100644 --- a/mysql-test/t/rpl_row_func002.test +++ b/mysql-test/t/rpl_row_func002.test @@ -84,8 +84,8 @@ connection master; # time to dump the databases and so we can see if they match ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/func002_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/func002_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/func002_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/func002_slave.sql # Cleanup DROP FUNCTION test.f1; @@ -97,7 +97,7 @@ sync_slave_with_master; # the files your self to see what is not matching :-). The files are located # in mysql-test/var/tmp -exec diff ./var/tmp/func002_master.sql ./var/tmp/func002_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/func002_master.sql $MYSQLTEST_VARDIR/tmp/func002_slave.sql; # End of 5.0 test case diff --git a/mysql-test/t/rpl_row_mysqlbinlog-master.opt b/mysql-test/t/rpl_row_mysqlbinlog-master.opt new file mode 100644 index 00000000000..07d12817f5f --- /dev/null +++ b/mysql-test/t/rpl_row_mysqlbinlog-master.opt @@ -0,0 +1 @@ +--max-binlog-size=1040384 diff --git a/mysql-test/t/rpl_row_mysqlbinlog.test b/mysql-test/t/rpl_row_mysqlbinlog.test new file mode 100644 index 00000000000..3b4c8db86d8 --- /dev/null +++ b/mysql-test/t/rpl_row_mysqlbinlog.test @@ -0,0 +1,319 @@ +################################################################## +# Author: JBM # +# Date: 2006-02-22 # +# Purpose: To test changes to mysqlbinlog for row based bin logs # +# We are using .opt file since we need small binlog size # +################################################################## +# Include Section +# Make sure that we have row based bin log +-- source include/have_binlog_format_row.inc +# Embedded server doesn't support binlogging +-- source include/not_embedded.inc +-- source include/master-slave.inc + +# Setup Section +# we need this for getting fixed timestamps inside of this test + +--disable_query_log +select "---Setup Section --" as ""; +--enable_query_log + +set timestamp=1000000000; + +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3; +--enable_warnings + +connection master; +CREATE TABLE t1(word VARCHAR(20)); +CREATE TABLE t2(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY); +CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT); + + +# Test Section +# Lets start by putting some data into the tables. + +--disable_query_log +INSERT INTO t1 VALUES ("abirvalg"); +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; +LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1; + +# d1 length 3000 +set @d1 = 'dd1'; +set @d1 = concat(@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1); +set @d1 = concat(@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1); +set @d1 = concat(@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1); + +let $count=500; +while ($count) +{ + INSERT INTO t2 VALUES (NULL); + eval INSERT INTO t3 VALUES ($count,@d1,'20060222000000','Tested in Texas',$count*2.2); + dec $count; +} +--enable_query_log + + +--disable_query_log +select "---Test1 check table load --" as ""; +--enable_query_log + +# Lets Check the tables on the Master +SELECT COUNT(*) from t1; +SELECT COUNT(*) from t2; +SELECT COUNT(*) from t3; +SELECT * FROM t1 ORDER BY word LIMIT 5; +SELECT * FROM t2 ORDER BY id LIMIT 5; +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; + +# Should have the same on the slave; + +sync_slave_with_master; +SELECT COUNT(*) from t1; +SELECT COUNT(*) from t2; +SELECT COUNT(*) from t3; +SELECT * FROM t1 ORDER BY word LIMIT 5; +SELECT * FROM t2 ORDER BY id LIMIT 5; +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; + +# Okay time to get busy, back to master + +connection master; + +# simple query to show more in second binlog +insert into t1 values ("Alas"); +flush logs; + +# delimiters are for easier debugging in future +--disable_query_log +select "--- Test 1 Dump binlog to file --" as ""; +--enable_query_log + +# +# Prepare local temporary file to recreate what we have currently. + +--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/master.sql + +--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000002 >> $MYSQLTEST_VARDIR/tmp/master.sql + +# Now that we have our file, lets get rid of the current database. +# Cleanup the master and the slave and try to recreate. +--disable_query_log +select "--- Test 1 delete tables, clean master and slave --" as ""; +--enable_query_log + +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; + +sync_slave_with_master; +#we expect STOP SLAVE to produce a warning as the slave is stopped +#(the server was started with skip-slave-start) +--disable_warnings +stop slave; +--enable_warnings +--require r/slave-stopped.result +show status like 'Slave_running'; +connection master; +reset master; +connection slave; +reset slave; +start slave; +--require r/slave-running.result +show status like 'Slave_running'; +connection master; + +# We should be clean at this point, now we will run in the file from above. +--disable_query_log +select "--- Test 1 Load from Dump binlog file --" as ""; +--enable_query_log + +--exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/master.sql" + +--disable_query_log +select "--- Test 1 Check Load Results --" as ""; +--enable_query_log + +# Lets Check the tables on the Master +SELECT COUNT(*) from t1; +SELECT COUNT(*) from t2; +SELECT COUNT(*) from t3; +SELECT * FROM t1 ORDER BY word LIMIT 5; +SELECT * FROM t2 ORDER BY id LIMIT 5; +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; + +# Should have the same on the slave; + +sync_slave_with_master; +SELECT COUNT(*) from t1; +SELECT COUNT(*) from t2; +SELECT COUNT(*) from t3; +SELECT * FROM t1 ORDER BY word LIMIT 5; +SELECT * FROM t2 ORDER BY id LIMIT 5; +SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; +connection master; + +# We should be gold by the time, so I will get rid of our file. + +--exec rm $MYSQLTEST_VARDIR/tmp/master.sql + + +# this test for position option +# By setting this position to 412, we should only get the create of t3 +--disable_query_log +select "--- Test 2 position test --" as ""; +--enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=412 $MYSQLTEST_VARDIR/log/master-bin.000001 + +# These are tests for remote binlog. +# They should return the same as previous test. + +--disable_query_log +select "--- Test 3 First Remote test --" as ""; +--enable_query_log + +# This is broken now +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 + +# This part is disabled due to bug #17654 +################### Start Bug 17654 ###################### +#--disable_query_log +#select "--- Test 4 Second Remote test --" as ""; +#--enable_query_log +#--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql + +#--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 >> $MYSQLTEST_VARDIR/tmp/remote.sql + +# Now that we have our file, lets get rid of the current database. +# Cleanup the master and the slave and try to recreate. + +#DROP TABLE t1; +#DROP TABLE t2; +#DROP TABLE t3; + +#sync_slave_with_master; + +#we expect STOP SLAVE to produce a warning as the slave is stopped +#(the server was started with skip-slave-start) + +#--disable_warnings +#stop slave; +#--enable_warnings +#--require r/slave-stopped.result +#show status like 'Slave_running'; +#connection master; +#reset master; +#connection slave; +#reset slave; +#start slave; +#--require r/slave-running.result +#show status like 'Slave_running'; +#connection master; + +# We should be clean at this point, now we will run in the file from above. + +#--exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/remote.sql" + +# Lets Check the tables on the Master + +#SELECT COUNT(*) from t1; +#SELECT COUNT(*) from t2; +#SELECT COUNT(*) from t3; +#SELECT * FROM t1 ORDER BY word LIMIT 5; +#SELECT * FROM t2 ORDER BY id LIMIT 5; +#SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; + +# Should have the same on the slave; + +#sync_slave_with_master; +#SELECT COUNT(*) from t1; +#SELECT COUNT(*) from t2; +#SELECT COUNT(*) from t3; +#SELECT * FROM t1 ORDER BY word LIMIT 5; +#SELECT * FROM t2 ORDER BY id LIMIT 5; +#SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; +#connection master; + +# We should be gold by the time, so I will get rid of our file. + +#--exec rm $MYSQLTEST_VARDIR/tmp/remote.sql +################### End Bug 17654 ###################### + +# LOAD DATA +--disable_query_log +select "--- Test 5 LOAD DATA --" as ""; +--enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 + +# Bug#7853 (mysqlbinlog does not accept input from stdin) + +--disable_query_log +select "--- Test 6 reading stdin --" as ""; +--enable_query_log +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +--exec $MYSQL_BINLOG --short-form - < $MYSQLTEST_VARDIR/log/master-bin.000001 + +--disable_query_log +select "--- Test 7 reading stdin w/position --" as ""; +--enable_query_log +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +--exec $MYSQL_BINLOG --short-form --position=412 - < $MYSQLTEST_VARDIR/log/master-bin.000001 + +# Bug#16217 (mysql client did not know how not switch its internal charset) +--disable_query_log +select "--- Test 8 switch internal charset --" as ""; +--enable_query_log +sync_slave_with_master; + +#we expect STOP SLAVE to produce a warning as the slave is stopped +#(the server was started with skip-slave-start) + +--disable_warnings +stop slave; +--enable_warnings +--require r/slave-stopped.result +show status like 'Slave_running'; +connection master; +reset master; +connection slave; +reset slave; +start slave; +--require r/slave-running.result +show status like 'Slave_running'; +connection master; + +create table t4 (f text character set utf8); +create table t5 (f text character set cp932); +--exec $MYSQL --default-character-set=utf8 test -e "insert into t4 values(_utf8'ソ')" +--exec $MYSQL --default-character-set=cp932 test -e "insert into t5 values(_cp932'ƒ\');" +flush logs; +rename table t4 to t04, t5 to t05; +--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000001 | $MYSQL --default-character-set=utf8 +# original and recovered data must be equal +select HEX(f) from t04; +select HEX(f) from t4; +select HEX(f) from t05; +select HEX(f) from t5; + +# slave should have same +sync_slave_with_master; +select HEX(f) from t04; +select HEX(f) from t4; +select HEX(f) from t05; +select HEX(f) from t5; + +--disable_query_log +select "--- Test cleanup --" as ""; +--enable_query_log +# clean up +connection master; +DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5; +sync_slave_with_master; + +# End of 4.1 tests diff --git a/mysql-test/t/rpl_row_sp001.test b/mysql-test/t/rpl_row_sp001.test index 88384b242b0..8e01cbc4f44 100644 --- a/mysql-test/t/rpl_row_sp001.test +++ b/mysql-test/t/rpl_row_sp001.test @@ -119,8 +119,8 @@ SELECT * FROM t2 ORDER BY a; # time to dump the databases and so we can see if they match ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/sp001_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/sp001_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp001_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp001_slave.sql # First lets cleanup @@ -135,12 +135,12 @@ sync_slave_with_master; # the test will show that the diff statement failed and not reject file # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) Failed dump files -# will be located in mysql-test/var/tmp +# will be located in $MYSQLTEST_VARDIR/tmp ---exec diff ./var/tmp/sp001_master.sql ./var/tmp/sp001_slave.sql; +--exec diff $MYSQLTEST_VARDIR/tmp/sp001_master.sql $MYSQLTEST_VARDIR/tmp/sp001_slave.sql; # If all is good, when can cleanup our dump files. -system rm ./var/tmp/sp001_master.sql; -system rm ./var/tmp/sp001_slave.sql; +system rm $MYSQLTEST_VARDIR/tmp/sp001_master.sql; +system rm $MYSQLTEST_VARDIR/tmp/sp001_slave.sql; # End of 5.0 test case diff --git a/mysql-test/t/rpl_row_sp010.test b/mysql-test/t/rpl_row_sp010.test index 10940e1e030..28b82217517 100644 --- a/mysql-test/t/rpl_row_sp010.test +++ b/mysql-test/t/rpl_row_sp010.test @@ -37,7 +37,7 @@ BEGIN END| delimiter ;| CALL test.p2(); -SELECT * FROM test.t1; +SELECT * FROM test.t1 ORDER BY a; save_master_pos; connection slave; @@ -59,12 +59,12 @@ BEGIN END| delimiter ;| CALL test.p4(); -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; save_master_pos; connection slave; sync_with_master; -SELECT * FROM test.t2; +SELECT * FROM test.t2 ORDER BY a; # Cleanup connection master; diff --git a/mysql-test/t/rpl_row_sp011.test b/mysql-test/t/rpl_row_sp011.test index 73d2f628dbd..54e708492d1 100644 --- a/mysql-test/t/rpl_row_sp011.test +++ b/mysql-test/t/rpl_row_sp011.test @@ -79,8 +79,8 @@ CALL test.p1(); sync_slave_with_master; #SELECT * FROM test.t2; ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/sp011_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/sp011_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp011_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp011_slave.sql # Cleanup connection master; @@ -100,12 +100,12 @@ sync_slave_with_master; # the test will show that the diff statement failed and not reject file # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) Failed test -# Will leave dump files in mysql-test/var/tmp +# Will leave dump files in $MYSQLTEST_VARDIR/tmp -exec diff ./var/tmp/sp011_master.sql ./var/tmp/sp011_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/sp011_master.sql $MYSQLTEST_VARDIR/tmp/sp011_slave.sql; # If all is good, when can cleanup our dump files. -system rm ./var/tmp/sp011_master.sql; -system rm ./var/tmp/sp011_slave.sql; +system rm $MYSQLTEST_VARDIR/tmp/sp011_master.sql; +system rm $MYSQLTEST_VARDIR/tmp/sp011_slave.sql; # End of 5.0 test case diff --git a/mysql-test/t/rpl_row_stop_middle_update.test b/mysql-test/t/rpl_row_stop_middle_update.test index 82c4b1a9936..29b3008e822 100644 --- a/mysql-test/t/rpl_row_stop_middle_update.test +++ b/mysql-test/t/rpl_row_stop_middle_update.test @@ -9,7 +9,7 @@ connection master; create table t1 (words varchar(20)) engine=myisam; -load data infile '../../std_data/words.dat' into table t1 (words); +load data infile '../std_data_ln/words.dat' into table t1 (words); select count(*) from t1; save_master_pos; diff --git a/mysql-test/t/rpl_row_trig001.test b/mysql-test/t/rpl_row_trig001.test index b7866069a51..931cab95948 100644 --- a/mysql-test/t/rpl_row_trig001.test +++ b/mysql-test/t/rpl_row_trig001.test @@ -75,8 +75,8 @@ let $message=<End test section 2 (Tiggers & SP)>; # time to dump the databases and so we can see if they match ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/trig001_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/trig001_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/trig001_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/trig001_slave.sql # Cleanup connection master; @@ -93,8 +93,8 @@ sync_slave_with_master; # the test will show that the diff statement failed and not reject file # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) Failed tests -# will leave dump files in mysql-test/var/tmp +# will leave dump files in $MYSQLTEST_VARDIR/tmp -exec diff ./var/tmp/trig001_master.sql ./var/tmp/trig001_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/trig001_master.sql $MYSQLTEST_VARDIR/tmp/trig001_slave.sql; # End of 5.0 test case diff --git a/mysql-test/t/rpl_row_trig003.test b/mysql-test/t/rpl_row_trig003.test index 799c2d6c9c7..d4570afd094 100644 --- a/mysql-test/t/rpl_row_trig003.test +++ b/mysql-test/t/rpl_row_trig003.test @@ -125,8 +125,8 @@ connection master; # time to dump the databases and so we can see if they match ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/trg003_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/trg003_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/trg003_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/trg003_slave.sql # cleanup --disable_warnings @@ -147,6 +147,6 @@ DROP TABLE IF EXISTS test.t2; DROP TABLE IF EXISTS test.t3; --enable_warnings -exec diff ./var/tmp/trg003_master.sql ./var/tmp/trg003_slave.sql; +exec diff $MYSQLTEST_VARDIR/tmp/trg003_master.sql $MYSQLTEST_VARDIR/tmp/trg003_slave.sql; # End of 5.0 test case diff --git a/mysql-test/t/rpl_sp004.test b/mysql-test/t/rpl_sp004.test index 9156e6f4047..335a17c7af0 100644 --- a/mysql-test/t/rpl_sp004.test +++ b/mysql-test/t/rpl_sp004.test @@ -76,8 +76,8 @@ SELECT * FROM test.t1; SELECT * FROM test.t2; #SELECT * FROM test.t3; ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/sp004_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > ./var/tmp/sp004_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp004_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/sp004_slave.sql # Cleanup connection master; @@ -91,7 +91,7 @@ sync_slave_with_master; # If the test fails, you will need to diff the dumps to see why. --- exec diff ./var/tmp/sp004_master.sql ./var/tmp/sp004_slave.sql +-- exec diff $MYSQLTEST_VARDIR/tmp/sp004_master.sql $MYSQLTEST_VARDIR/tmp/sp004_slave.sql # End of 5.0 test case diff --git a/mysql-test/t/rpl_switch_stm_row_mixed.test b/mysql-test/t/rpl_switch_stm_row_mixed.test new file mode 100644 index 00000000000..f607148a4b4 --- /dev/null +++ b/mysql-test/t/rpl_switch_stm_row_mixed.test @@ -0,0 +1,165 @@ +-- source include/have_binlog_format_row.inc +-- source include/master-slave.inc + +connection master; +--disable_warnings +drop database if exists mysqltest1; +create database mysqltest1; +--enable_warnings +use mysqltest1; + +show global variables like "binlog_format%"; +show session variables like "binlog_format%"; +select @@global.binlog_format, @@session.binlog_format; + +CREATE TABLE t1 (a varchar(100)); + +prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work")); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; + +# verify that temp tables prevent a switch to SBR +create temporary table tmp(a char(3)); +insert into tmp values("see"); +--error ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR +set binlog_format=statement; +insert into t1 select * from tmp; +drop temporary table tmp; + +# Now we go to SBR +set binlog_format=statement; +show global variables like "binlog_format%"; +show session variables like "binlog_format%"; +select @@global.binlog_format, @@session.binlog_format; +set global binlog_format=statement; +show global variables like "binlog_format%"; +show session variables like "binlog_format%"; +select @@global.binlog_format, @@session.binlog_format; + +prepare stmt1 from 'insert into t1 select ?'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values("for"); +insert into t1 select "yesterday"; + +# test SET DEFAULT (=statement at this point of test) +set binlog_format=default; +select @@global.binlog_format, @@session.binlog_format; +# due to cluster it's hard to set back to default +--error ER_NO_DEFAULT +set global binlog_format=default; +select @@global.binlog_format, @@session.binlog_format; + +prepare stmt1 from 'insert into t1 select ?'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values("for"); +insert into t1 select "yesterday"; + +# and now the mixed mode + +set binlog_format=mixed; +select @@global.binlog_format, @@session.binlog_format; +set global binlog_format=mixed; +select @@global.binlog_format, @@session.binlog_format; + +prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; +set @string="emergency"; +insert into t1 values("work"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work")); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work")); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; + +# inside a stored procedure (inside a function or trigger won't +# work) + +delimiter |; +create procedure foo() +begin +insert into t1 values("work"); +insert into t1 values(concat("for",UUID())); +insert into t1 select "yesterday"; +end| +create procedure foo2() +begin +insert into t1 values(concat("emergency",UUID())); +insert into t1 values("work"); +insert into t1 values(concat("for",UUID())); +set session binlog_format=row; # accepted for stored procs +insert into t1 values("more work"); +set session binlog_format=mixed; +end| +create function foo3() returns bigint unsigned +begin + set session binlog_format=row; # rejected for stored funcs + insert into t1 values("alarm"); + return 100; +end| +delimiter ;| +call foo(); +call foo2(); + +# test that can't SET in a stored function if not in row-based mode +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT +select foo3(); +select * from t1 where a="alarm"; + +# and now compare: + +show binlog events from 102; +sync_slave_with_master; +# as we're using UUID we don't SELECT but use "diff" like in rpl_row_UUID +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_row_UDF_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_row_UDF_slave.sql + +connection master; +drop database mysqltest1; +sync_slave_with_master; + +# Let's compare. Note: If they match test will pass, if they do not match +# the test will show that the diff statement failed and not reject file +# will be created. You will need to go to the mysql-test dir and diff +# the files your self to see what is not matching + +#--exec diff $MYSQLTEST_VARDIR/tmp/rpl_row_UDF_master.sql $MYSQLTEST_VARDIR/tmp/rpl_row_UDF_slave.sql; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 9cfe85d3bd4..a7b24a5e06c 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -393,7 +393,7 @@ SHOW TABLE STATUS like 't1'; --error 1033 show create table t1; drop table if exists t1; -system rm -f var/master-data/test/t1.frm ; +system rm -f $MYSQLTEST_VARDIR/master-data/test/t1.frm ; # End of 4.1 tests diff --git a/mysql-test/t/skip_grants.test b/mysql-test/t/skip_grants.test index a0164cb0759..27220c9b507 100644 --- a/mysql-test/t/skip_grants.test +++ b/mysql-test/t/skip_grants.test @@ -30,3 +30,6 @@ create table t1 (a int); create definer='user'@'host' sql security definer view v1 as select * from t1; drop view v1; drop table t1; + +# BUG#17595: DROP FUNCTION IF EXISTS f1 crashes server +drop function if exists f1; diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test index 5fc81c338c6..375d2289459 100644 --- a/mysql-test/t/sp-destruct.test +++ b/mysql-test/t/sp-destruct.test @@ -54,10 +54,13 @@ flush table mysql.proc; # Thrashing the .frm file --system echo 'saljdlfa' > $MYSQLTEST_VARDIR/master-data/mysql/proc.frm +--replace_result $MYSQLTEST_VARDIR . master-data// '' --error ER_NOT_FORM_FILE call bug14233(); +--replace_result $MYSQLTEST_VARDIR . master-data// '' --error ER_NOT_FORM_FILE create view v1 as select bug14233_f(); +--replace_result $MYSQLTEST_VARDIR . master-data// '' --error ER_NOT_FORM_FILE insert into t1 values (0); diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 63185ea9a88..4b307de2ad0 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1682,9 +1682,21 @@ drop procedure bug15091; # +# BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION +# +--disable_warnings +drop function if exists bug16896; +--enable_warnings + +--error ER_SP_NO_AGGREGATE +create aggregate function bug16896() returns int return 1; + + +# # BUG#NNNN: New bug synopsis # #--disable_warnings #drop procedure if exists bugNNNN| #--enable_warnings #create procedure bugNNNN... + diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test index 90160780618..19f94a32d9c 100644 --- a/mysql-test/t/sp-security.test +++ b/mysql-test/t/sp-security.test @@ -525,4 +525,26 @@ disconnect user_bug14533; drop user user_bug14533@localhost; drop database db_bug14533; + +# +# BUG#7787: Stored procedures: improper warning for "grant execute" statement +# + +# Prepare. + +CREATE DATABASE db_bug7787; +use db_bug7787; + +# Test. + +CREATE PROCEDURE p1() + SHOW INNODB STATUS; + +GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost; + +# Cleanup. + +DROP DATABASE db_bug7787; +use test; + # End of 5.0 bugs. diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index d535fc8319e..7709fb68e87 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -699,32 +699,34 @@ drop procedure into_test4| --disable_warnings drop procedure if exists into_outfile| --enable_warnings -create procedure into_outfile(x char(16), y int) +--replace_result $MYSQLTEST_VARDIR .. +eval create procedure into_outfile(x char(16), y int) begin insert into test.t1 values (x, y); - select * into outfile "/tmp/spout" from test.t1; + select * into outfile "$MYSQLTEST_VARDIR/tmp/spout" from test.t1; insert into test.t1 values (concat(x, "2"), y+2); end| -system rm -f /tmp/spout| +--system rm -f $MYSQLTEST_VARDIR/tmp/spout call into_outfile("ofile", 1)| -system rm -f /tmp/spout| +--system rm -f $MYSQLTEST_VARDIR/tmp/spout delete from t1| drop procedure into_outfile| --disable_warnings drop procedure if exists into_dumpfile| --enable_warnings -create procedure into_dumpfile(x char(16), y int) +--replace_result $MYSQLTEST_VARDIR .. +eval create procedure into_dumpfile(x char(16), y int) begin insert into test.t1 values (x, y); - select * into dumpfile "/tmp/spdump" from test.t1 limit 1; + select * into dumpfile "$MYSQLTEST_VARDIR/tmp/spdump" from test.t1 limit 1; insert into test.t1 values (concat(x, "2"), y+2); end| -system rm -f /tmp/spdump| +--system rm -f $MYSQLTEST_VARDIR/tmp/spdump call into_dumpfile("dfile", 1)| -system rm -f /tmp/spdump| +--system rm -f $MYSQLTEST_VARDIR/tmp/spdump delete from t1| drop procedure into_dumpfile| @@ -1660,7 +1662,7 @@ drop function `foo`| # Implicit LOCK/UNLOCK TABLES for table access in functions # ---disable_warning +--disable_warnings drop function if exists t1max| --enable_warnings create function t1max() returns int @@ -1704,6 +1706,397 @@ drop table t3| drop function getcount| +# Test cases for different combinations of condition handlers in nested +# begin-end blocks in stored procedures. +# +# Note that the standard specifies that the most specific handler should +# be triggered even if it's an outer handler masked by a less specific +# handler in an inner block. +# Note also that '02000' is more specific than NOT FOUND; there might be +# other '02xxx' states, even if we currently do not issue them in any +# situation (e.g. '02001'). +# +# The combinations we test are these: +# +# Inner +# errcode sqlstate not found sqlwarning sqlexception +# Outer +------------+------------+------------+------------+------------+ +#errcode | h_ee (i) | h_es (o) | h_en (o) | h_ew (o) | h_ex (o) | +#sqlstate | h_se (i) | h_ss (i) | h_sn (o) | h_sw (o) | h_sx (o) | +#not found | h_ne (i) | h_ns (i) | h_nn (i) | | | +#sqlwarning | h_we (i) | h_ws (i) | | h_ww (i) | | +#sqlexception | h_xe (i) | h_xs (i) | | | h_xx (i) | +# +------------+---------------------------------------------------+ +# +# (i) means that the inner handler is the one that should be invoked, +# (o) means that the outer handler should be invoked. +# +# ('not found', 'sqlwarning' and 'sqlexception' are mutually exclusive, hence +# no tests for those combinations.) +# + +--disable_warnings +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +--enable_warnings + +# smallint - to get out of range warnings +# primary key - to get constraint errors +create table t3 (a smallint primary key)| + +insert into t3 (a) values (1)| + +create procedure h_ee() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (bad)' as 'h_ee'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_ee'; + + insert into t3 values (1); + end; +end| + +create procedure h_es() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (good)' as 'h_es'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (bad)' as 'h_es'; + + insert into t3 values (1); + end; +end| + +create procedure h_en() + deterministic +begin + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Outer (good)' as 'h_en'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (bad)' as 'h_en'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_ew() + deterministic +begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Outer (good)' as 'h_ew'; + + begin + declare continue handler for sqlwarning + select 'Inner (bad)' as 'h_ew'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ex() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (good)' as 'h_ex'; + + begin + declare continue handler for sqlexception + select 'Inner (bad)' as 'h_ex'; + + insert into t3 values (1); + end; +end| + +create procedure h_se() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_se'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_se'; + + insert into t3 values (1); + end; +end| + +create procedure h_ss() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_ss'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_ss'; + + insert into t3 values (1); + end; +end| + +create procedure h_sn() + deterministic +begin + -- Note: '02000' is more specific than NOT FOUND ; + -- there might be other not found states + declare continue handler for sqlstate '02000' -- no data + select 'Outer (good)' as 'h_sn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (bad)' as 'h_sn'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_sw() + deterministic +begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Outer (good)' as 'h_sw'; + + begin + declare continue handler for sqlwarning + select 'Inner (bad)' as 'h_sw'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_sx() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (good)' as 'h_sx'; + + begin + declare continue handler for sqlexception + select 'Inner (bad)' as 'h_sx'; + + insert into t3 values (1); + end; +end| + +create procedure h_ne() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ne'; + + begin + declare x int; + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Inner (good)' as 'h_ne'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_ns() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ns'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (good)' as 'h_ns'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_nn() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_nn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (good)' as 'h_nn'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_we() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_we'; + + begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Inner (good)' as 'h_we'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ws() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ws'; + + begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ww() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ww'; + + begin + declare continue handler for sqlwarning + select 'Inner (good)' as 'h_ww'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_xe() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xe'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_xe'; + + insert into t3 values (1); + end; +end| + +create procedure h_xs() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xs'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; + + insert into t3 values (1); + end; +end| + +create procedure h_xx() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xx'; + + begin + declare continue handler for sqlexception + select 'Inner (good)' as 'h_xx'; + + insert into t3 values (1); + end; +end| + +call h_ee()| +call h_es()| +call h_en()| +call h_ew()| +call h_ex()| +call h_se()| +call h_ss()| +call h_sn()| +call h_sw()| +call h_sx()| +call h_ne()| +call h_ns()| +call h_nn()| +call h_we()| +call h_ws()| +call h_ww()| +call h_xe()| +call h_xs()| +call h_xx()| + +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| + + # # Test cases for old bugs # @@ -5228,6 +5621,31 @@ drop table t3| # +# BUG#17476: Stored procedure not returning data when it is called first +# time per connection +# +--disable_warnings +drop procedure if exists bug17476| +--enable_warnings + +create table t3 ( d date )| +insert into t3 values + ( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ), + ( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )| + +create procedure bug17476(pDateFormat varchar(10)) + select date_format(t3.d, pDateFormat), count(*) + from t3 + group by date_format(t3.d, pDateFormat)| + +call bug17476('%Y-%m')| +call bug17476('%Y-%m')| + +drop table t3| +drop procedure bug17476| + + +# # BUG#NNNN: New bug synopsis # #--disable_warnings diff --git a/mysql-test/t/sp.test.orig b/mysql-test/t/sp.test.orig new file mode 100644 index 00000000000..a4b99620344 --- /dev/null +++ b/mysql-test/t/sp.test.orig @@ -0,0 +1,5716 @@ +# +# Basic stored PROCEDURE tests +# +# Please keep this file free of --error cases and other +# things that will not run in a single debugged mysqld +# process (e.g. master-slave things). +# +# Test cases for bugs are added at the end. See template there. +# +# Tests that require --error go into sp-error.test +# Tests that require inndb go into sp_trans.test +# Tests that check privilege and security issues go to sp-security.test. +# Tests that require multiple connections, except security/privilege tests, +# go to sp-thread. +# Tests that uses 'goto' to into sp-goto.test (currently disabled) +# Tests that destroys system tables (e.g. mysql.proc) for error testing +# go to sp-destruct. + +use test; + +# Test tables +# +# t1 and t2 are reused throughout the file, and dropped at the end. +# t3 and up are created and dropped when needed. +# +--disable_warnings +drop table if exists t1,t2,t3,t4; +--enable_warnings +create table t1 ( + id char(16) not null default '', + data int not null +); +create table t2 ( + s char(16), + i int, + d double +); + + +# Single statement, no params. +--disable_warnings +drop procedure if exists foo42; +--enable_warnings +create procedure foo42() + insert into test.t1 values ("foo", 42); + +call foo42(); +select * from t1; +delete from t1; +drop procedure foo42; + + +# Single statement, two IN params. +--disable_warnings +drop procedure if exists bar; +--enable_warnings +create procedure bar(x char(16), y int) + insert into test.t1 values (x, y); + +call bar("bar", 666); +select * from t1; +delete from t1; +# Don't drop procedure yet... + + +# Now for multiple statements... +delimiter |; + +# Empty statement +--disable_warnings +drop procedure if exists empty| +--enable_warnings +create procedure empty() +begin +end| + +call empty()| +drop procedure empty| + +# Scope test. This is legal (warnings might be possible in the future, +# but for the time being, we just accept it). +--disable_warnings +drop procedure if exists scope| +--enable_warnings +create procedure scope(a int, b float) +begin + declare b int; + declare c float; + + begin + declare c int; + end; +end| + +drop procedure scope| + +# Two statements. +--disable_warnings +drop procedure if exists two| +--enable_warnings +create procedure two(x1 char(16), x2 char(16), y int) +begin + insert into test.t1 values (x1, y); + insert into test.t1 values (x2, y); +end| + +call two("one", "two", 3)| +select * from t1| +delete from t1| +drop procedure two| + + +# Simple test of local variables and SET. +--disable_warnings +drop procedure if exists locset| +--enable_warnings +create procedure locset(x char(16), y int) +begin + declare z1, z2 int; + set z1 = y; + set z2 = z1+2; + insert into test.t1 values (x, z2); +end| + +call locset("locset", 19)| +select * from t1| +delete from t1| +drop procedure locset| + + +# In some contexts local variables are not recognized +# (and in some, you have to qualify the identifier). +--disable_warnings +drop procedure if exists setcontext| +--enable_warnings +create procedure setcontext() +begin + declare data int default 2; + + insert into t1 (id, data) values ("foo", 1); + replace t1 set data = data, id = "bar"; + update t1 set id = "kaka", data = 3 where t1.data = data; +end| + +call setcontext()| +select * from t1| +delete from t1| +drop procedure setcontext| + + +# Set things to null +create table t3 ( d date, i int, f double, s varchar(32) )| + +--disable_warnings +drop procedure if exists nullset| +--enable_warnings +create procedure nullset() +begin + declare ld date; + declare li int; + declare lf double; + declare ls varchar(32); + + set ld = null, li = null, lf = null, ls = null; + insert into t3 values (ld, li, lf, ls); + + insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), + ((li is null), 1, "li is null"), + ((li = 0), null, "li = 0"), + ((lf is null), 1, "lf is null"), + ((lf = 0), null, "lf = 0"), + ((ls is null), 1, "ls is null"); +end| + +call nullset()| +select * from t3| +drop table t3| +drop procedure nullset| + + +# The peculiar (non-standard) mixture of variables types in SET. +--disable_warnings +drop procedure if exists mixset| +--enable_warnings +create procedure mixset(x char(16), y int) +begin + declare z int; + + set @z = y, z = 666, max_join_size = 100; + insert into test.t1 values (x, z); +end| + +call mixset("mixset", 19)| +show variables like 'max_join_size'| +select id,data,@z from t1| +delete from t1| +drop procedure mixset| + + +# Multiple CALL statements, one with OUT parameter. +--disable_warnings +drop procedure if exists zip| +--enable_warnings +create procedure zip(x char(16), y int) +begin + declare z int; + call zap(y, z); + call bar(x, z); +end| + +# SET local variables and OUT parameter. +--disable_warnings +drop procedure if exists zap| +--enable_warnings +create procedure zap(x int, out y int) +begin + declare z int; + set z = x+1, y = z; +end| + +call zip("zip", 99)| +select * from t1| +delete from t1| +drop procedure zip| +drop procedure bar| + +# Top-level OUT parameter +call zap(7, @zap)| +select @zap| + +drop procedure zap| + + +# "Deep" calls... +--disable_warnings +drop procedure if exists c1| +--enable_warnings +create procedure c1(x int) + call c2("c", x)| +--disable_warnings +drop procedure if exists c2| +--enable_warnings +create procedure c2(s char(16), x int) + call c3(x, s)| +--disable_warnings +drop procedure if exists c3| +--enable_warnings +create procedure c3(x int, s char(16)) + call c4("level", x, s)| +--disable_warnings +drop procedure if exists c4| +--enable_warnings +create procedure c4(l char(8), x int, s char(16)) + insert into t1 values (concat(l,s), x)| + +call c1(42)| +select * from t1| +delete from t1| +drop procedure c1| +drop procedure c2| +drop procedure c3| +drop procedure c4| + +# INOUT test +--disable_warnings +drop procedure if exists iotest| +--enable_warnings +create procedure iotest(x1 char(16), x2 char(16), y int) +begin + call inc2(x2, y); + insert into test.t1 values (x1, y); +end| + +--disable_warnings +drop procedure if exists inc2| +--enable_warnings +create procedure inc2(x char(16), y int) +begin + call inc(y); + insert into test.t1 values (x, y); +end| + +--disable_warnings +drop procedure if exists inc| +--enable_warnings +create procedure inc(inout io int) + set io = io + 1| + +call iotest("io1", "io2", 1)| +select * from t1| +delete from t1| +drop procedure iotest| +drop procedure inc2| + +# Propagating top-level @-vars +--disable_warnings +drop procedure if exists incr| +--enable_warnings +create procedure incr(inout x int) + call inc(x)| + +# Before +select @zap| +call incr(@zap)| +# After +select @zap| + +drop procedure inc| +drop procedure incr| + +# Call-by-value test +# The expected result is: +# ("cbv2", 4) +# ("cbv1", 4711) +--disable_warnings +drop procedure if exists cbv1| +--enable_warnings +create procedure cbv1() +begin + declare y int default 3; + + call cbv2(y+1, y); + insert into test.t1 values ("cbv1", y); +end| + +--disable_warnings +drop procedure if exists cbv2| +--enable_warnings +create procedure cbv2(y1 int, inout y2 int) +begin + set y2 = 4711; + insert into test.t1 values ("cbv2", y1); +end| + +call cbv1()| +select * from t1| +delete from t1| +drop procedure cbv1| +drop procedure cbv2| + + +# Subselect arguments + +insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| + +--disable_warnings +drop procedure if exists sub1| +--enable_warnings +create procedure sub1(id char(16), x int) + insert into test.t1 values (id, x)| + +--disable_warnings +drop procedure if exists sub2| +--enable_warnings +create procedure sub2(id char(16)) +begin + declare x int; + set x = (select sum(t.i) from test.t2 t); + insert into test.t1 values (id, x); +end| + +--disable_warnings +drop procedure if exists sub3| +--enable_warnings +create function sub3(i int) returns int + return i+1| + +call sub1("sub1a", (select 7))| +call sub1("sub1b", (select max(i) from t2))| +--error ER_OPERAND_COLUMNS +call sub1("sub1c", (select i,d from t2 limit 1))| +call sub1("sub1d", (select 1 from (select 1) a))| +call sub2("sub2")| +select * from t1| +select sub3((select max(i) from t2))| +drop procedure sub1| +drop procedure sub2| +drop function sub3| +delete from t1| +delete from t2| + +# Basic tests of the flow control constructs + +# Just test on 'x'... +--disable_warnings +drop procedure if exists a0| +--enable_warnings +create procedure a0(x int) +while x do + set x = x-1; + insert into test.t1 values ("a0", x); +end while| + +call a0(3)| +select * from t1| +delete from t1| +drop procedure a0| + + +# The same, but with a more traditional test. +--disable_warnings +drop procedure if exists a| +--enable_warnings +create procedure a(x int) +while x > 0 do + set x = x-1; + insert into test.t1 values ("a", x); +end while| + +call a(3)| +select * from t1| +delete from t1| +drop procedure a| + + +# REPEAT +--disable_warnings +drop procedure if exists b| +--enable_warnings +create procedure b(x int) +repeat + insert into test.t1 values (repeat("b",3), x); + set x = x-1; +until x = 0 end repeat| + +call b(3)| +select * from t1| +delete from t1| +drop procedure b| + + +# Check that repeat isn't parsed the wrong way +--disable_warnings +drop procedure if exists b2| +--enable_warnings +create procedure b2(x int) +repeat(select 1 into outfile 'b2'); + insert into test.t1 values (repeat("b2",3), x); + set x = x-1; +until x = 0 end repeat| + +# We don't actually want to call it. +drop procedure b2| + + +# Labelled WHILE with ITERATE (pointless really) +--disable_warnings +drop procedure if exists c| +--enable_warnings +create procedure c(x int) +hmm: while x > 0 do + insert into test.t1 values ("c", x); + set x = x-1; + iterate hmm; + insert into test.t1 values ("x", x); +end while hmm| + +call c(3)| +select * from t1| +delete from t1| +drop procedure c| + + +# Labelled WHILE with LEAVE +--disable_warnings +drop procedure if exists d| +--enable_warnings +create procedure d(x int) +hmm: while x > 0 do + insert into test.t1 values ("d", x); + set x = x-1; + leave hmm; + insert into test.t1 values ("x", x); +end while| + +call d(3)| +select * from t1| +delete from t1| +drop procedure d| + + +# LOOP, with simple IF statement +--disable_warnings +drop procedure if exists e| +--enable_warnings +create procedure e(x int) +foo: loop + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("e", x); + set x = x-1; +end loop foo| + +call e(3)| +select * from t1| +delete from t1| +drop procedure e| + + +# A full IF statement +--disable_warnings +drop procedure if exists f| +--enable_warnings +create procedure f(x int) +if x < 0 then + insert into test.t1 values ("f", 0); +elseif x = 0 then + insert into test.t1 values ("f", 1); +else + insert into test.t1 values ("f", 2); +end if| + +call f(-2)| +call f(0)| +call f(4)| +select * from t1| +delete from t1| +drop procedure f| + + +# This form of CASE is really just syntactic sugar for IF-ELSEIF-... +--disable_warnings +drop procedure if exists g| +--enable_warnings +create procedure g(x int) +case +when x < 0 then + insert into test.t1 values ("g", 0); +when x = 0 then + insert into test.t1 values ("g", 1); +else + insert into test.t1 values ("g", 2); +end case| + +call g(-42)| +call g(0)| +call g(1)| +select * from t1| +delete from t1| +drop procedure g| + + +# The "simple CASE" +--disable_warnings +drop procedure if exists h| +--enable_warnings +create procedure h(x int) +case x +when 0 then + insert into test.t1 values ("h0", x); +when 1 then + insert into test.t1 values ("h1", x); +else + insert into test.t1 values ("h?", x); +end case| + +call h(0)| +call h(1)| +call h(17)| +select * from t1| +delete from t1| +drop procedure h| + + +# It's actually possible to LEAVE a BEGIN-END block +--disable_warnings +drop procedure if exists i| +--enable_warnings +create procedure i(x int) +foo: +begin + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("i", x); +end foo| + +call i(0)| +call i(3)| +select * from t1| +delete from t1| +drop procedure i| + + +# SELECT with one of more result set sent back to the clinet +insert into t1 values ("foo", 3), ("bar", 19)| +insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| + +--disable_warnings +drop procedure if exists sel1| +--enable_warnings +create procedure sel1() +begin + select * from t1; +end| + +call sel1()| +drop procedure sel1| + +--disable_warnings +drop procedure if exists sel2| +--enable_warnings +create procedure sel2() +begin + select * from t1; + select * from t2; +end| + +call sel2()| +drop procedure sel2| +delete from t1| +delete from t2| + +# SELECT INTO local variables +--disable_warnings +drop procedure if exists into_test| +--enable_warnings +create procedure into_test(x char(16), y int) +begin + insert into test.t1 values (x, y); + select id,data into x,y from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +call into_test("into", 100)| +select * from t1| +delete from t1| +drop procedure into_test| + + +# SELECT INTO with a mix of local and global variables +--disable_warnings +drop procedure if exists into_tes2| +--enable_warnings +create procedure into_test2(x char(16), y int) +begin + insert into test.t1 values (x, y); + select id,data into x,@z from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +call into_test2("into", 100)| +select id,data,@z from t1| +delete from t1| +drop procedure into_test2| + + +# SELECT * INTO ... (bug test) +--disable_warnings +drop procedure if exists into_test3| +--enable_warnings +create procedure into_test3() +begin + declare x char(16); + declare y int; + + select * into x,y from test.t1 limit 1; + insert into test.t2 values (x, y, 0.0); +end| + +insert into t1 values ("into3", 19)| +# Two call needed for bug test +call into_test3()| +call into_test3()| +select * from t2| +delete from t1| +delete from t2| +drop procedure into_test3| + + +# SELECT INTO with no data is a warning ("no data", which we will +# not see normally). When not caught, execution proceeds. +--disable_warnings +drop procedure if exists into_test4| +--enable_warnings +create procedure into_test4() +begin + declare x int; + + select data into x from test.t1 limit 1; + insert into test.t3 values ("into4", x); +end| + +delete from t1| +create table t3 ( s char(16), d int)| +call into_test4()| +select * from t3| +insert into t1 values ("i4", 77)| +call into_test4()| +select * from t3| +delete from t1| +drop table t3| +drop procedure into_test4| + + +# These two (and the two procedures above) caused an assert() to fail in +# sql_base.cc:lock_tables() at some point. +--disable_warnings +drop procedure if exists into_outfile| +--enable_warnings +create procedure into_outfile(x char(16), y int) +begin + insert into test.t1 values (x, y); + select * into outfile "../tmp/spout" from test.t1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +--system rm -f $MYSQLTEST_VARDIR/tmp/spout +call into_outfile("ofile", 1)| +--system rm -f $MYSQLTEST_VARDIR/tmp/spout +delete from t1| +drop procedure into_outfile| + +--disable_warnings +drop procedure if exists into_dumpfile| +--enable_warnings +create procedure into_dumpfile(x char(16), y int) +begin + insert into test.t1 values (x, y); + select * into dumpfile "../tmp/spdump" from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +--system rm -f $MYSQLTEST_VARDIR/tmp/spdump +call into_dumpfile("dfile", 1)| +--system rm -f $MYSQLTEST_VARDIR/tmp/spdump +delete from t1| +drop procedure into_dumpfile| + +--disable_warnings +drop procedure if exists create_select| +--enable_warnings +create procedure create_select(x char(16), y int) +begin + insert into test.t1 values (x, y); + create temporary table test.t3 select * from test.t1; + insert into test.t3 values (concat(x, "2"), y+2); +end| + +call create_select("cs", 90)| +select * from t1, t3| +drop table t3| +delete from t1| +drop procedure create_select| + + +# A minimal, constant FUNCTION. +--disable_warnings +drop function if exists e| +--enable_warnings +create function e() returns double + return 2.7182818284590452354| + +set @e = e()| +select e(), @e| + +# A minimal function with one argument +--disable_warnings +drop function if exists inc| +--enable_warnings +create function inc(i int) returns int + return i+1| + +select inc(1), inc(99), inc(-71)| + +# A minimal function with two arguments +--disable_warnings +drop function if exists mul| +--enable_warnings +create function mul(x int, y int) returns int + return x*y| + +select mul(1,1), mul(3,5), mul(4711, 666)| + +# A minimal string function +--disable_warnings +drop function if exists append| +--enable_warnings +create function append(s1 char(8), s2 char(8)) returns char(16) + return concat(s1, s2)| + +select append("foo", "bar")| + +# A function with flow control +--disable_warnings +drop function if exists fac| +--enable_warnings +create function fac(n int unsigned) returns bigint unsigned +begin + declare f bigint unsigned default 1; + + while n > 1 do + set f = f * n; + set n = n - 1; + end while; + return f; +end| + +select fac(1), fac(2), fac(5), fac(10)| + +# Nested calls +--disable_warnings +drop function if exists fun| +--enable_warnings +create function fun(d double, i int, u int unsigned) returns double + return mul(inc(i), fac(u)) / e()| + +select fun(2.3, 3, 5)| + + +# Various function calls in differen statements + +insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| +insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| + +# Disable PS because double's give a bit different values +--disable_ps_protocol +select * from t2 where s = append("a", "b")| +select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2)| +select * from t2 where d = e()| +select * from t2| +--enable_ps_protocol +delete from t2| + +drop function e| +drop function inc| +drop function mul| +drop function append| +drop function fun| + + +# +# CONDITIONs and HANDLERs +# + +--disable_warnings +drop procedure if exists hndlr1| +--enable_warnings +create procedure hndlr1(val int) +begin + declare x int default 0; + declare foo condition for 1136; + declare bar condition for sqlstate '42S98'; # Just for testing syntax + declare zip condition for sqlstate value '42S99'; # Just for testing syntax + declare continue handler for foo set x = 1; + + insert into test.t1 values ("hndlr1", val, 2); # Too many values + if (x) then + insert into test.t1 values ("hndlr1", val); # This instead then + end if; +end| + +call hndlr1(42)| +select * from t1| +delete from t1| +drop procedure hndlr1| + +--disable_warnings +drop procedure if exists hndlr2| +--enable_warnings +create procedure hndlr2(val int) +begin + declare x int default 0; + + begin + declare exit handler for sqlstate '21S01' set x = 1; + + insert into test.t1 values ("hndlr2", val, 2); # Too many values + end; + + insert into test.t1 values ("hndlr2", x); +end| + +call hndlr2(42)| +select * from t1| +delete from t1| +drop procedure hndlr2| + + +--disable_warnings +drop procedure if exists hndlr3| +--enable_warnings +create procedure hndlr3(val int) +begin + declare x int default 0; + declare continue handler for sqlexception # Any error + begin + declare z int; + + set z = 2 * val; + set x = 1; + end; + + if val < 10 then + begin + declare y int; + + set y = val + 10; + insert into test.t1 values ("hndlr3", y, 2); # Too many values + if x then + insert into test.t1 values ("hndlr3", y); + end if; + end; + end if; +end| + +call hndlr3(3)| +select * from t1| +delete from t1| +drop procedure hndlr3| + + +# Variables might be uninitialized when using handlers +# (Otherwise the compiler can detect if a variable is not set, but +# not in this case.) +create table t3 ( id char(16), data int )| + +--disable_warnings +drop procedure if exists hndlr4| +--enable_warnings +create procedure hndlr4() +begin + declare x int default 0; + declare val int; # No default + declare continue handler for sqlstate '02000' set x=1; + + select data into val from test.t3 where id='z' limit 1; # No hits + + insert into test.t3 values ('z', val); +end| + +call hndlr4()| +select * from t3| +drop table t3| +drop procedure hndlr4| + + +# +# Cursors +# +--disable_warnings +drop procedure if exists cur1| +--enable_warnings +create procedure cur1() +begin + declare a char(16); + declare b int; + declare c double; + declare done int default 0; + declare c cursor for select * from test.t2; + declare continue handler for sqlstate '02000' set done = 1; + + open c; + repeat + fetch c into a, b, c; + if not done then + insert into test.t1 values (a, b+c); + end if; + until done end repeat; + close c; +end| + +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| +call cur1()| +select * from t1| +drop procedure cur1| + +create table t3 ( s char(16), i int )| + +--disable_warnings +drop procedure if exists cur2| +--enable_warnings +create procedure cur2() +begin + declare done int default 0; + declare c1 cursor for select id,data from test.t1; + declare c2 cursor for select i from test.t2; + declare continue handler for sqlstate '02000' set done = 1; + + open c1; + open c2; + repeat + begin + declare a char(16); + declare b,c int; + + fetch from c1 into a, b; + fetch next from c2 into c; + if not done then + if b < c then + insert into test.t3 values (a, b); + else + insert into test.t3 values (a, c); + end if; + end if; + end; + until done end repeat; + close c1; + close c2; +end| + +call cur2()| +select * from t3| +delete from t1| +delete from t2| +drop table t3| +drop procedure cur2| + + +# The few characteristics we parse +--disable_warnings +drop procedure if exists chistics| +--enable_warnings +create procedure chistics() + language sql + modifies sql data + not deterministic + sql security definer + comment 'Characteristics procedure test' + insert into t1 values ("chistics", 1)| + +show create procedure chistics| +# Call it, just to make sure. +call chistics()| +select * from t1| +delete from t1| +alter procedure chistics sql security invoker| +show create procedure chistics| +drop procedure chistics| + +--disable_warnings +drop function if exists chistics| +--enable_warnings +create function chistics() returns int + language sql + deterministic + sql security invoker + comment 'Characteristics procedure test' + return 42| + +show create function chistics| +# Call it, just to make sure. +select chistics()| +alter function chistics + no sql + comment 'Characteristics function test'| +show create function chistics| +drop function chistics| + + +# Check mode settings +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| + +set @@sql_mode = 'ANSI'| +delimiter $| +--disable_warnings +drop procedure if exists modes$ +--enable_warnings +create procedure modes(out c1 int, out c2 int) +begin + declare done int default 0; + declare x int; + declare c cursor for select data from t1; + declare continue handler for sqlstate '02000' set done = 1; + + select 1 || 2 into c1; + set c2 = 0; + open c; + repeat + fetch c into x; + if not done then + set c2 = c2 + 1; + end if; + until done end repeat; + close c; +end$ +delimiter |$ +set @@sql_mode = ''| + +set sql_select_limit = 1| +call modes(@c1, @c2)| +set sql_select_limit = default| + +select @c1, @c2| +delete from t1| +drop procedure modes| + + +# Check that dropping a database without routines works. +# (Dropping with routines is tested in sp-security.test) +# First an empty db. +create database sp_db1| +drop database sp_db1| + +# Again, with a table. +create database sp_db2| +use sp_db2| +# Just put something in here... +create table t3 ( s char(4), t int )| +insert into t3 values ("abcd", 42), ("dcba", 666)| +use test| +drop database sp_db2| + +# And yet again, with just a procedure. +create database sp_db3| +use sp_db3| +--disable_warnings +drop procedure if exists dummy| +--enable_warnings +create procedure dummy(out x int) + set x = 42| +use test| +drop database sp_db3| +# Check that it's gone +select type,db,name from mysql.proc where db = 'sp_db3'| + + +# ROW_COUNT() function after a CALL +# We test the other cases here too, although it's not strictly SP specific +--disable_warnings +drop procedure if exists rc| +--enable_warnings +create procedure rc() +begin + delete from t1; + insert into t1 values ("a", 1), ("b", 2), ("c", 3); +end| + +call rc()| +select row_count()| +--disable_ps_protocol +update t1 set data=42 where id = "b"; +select row_count()| +--enable_ps_protocol +delete from t1| +select row_count()| +delete from t1| +select row_count()| +select * from t1| +select row_count()| +drop procedure rc| + + +# +# Let us test how well new locking scheme works. +# + +# Let us prepare playground +--disable_warnings +drop function if exists f0| +drop function if exists f1| +drop function if exists f2| +drop function if exists f3| +drop function if exists f4| +drop function if exists f5| +drop function if exists f6| +drop function if exists f7| +drop function if exists f8| +drop function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| +drop view if exists v0| +drop view if exists v1| +drop view if exists v2| +--enable_warnings +delete from t1| +delete from t2| +insert into t1 values ("a", 1), ("b", 2) | +insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | + +# Test the simplest function using tables +create function f1() returns int + return (select sum(data) from t1)| +select f1()| +# This should work too (and give 2 rows as result) +select id, f1() from t1| + +# Function which uses two instances of table simultaneously +create function f2() returns int + return (select data from t1 where data <= (select sum(data) from t1) limit 1)| +select f2()| +select id, f2() from t1| + +# Function which uses the same table twice in different queries +create function f3() returns int +begin + declare n int; + declare m int; + set n:= (select min(data) from t1); + set m:= (select max(data) from t1); + return n < m; +end| +select f3()| +select id, f3() from t1| + +# Calling two functions using same table +select f1(), f3()| +select id, f1(), f3() from t1| + +# Function which uses two different tables +create function f4() returns double + return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| +select f4()| +select s, f4() from t2| + +# Recursive functions which due to this recursion require simultaneous +# access to several instance of the same table won't work +create function f5(i int) returns int +begin + if i <= 0 then + return 0; + elseif i = 1 then + return (select count(*) from t1 where data = i); + else + return (select count(*) + f5( i - 1) from t1 where data = i); + end if; +end| +select f5(1)| +# Since currently recursive functions are disallowed ER_SP_NO_RECURSION +# error will be returned, once we will allow them error about +# insufficient number of locked tables will be returned instead. +--error ER_SP_NO_RECURSION +select f5(2)| +--error ER_SP_NO_RECURSION +select f5(3)| + +# OTOH this should work +create function f6() returns int +begin + declare n int; + set n:= f1(); + return (select count(*) from t1 where data <= f7() and data <= n); +end| +create function f7() returns int + return (select sum(data) from t1 where data <= f1())| +select f6()| +select id, f6() from t1| + +# +# Let us test how new locking work with views +# +# The most trivial view +create view v1 (a) as select f1()| +select * from v1| +select id, a from t1, v1| +select * from v1, v1 as v| +# A bit more complex construction +create view v2 (a) as select a*10 from v1| +select * from v2| +select id, a from t1, v2| +select * from v1, v2| + +# Nice example where the same view is used on +# on different expression levels +create function f8 () returns int + return (select count(*) from v2)| + +select *, f8() from v1| + +# Let us test what will happen if function is missing +drop function f1| +--error 1356 +select * from v1| + +# And what will happen if we have recursion which involves +# views and functions ? +create function f1() returns int + return (select sum(data) from t1) + (select sum(data) from v1)| +--error ER_SP_NO_RECURSION +select f1()| +--error ER_SP_NO_RECURSION +select * from v1| +--error ER_SP_NO_RECURSION +select * from v2| +# Back to the normal cases +drop function f1| +create function f1() returns int + return (select sum(data) from t1)| + +# Let us also test some weird cases where no real tables is used +create function f0() returns int + return (select * from (select 100) as r)| +select f0()| +select *, f0() from (select 1) as t| +create view v0 as select f0()| +select * from v0| +select *, f0() from v0| + +# +# Let us test how well prelocking works with explicit LOCK TABLES. +# +lock tables t1 read, t1 as t11 read| +# These should work well +select f3()| +select id, f3() from t1 as t11| +# Degenerate cases work too :) +select f0()| +select * from v0| +select *, f0() from v0, (select 123) as d1| +# But these should not ! +--error 1100 +select id, f3() from t1| +--error 1100 +select f4()| +unlock tables| + +# Let us test how LOCK TABLES which implicitly depends on functions +# works +lock tables v2 read, mysql.proc read| +select * from v2| +select * from v1| +# These should not work as we have too little instances of tables locked +--error 1100 +select * from v1, t1| +--error 1100 +select f4()| +unlock tables| + +# Tests for handling of temporary tables in functions. +# +# Unlike for permanent tables we should be able to create, use +# and drop such tables in functions. +# +# Simplest function using temporary table. It is also test case for bug +# #12198 "Temporary table aliasing does not work inside stored functions" +create function f9() returns int +begin + declare a, b int; + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + set a:= (select count(*) from t3); + set b:= (select count(*) from t3 t3_alias); + return a + b; +end| +# This will emit warning as t3 was not existing before. +select f9()| +select f9() from t1 limit 1| + +# Function which uses both temporary and permanent tables. +create function f10() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 select id from t4; + return (select count(*) from t3); +end| +# Check that we don't ignore completely tables used in function +--error ER_NO_SUCH_TABLE +select f10()| +create table t4 as select 1 as id| +select f10()| + +# Practical cases which we don't handle well (yet) +# +# Function which does not work because of well-known and documented +# limitation of MySQL. We can't use the several instances of the +# same temporary table in statement. +create function f11() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return (select count(*) from t3 as a, t3 as b); +end| +--error ER_CANT_REOPEN_TABLE +select f11()| +--error ER_CANT_REOPEN_TABLE +select f11() from t1| +# We don't handle temporary tables used by nested functions well +create function f12_1() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return f12_2(); +end| +create function f12_2() returns int + return (select count(*) from t3)| +# We need clean start to get error +drop temporary table t3| +--error ER_NO_SUCH_TABLE +select f12_1()| +--error ER_NO_SUCH_TABLE +select f12_1() from t1 limit 1| + +# Cleanup +drop function f0| +drop function f1| +drop function f2| +drop function f3| +drop function f4| +drop function f5| +drop function f6| +drop function f7| +drop function f8| +drop function f9| +drop function f10| +drop function f11| +drop function f12_1| +drop function f12_2| +drop view v0| +drop view v1| +drop view v2| +delete from t1 | +delete from t2 | +drop table t4| + +# End of non-bug tests + + +# +# Some "real" examples +# + +# fac + +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 (n int unsigned not null primary key, f bigint unsigned)| + +--disable_warnings +drop procedure if exists ifac| +--enable_warnings +create procedure ifac(n int unsigned) +begin + declare i int unsigned default 1; + + if n > 20 then + set n = 20; # bigint overflow otherwise + end if; + while i <= n do + begin + insert into test.t3 values (i, fac(i)); + set i = i + 1; + end; + end while; +end| + +call ifac(20)| +select * from t3| +drop table t3| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like '%f%'| +drop procedure ifac| +drop function fac| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like '%f%'| + + +# primes + +--disable_warnings +drop table if exists t3| +--enable_warnings + +create table t3 ( + i int unsigned not null primary key, + p bigint unsigned not null +)| + +insert into t3 values + ( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), + ( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), + (10, 37), (11, 41), (12, 43), (13, 47), (14, 53), + (15, 59), (16, 61), (17, 67), (18, 71), (19, 73), + (20, 79), (21, 83), (22, 89), (23, 97), (24, 101), + (25, 103), (26, 107), (27, 109), (28, 113), (29, 127), + (30, 131), (31, 137), (32, 139), (33, 149), (34, 151), + (35, 157), (36, 163), (37, 167), (38, 173), (39, 179), + (40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| + +--disable_warnings +drop procedure if exists opp| +--enable_warnings +create procedure opp(n bigint unsigned, out pp bool) +begin + declare r double; + declare b, s bigint unsigned default 0; + + set r = sqrt(n); + + again: + loop + if s = 45 then + set b = b+200, s = 0; + else + begin + declare p bigint unsigned; + + select t.p into p from test.t3 t where t.i = s; + if b+p > r then + set pp = 1; + leave again; + end if; + if mod(n, b+p) = 0 then + set pp = 0; + leave again; + end if; + set s = s+1; + end; + end if; + end loop; +end| + +--disable_warnings +drop procedure if exists ip| +--enable_warnings +create procedure ip(m int unsigned) +begin + declare p bigint unsigned; + declare i int unsigned; + + set i=45, p=201; + + while i < m do + begin + declare pp bool default 0; + + call opp(p, pp); + if pp then + insert into test.t3 values (i, p); + set i = i+1; + end if; + set p = p+2; + end; + end while; +end| +show create procedure opp| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like '%p%'| + +# This isn't the fastest way in the world to compute prime numbers, so +# don't be too ambitious. ;-) +call ip(200)| +# We don't want to select the entire table here, just pick a few +# examples. +# The expected result is: +# i p +# --- ---- +# 45 211 +# 100 557 +# 199 1229 +select * from t3 where i=45 or i=100 or i=199| +drop table t3| +drop procedure opp| +drop procedure ip| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like '%p%'| + + +# Fibonacci, for recursion test. (Yet Another Numerical series :) +# +--disable_warnings +drop table if exists t3| +--enable_warnings +create table t3 ( f bigint unsigned not null )| + +# We deliberately do it the awkward way, fetching the last two +# values from the table, in order to exercise various statements +# and table accesses at each turn. +--disable_warnings +drop procedure if exists fib| +--enable_warnings +create procedure fib(n int unsigned) +begin + if n > 1 then + begin + declare x, y bigint unsigned; + declare c cursor for select f from t3 order by f desc limit 2; + + open c; + fetch c into y; + fetch c into x; + close c; + insert into t3 values (x+y); + call fib(n-1); + end; + end if; +end| + +# Enable recursion +set @@max_sp_recursion_depth= 20| + +# Minimum test: recursion of 3 levels + +insert into t3 values (0), (1)| + +call fib(3)| + +select * from t3 order by f asc| + +delete from t3| + +# The original test, 20 levels, ran into memory limits on some machines +# and builds. Try 10 instead... + +insert into t3 values (0), (1)| + +call fib(10)| + +select * from t3 order by f asc| +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| + +# +# Comment & suid +# + +--disable_warnings +drop procedure if exists bar| +--enable_warnings +create procedure bar(x char(16), y int) + comment "111111111111" sql security invoker + insert into test.t1 values (x, y)| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bar'| +alter procedure bar comment "2222222222" sql security definer| +alter procedure bar comment "3333333333"| +alter procedure bar| +show create procedure bar| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bar'| +drop procedure bar| + +# +# rexecution +# +--disable_warnings +drop procedure if exists p1| +--enable_warnings +create procedure p1 () + select (select s1 from t3) from t3| + +create table t3 (s1 int)| + +call p1()| +insert into t3 values (1)| +call p1()| +drop procedure p1| +drop table t3| + +# +# backticks +# +--disable_warnings +drop function if exists foo| +--enable_warnings +create function `foo` () returns int + return 5| +select `foo` ()| +drop function `foo`| + +# +# Implicit LOCK/UNLOCK TABLES for table access in functions +# + +--disable_warnings +drop function if exists t1max| +--enable_warnings +create function t1max() returns int +begin + declare x int; + select max(data) into x from t1; + return x; +end| + +insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| +select t1max()| +drop function t1max| + +create table t3 ( + v char(16) not null primary key, + c int unsigned not null +)| + +create function getcount(s char(16)) returns int +begin + declare x int; + + select count(*) into x from t3 where v = s; + if x = 0 then + insert into t3 values (s, 1); + else + update t3 set c = c+1 where v = s; + end if; + return x; +end| + +select * from t1 where data = getcount("bar")| +select * from t3| +select getcount("zip")| +select getcount("zip")| +select * from t3| +select getcount(id) from t1 where data = 3| +select getcount(id) from t1 where data = 5| +select * from t3| +drop table t3| +drop function getcount| + + +# Test cases for different combinations of condition handlers in nested +# begin-end blocks in stored procedures. +# +# Note that the standard specifies that the most specific handler should +# be triggered even if it's an outer handler masked by a less specific +# handler in an inner block. +# Note also that '02000' is more specific than NOT FOUND; there might be +# other '02xxx' states, even if we currently do not issue them in any +# situation (e.g. '02001'). +# +# The combinations we test are these: +# +# Inner +# errcode sqlstate not found sqlwarning sqlexception +# Outer +------------+------------+------------+------------+------------+ +#errcode | h_ee (i) | h_es (o) | h_en (o) | h_ew (o) | h_ex (o) | +#sqlstate | h_se (i) | h_ss (i) | h_sn (o) | h_sw (o) | h_sx (o) | +#not found | h_ne (i) | h_ns (i) | h_nn (i) | | | +#sqlwarning | h_we (i) | h_ws (i) | | h_ww (i) | | +#sqlexception | h_xe (i) | h_xs (i) | | | h_xx (i) | +# +------------+---------------------------------------------------+ +# +# (i) means that the inner handler is the one that should be invoked, +# (o) means that the outer handler should be invoked. +# +# ('not found', 'sqlwarning' and 'sqlexception' are mutually exclusive, hence +# no tests for those combinations.) +# + +--disable_warnings +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +--enable_warnings + +# smallint - to get out of range warnings +# primary key - to get constraint errors +create table t3 (a smallint primary key)| + +insert into t3 (a) values (1)| + +create procedure h_ee() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (bad)' as 'h_ee'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_ee'; + + insert into t3 values (1); + end; +end| + +create procedure h_es() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (good)' as 'h_es'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (bad)' as 'h_es'; + + insert into t3 values (1); + end; +end| + +create procedure h_en() + deterministic +begin + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Outer (good)' as 'h_en'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (bad)' as 'h_en'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_ew() + deterministic +begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Outer (good)' as 'h_ew'; + + begin + declare continue handler for sqlwarning + select 'Inner (bad)' as 'h_ew'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ex() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (good)' as 'h_ex'; + + begin + declare continue handler for sqlexception + select 'Inner (bad)' as 'h_ex'; + + insert into t3 values (1); + end; +end| + +create procedure h_se() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_se'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_se'; + + insert into t3 values (1); + end; +end| + +create procedure h_ss() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_ss'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_ss'; + + insert into t3 values (1); + end; +end| + +create procedure h_sn() + deterministic +begin + -- Note: '02000' is more specific than NOT FOUND ; + -- there might be other not found states + declare continue handler for sqlstate '02000' -- no data + select 'Outer (good)' as 'h_sn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (bad)' as 'h_sn'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_sw() + deterministic +begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Outer (good)' as 'h_sw'; + + begin + declare continue handler for sqlwarning + select 'Inner (bad)' as 'h_sw'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_sx() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (good)' as 'h_sx'; + + begin + declare continue handler for sqlexception + select 'Inner (bad)' as 'h_sx'; + + insert into t3 values (1); + end; +end| + +create procedure h_ne() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ne'; + + begin + declare x int; + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Inner (good)' as 'h_ne'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_ns() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ns'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (good)' as 'h_ns'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_nn() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_nn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (good)' as 'h_nn'; + + select a into x from t3 where a = 42; + end; +end| + +create procedure h_we() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_we'; + + begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Inner (good)' as 'h_we'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ws() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ws'; + + begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ww() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ww'; + + begin + declare continue handler for sqlwarning + select 'Inner (good)' as 'h_ww'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_xe() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xe'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_xe'; + + insert into t3 values (1); + end; +end| + +create procedure h_xs() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xs'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; + + insert into t3 values (1); + end; +end| + +create procedure h_xx() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xx'; + + begin + declare continue handler for sqlexception + select 'Inner (good)' as 'h_xx'; + + insert into t3 values (1); + end; +end| + +call h_ee()| +call h_es()| +call h_en()| +call h_ew()| +call h_ex()| +call h_se()| +call h_ss()| +call h_sn()| +call h_sw()| +call h_sx()| +call h_ne()| +call h_ns()| +call h_nn()| +call h_we()| +call h_ws()| +call h_ww()| +call h_xe()| +call h_xs()| +call h_xx()| + +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| + + +# +# Test cases for old bugs +# + +# +# BUG#822 +# +--disable_warnings +drop procedure if exists bug822| +--enable_warnings +create procedure bug822(a_id char(16), a_data int) +begin + declare n int; + select count(*) into n from t1 where id = a_id and data = a_data; + if n = 0 then + insert into t1 (id, data) values (a_id, a_data); + end if; +end| + +delete from t1| +call bug822('foo', 42)| +call bug822('foo', 42)| +call bug822('bar', 666)| +select * from t1| +delete from t1| +drop procedure bug822| + +# +# BUG#1495 +# +--disable_warnings +drop procedure if exists bug1495| +--enable_warnings +create procedure bug1495() +begin + declare x int; + + select data into x from t1 order by id limit 1; + if x > 10 then + insert into t1 values ("less", x-10); + else + insert into t1 values ("more", x+10); + end if; +end| + +insert into t1 values ('foo', 12)| +call bug1495()| +delete from t1 where id='foo'| +insert into t1 values ('bar', 7)| +call bug1495()| +delete from t1 where id='bar'| +select * from t1| +delete from t1| +drop procedure bug1495| + +# +# BUG#1547 +# +--disable_warnings +drop procedure if exists bug1547| +--enable_warnings +create procedure bug1547(s char(16)) +begin + declare x int; + + select data into x from t1 where s = id limit 1; + if x > 10 then + insert into t1 values ("less", x-10); + else + insert into t1 values ("more", x+10); + end if; +end| + +insert into t1 values ("foo", 12), ("bar", 7)| +call bug1547("foo")| +call bug1547("bar")| +select * from t1| +delete from t1| +drop procedure bug1547| + +# +# BUG#1656 +# +--disable_warnings +drop table if exists t70| +--enable_warnings +create table t70 (s1 int,s2 int)| +insert into t70 values (1,2)| + +--disable_warnings +drop procedure if exists bug1656| +--enable_warnings +create procedure bug1656(out p1 int, out p2 int) + select * into p1, p1 from t70| + +call bug1656(@1, @2)| +select @1, @2| +drop table t70| +drop procedure bug1656| + +# +# BUG#1862 +# +create table t3(a int)| + +--disable_warnings +drop procedure if exists bug1862| +--enable_warnings +create procedure bug1862() +begin + insert into t3 values(2); + flush tables; +end| + +call bug1862()| +# the second call caused a segmentation +call bug1862()| +select * from t3| +drop table t3| +drop procedure bug1862| + +# +# BUG#1874 +# +--disable_warnings +drop procedure if exists bug1874| +--enable_warnings +create procedure bug1874() +begin + declare x int; + declare y double; + select max(data) into x from t1; + insert into t2 values ("max", x, 0); + select min(data) into x from t1; + insert into t2 values ("min", x, 0); + select sum(data) into x from t1; + insert into t2 values ("sum", x, 0); + select avg(data) into y from t1; + insert into t2 values ("avg", 0, y); +end| + +insert into t1 (data) values (3), (1), (5), (9), (4)| +call bug1874()| +select * from t2| +delete from t1| +delete from t2| +drop procedure bug1874| + +# +# BUG#2260 +# +--disable_warnings +drop procedure if exists bug2260| +--enable_warnings +create procedure bug2260() +begin + declare v1 int; + declare c1 cursor for select data from t1; + declare continue handler for not found set @x2 = 1; + + open c1; + fetch c1 into v1; + set @x2 = 2; + close c1; +end| + +call bug2260()| +select @x2| +drop procedure bug2260| + +# +# BUG#2267 "Lost connect if stored procedure has SHOW FUNCTION STATUS" +# +--disable_warnings +drop procedure if exists bug2267_1| +--enable_warnings +create procedure bug2267_1() +begin + show procedure status; +end| + +--disable_warnings +drop procedure if exists bug2267_2| +--enable_warnings +create procedure bug2267_2() +begin + show function status; +end| + +--disable_warnings +drop procedure if exists bug2267_3| +--enable_warnings +create procedure bug2267_3() +begin + show create procedure bug2267_1; +end| + +--disable_warnings +drop procedure if exists bug2267_4| +drop function if exists bug2267_4| +--enable_warnings +create procedure bug2267_4() +begin + show create function bug2267_4; +end| +create function bug2267_4() returns int return 100| + +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +call bug2267_1()| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +call bug2267_2()| +call bug2267_3()| +call bug2267_4()| + +drop procedure bug2267_1| +drop procedure bug2267_2| +drop procedure bug2267_3| +drop procedure bug2267_4| +drop function bug2267_4| + +# +# BUG#2227 +# +--disable_warnings +drop procedure if exists bug2227| +--enable_warnings +create procedure bug2227(x int) +begin + declare y float default 2.6; + declare z char(16) default "zzz"; + + select 1.3, x, y, 42, z; +end| + +call bug2227(9)| +drop procedure bug2227| + +# +# BUG#2614 "Stored procedure with INSERT ... SELECT that does not +# contain any tables crashes server" +# +--disable_warnings +drop procedure if exists bug2614| +--enable_warnings +create procedure bug2614() +begin + drop table if exists t3; + create table t3 (id int default '0' not null); + insert into t3 select 12; + insert into t3 select * from t3; +end| + +--disable_warnings +call bug2614()| +--enable_warnings +call bug2614()| +drop table t3| +drop procedure bug2614| + +# +# BUG#2674 +# +--disable_warnings +drop function if exists bug2674| +--enable_warnings +create function bug2674() returns int + return @@sort_buffer_size| + +set @osbs = @@sort_buffer_size| +set @@sort_buffer_size = 262000| +select bug2674()| +drop function bug2674| +set @@sort_buffer_size = @osbs| + +# +# BUG#3259 +# +--disable_warnings +drop procedure if exists bug3259_1 | +--enable_warnings +create procedure bug3259_1 () begin end| +--disable_warnings +drop procedure if exists BUG3259_2 | +--enable_warnings +create procedure BUG3259_2 () begin end| +--disable_warnings +drop procedure if exists Bug3259_3 | +--enable_warnings +create procedure Bug3259_3 () begin end| + +call BUG3259_1()| +call BUG3259_1()| +call bug3259_2()| +call Bug3259_2()| +call bug3259_3()| +call bUG3259_3()| + +drop procedure bUg3259_1| +drop procedure BuG3259_2| +drop procedure BUG3259_3| + +# +# BUG#2772 +# +--disable_warnings +drop function if exists bug2772| +--enable_warnings +create function bug2772() returns char(10) character set latin2 + return 'a'| + +select bug2772()| +drop function bug2772| + +# +# BUG#2776 +# +--disable_warnings +drop procedure if exists bug2776_1| +--enable_warnings +create procedure bug2776_1(out x int) +begin + declare v int; + + set v = default; + set x = v; +end| + +--disable_warnings +drop procedure if exists bug2776_2| +--enable_warnings +create procedure bug2776_2(out x int) +begin + declare v int default 42; + + set v = default; + set x = v; +end| + +set @x = 1| +call bug2776_1(@x)| +select @x| +call bug2776_2(@x)| +select @x| +drop procedure bug2776_1| +drop procedure bug2776_2| + +# +# BUG#2780 +# +create table t3 (s1 smallint)| + +insert into t3 values (123456789012)| + +--disable_warnings +drop procedure if exists bug2780| +--enable_warnings +create procedure bug2780() +begin + declare exit handler for sqlwarning set @x = 1; + + set @x = 0; + insert into t3 values (123456789012); + insert into t3 values (0); +end| + +call bug2780()| +select @x| +select * from t3| + +drop procedure bug2780| +drop table t3| + +# +# BUG#1863 +# +create table t3 (content varchar(10) )| +insert into t3 values ("test1")| +insert into t3 values ("test2")| +create table t4 (f1 int, rc int, t3 int)| + +--disable_warnings +drop procedure if exists bug1863| +--enable_warnings +create procedure bug1863(in1 int) +begin + + declare ind int default 0; + declare t1 int; + declare t2 int; + declare t3 int; + + declare rc int default 0; + declare continue handler for 1065 set rc = 1; + + drop temporary table if exists temp_t1; + create temporary table temp_t1 ( + f1 int auto_increment, f2 varchar(20), primary key (f1) + ); + + insert into temp_t1 (f2) select content from t3; + + select f2 into t3 from temp_t1 where f1 = 10; + + if (rc) then + insert into t4 values (1, rc, t3); + end if; + + insert into t4 values (2, rc, t3); + +end| + +call bug1863(10)| +call bug1863(10)| +select * from t4| + +drop procedure bug1863| +drop temporary table temp_t1; +drop table t3, t4| + +# +# BUG#2656 +# + +create table t3 ( + OrderID int not null, + MarketID int, + primary key (OrderID) +)| + +create table t4 ( + MarketID int not null, + Market varchar(60), + Status char(1), + primary key (MarketID) +)| + +insert t3 (OrderID,MarketID) values (1,1)| +insert t3 (OrderID,MarketID) values (2,2)| +insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| +insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| + +--disable_warnings +drop procedure if exists bug2656_1| +--enable_warnings +create procedure bug2656_1() +begin + select + m.Market + from t4 m JOIN t3 o + ON o.MarketID != 1 and o.MarketID = m.MarketID; +end | + +--disable_warnings +drop procedure if exists bug2656_2| +--enable_warnings +create procedure bug2656_2() +begin + select + m.Market + from + t4 m, t3 o + where + m.MarketID != 1 and m.MarketID = o.MarketID; + +end | + +call bug2656_1()| +call bug2656_1()| +call bug2656_2()| +call bug2656_2()| +drop procedure bug2656_1| +drop procedure bug2656_2| +drop table t3, t4| + + +# +# BUG#3426 +# +--disable_warnings +drop procedure if exists bug3426| +--enable_warnings +create procedure bug3426(in_time int unsigned, out x int) +begin + if in_time is null then + set @stamped_time=10; + set x=1; + else + set @stamped_time=in_time; + set x=2; + end if; +end| + +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +# Clear SP cache +alter procedure bug3426 sql security invoker| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| + +drop procedure bug3426| + +# +# BUG#3448 +# +--disable_warnings +create table t3 ( + a int primary key, + ach char(1) +) engine = innodb| + +create table t4 ( + b int primary key , + bch char(1) +) engine = innodb| +--enable_warnings + +insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')| +insert into t4 values (1 , 'bCh1' )| + +--disable_warnings +drop procedure if exists bug3448| +--enable_warnings +create procedure bug3448() + select * from t3 inner join t4 on t3.a = t4.b| + +select * from t3 inner join t4 on t3.a = t4.b| +call bug3448()| +call bug3448()| + +drop procedure bug3448| +drop table t3, t4| + + +# +# BUG#3734 +# +create table t3 ( + id int unsigned auto_increment not null primary key, + title VARCHAR(200), + body text, + fulltext (title,body) +)| + +insert into t3 (title,body) values + ('MySQL Tutorial','DBMS stands for DataBase ...'), + ('How To Use MySQL Well','After you went through a ...'), + ('Optimizing MySQL','In this tutorial we will show ...'), + ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), + ('MySQL vs. YourSQL','In the following database comparison ...'), + ('MySQL Security','When configured properly, MySQL ...')| + +--disable_warnings +drop procedure if exists bug3734 | +--enable_warnings +create procedure bug3734 (param1 varchar(100)) + select * from t3 where match (title,body) against (param1)| + +call bug3734('database')| +call bug3734('Security')| + +drop procedure bug3734| +drop table t3| + +# +# BUG#3863 +# +--disable_warnings +drop procedure if exists bug3863| +--enable_warnings +create procedure bug3863() +begin + set @a = 0; + while @a < 5 do + set @a = @a + 1; + end while; +end| + +call bug3863()| +select @a| +call bug3863()| +select @a| + +drop procedure bug3863| + +# +# BUG#2460 +# + +create table t3 ( + id int(10) unsigned not null default 0, + rid int(10) unsigned not null default 0, + msg text not null, + primary key (id), + unique key rid (rid, id) +)| + +--disable_warnings +drop procedure if exists bug2460_1| +--enable_warnings +create procedure bug2460_1(in v int) +begin + ( select n0.id from t3 as n0 where n0.id = v ) + union + ( select n0.id from t3 as n0, t3 as n1 + where n0.id = n1.rid and n1.id = v ) + union + ( select n0.id from t3 as n0, t3 as n1, t3 as n2 + where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ); +end| + +call bug2460_1(2)| +call bug2460_1(2)| +insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| +call bug2460_1(2)| +call bug2460_1(2)| + +--disable_warnings +drop procedure if exists bug2460_2| +--enable_warnings +create procedure bug2460_2() +begin + drop table if exists t3; + create temporary table t3 (s1 int); + insert into t3 select 1 union select 1; +end| + +call bug2460_2()| +call bug2460_2()| +select * from t3| + +drop procedure bug2460_1| +drop procedure bug2460_2| +drop table t3| + + +# +# BUG#2564 +# +set @@sql_mode = ''| +--disable_warnings +drop procedure if exists bug2564_1| +--enable_warnings +create procedure bug2564_1() + comment 'Joe''s procedure' + insert into `t1` values ("foo", 1)| + +set @@sql_mode = 'ANSI_QUOTES'| +--disable_warnings +drop procedure if exists bug2564_2| +--enable_warnings +create procedure bug2564_2() + insert into "t1" values ('foo', 1)| + +delimiter $| +set @@sql_mode = ''$ +--disable_warnings +drop function if exists bug2564_3$ +--enable_warnings +create function bug2564_3(x int, y int) returns int + return x || y$ + +set @@sql_mode = 'ANSI'$ +--disable_warnings +drop function if exists bug2564_4$ +--enable_warnings +create function bug2564_4(x int, y int) returns int + return x || y$ +delimiter |$ + +set @@sql_mode = ''| +show create procedure bug2564_1| +show create procedure bug2564_2| +show create function bug2564_3| +show create function bug2564_4| + +drop procedure bug2564_1| +drop procedure bug2564_2| +drop function bug2564_3| +drop function bug2564_4| + +# +# BUG#3132 +# +--disable_warnings +drop function if exists bug3132| +--enable_warnings +create function bug3132(s char(20)) returns char(50) + return concat('Hello, ', s, '!')| + +select bug3132('Bob') union all select bug3132('Judy')| +drop function bug3132| + +# +# BUG#3843 +# +--disable_warnings +drop procedure if exists bug3843| +--enable_warnings +create procedure bug3843() + analyze table t1| + +# Testing for packets out of order +call bug3843()| +call bug3843()| +select 1+2| + +drop procedure bug3843| + +# +# BUG#3368 +# +create table t3 ( s1 char(10) )| +insert into t3 values ('a'), ('b')| + +--disable_warnings +drop procedure if exists bug3368| +--enable_warnings +create procedure bug3368(v char(10)) +begin + select group_concat(v) from t3; +end| + +call bug3368('x')| +call bug3368('yz')| +drop procedure bug3368| +drop table t3| + +# +# BUG#4579 +# +create table t3 (f1 int, f2 int)| +insert into t3 values (1,1)| + +--disable_warnings +drop procedure if exists bug4579_1| +--enable_warnings +create procedure bug4579_1 () +begin + declare sf1 int; + + select f1 into sf1 from t3 where f1=1 and f2=1; + update t3 set f2 = f2 + 1 where f1=1 and f2=1; + call bug4579_2(); +end| + +--disable_warnings +drop procedure if exists bug4579_2| +--enable_warnings +create procedure bug4579_2 () +begin +end| + +call bug4579_1()| +call bug4579_1()| +call bug4579_1()| + +drop procedure bug4579_1| +drop procedure bug4579_2| +drop table t3| + +# +# BUG#2773: Function's data type ignored in stored procedures +# +--disable_warnings +drop procedure if exists bug2773| +--enable_warnings + +create function bug2773() returns int return null| +create table t3 as select bug2773()| +show create table t3| +drop table t3| +drop function bug2773| + +# +# BUG#3788: Stored procedure packet error +# +--disable_warnings +drop procedure if exists bug3788| +--enable_warnings + +create function bug3788() returns date return cast("2005-03-04" as date)| +select bug3788()| +drop function bug3788| + +create function bug3788() returns binary(1) return 5| +select bug3788()| +drop function bug3788| + + +# +# BUG#4726 +# +create table t3 (f1 int, f2 int, f3 int)| +insert into t3 values (1,1,1)| + +--disable_warnings +drop procedure if exists bug4726| +--enable_warnings +create procedure bug4726() +begin + declare tmp_o_id INT; + declare tmp_d_id INT default 1; + + while tmp_d_id <= 2 do + begin + select f1 into tmp_o_id from t3 where f2=1 and f3=1; + set tmp_d_id = tmp_d_id + 1; + end; + end while; +end| + +call bug4726()| +call bug4726()| +call bug4726()| + +drop procedure bug4726| +drop table t3| + +# +# BUG#4318 +# + +--disable_parsing # Don't know if HANDLER commands can work with SPs, or at all.. +create table t3 (s1 int)| +insert into t3 values (3), (4)| + +--disable_warnings +drop procedure if exists bug4318| +--enable_warnings +create procedure bug4318() + handler t3 read next| + +handler t3 open| +# Expect no results, as tables are closed, but there shouldn't be any errors +call bug4318()| +call bug4318()| +handler t3 close| + +drop procedure bug4318| +drop table t3| +--enable_parsing + +# +# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error +# +# Added tests for most other show commands we could find too. +# (Skipping those already tested, and the ones depending on optional handlers.) +# +# Note: This will return a large number of results of different formats, +# which makes it impossible to filter with --replace_column. +# It's possible that some of these are not deterministic across +# platforms. If so, just remove the offending command. +# +--disable_warnings +drop procedure if exists bug4902| +--enable_warnings +create procedure bug4902() +begin + show charset like 'foo'; + show collation like 'foo'; + show column types; + show create table t1; + show create database test; + show databases like 'foo'; + show errors; + show columns from t1; + show grants for 'root'@'localhost'; + show keys from t1; + show open tables like 'foo'; + show privileges; + show status like 'foo'; + show tables like 'foo'; + show variables like 'foo'; + show warnings; +end| +--disable_parsing +show binlog events; +show storage engines; +show master status; +show slave hosts; +show slave status; +--enable_parsing + +call bug4902()| +call bug4902()| + +drop procedure bug4902| + +# We need separate SP for SHOW PROCESSLIST since we want use replace_column +--disable_warnings +drop procedure if exists bug4902_2| +--enable_warnings +create procedure bug4902_2() +begin + show processlist; +end| +--replace_column 1 # 6 # 3 localhost +call bug4902_2()| +--replace_column 1 # 6 # 3 localhost +call bug4902_2()| +drop procedure bug4902_2| + +# +# BUG#4904 +# +--disable_warnings +drop procedure if exists bug4904| +--enable_warnings +create procedure bug4904() +begin + declare continue handler for sqlstate 'HY000' begin end; + + create table t2 as select * from t3; +end| + +-- error 1146 +call bug4904()| + +drop procedure bug4904| + +create table t3 (s1 char character set latin1, s2 char character set latin2)| + +--disable_warnings +drop procedure if exists bug4904| +--enable_warnings +create procedure bug4904 () +begin + declare continue handler for sqlstate 'HY000' begin end; + + select s1 from t3 union select s2 from t3; +end| + +call bug4904()| + +drop procedure bug4904| +drop table t3| + +# +# BUG#336 +# +--disable_warnings +drop procedure if exists bug336| +--enable_warnings +create procedure bug336(out y int) +begin + declare x int; + set x = (select sum(t.data) from test.t1 t); + set y = x; +end| + +insert into t1 values ("a", 2), ("b", 3)| +call bug336(@y)| +select @y| +delete from t1| +drop procedure bug336| + +# +# BUG#3157 +# +--disable_warnings +drop procedure if exists bug3157| +--enable_warnings +create procedure bug3157() +begin + if exists(select * from t1) then + set @n= @n + 1; + end if; + if (select count(*) from t1) then + set @n= @n + 1; + end if; +end| + +set @n = 0| +insert into t1 values ("a", 1)| +call bug3157()| +select @n| +delete from t1| +drop procedure bug3157| + +# +# BUG#5251: mysql changes creation time of a procedure/function when altering +# +--disable_warnings +drop procedure if exists bug5251| +--enable_warnings +create procedure bug5251() +begin +end| + +select created into @c1 from mysql.proc + where db='test' and name='bug5251'| +--sleep 2 +alter procedure bug5251 comment 'foobar'| +select count(*) from mysql.proc + where db='test' and name='bug5251' and created = @c1| + +drop procedure bug5251| + +# +# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE +# +--disable_warnings +drop procedure if exists bug5251| +--enable_warnings +create procedure bug5251() + checksum table t1| + +call bug5251()| +call bug5251()| +drop procedure bug5251| + +# +# BUG#5287: Stored procedure crash if leave outside loop +# +--disable_warnings +drop procedure if exists bug5287| +--enable_warnings +create procedure bug5287(param1 int) +label1: + begin + declare c cursor for select 5; + + loop + if param1 >= 0 then + leave label1; + end if; + end loop; +end| +call bug5287(1)| +drop procedure bug5287| + + +# +# BUG#5307: Stored procedure allows statement after BEGIN ... END +# +--disable_warnings +drop procedure if exists bug5307| +--enable_warnings +create procedure bug5307() +begin +end; set @x = 3| + +call bug5307()| +select @x| +drop procedure bug5307| + +# +# BUG#5258: Stored procedure modified date is 0000-00-00 +# (This was a design flaw) +--disable_warnings +drop procedure if exists bug5258| +--enable_warnings +create procedure bug5258() +begin +end| + +--disable_warnings +drop procedure if exists bug5258_aux| +--enable_warnings +create procedure bug5258_aux() +begin + declare c, m char(19); + + select created,modified into c,m from mysql.proc where name = 'bug5258'; + if c = m then + select 'Ok'; + else + select c, m; + end if; +end| + +call bug5258_aux()| + +drop procedure bug5258| +drop procedure bug5258_aux| + +# +# BUG#4487: Stored procedure connection aborted if uninitialized char +# +--disable_warnings +drop function if exists bug4487| +--enable_warnings +create function bug4487() returns char +begin + declare v char; + return v; +end| + +select bug4487()| +drop function bug4487| + + +# +# BUG#4941: Stored procedure crash fetching null value into variable. +# +--disable_warnings +drop procedure if exists bug4941| +--enable_warnings +--disable_warnings +drop procedure if exists bug4941| +--enable_warnings +create procedure bug4941(out x int) +begin + declare c cursor for select i from t2 limit 1; + open c; + fetch c into x; + close c; +end| + +insert into t2 values (null, null, null)| +set @x = 42| +call bug4941(@x)| +select @x| +delete from t1| +drop procedure bug4941| + + +# +# BUG#3583: query cache doesn't work for stored procedures +# +--disable_warnings +drop procedure if exists bug3583| +--enable_warnings +--disable_warnings +drop procedure if exists bug3583| +--enable_warnings +create procedure bug3583() +begin + declare c int; + + select * from t1; + select count(*) into c from t1; + select c; +end| + +insert into t1 values ("x", 3), ("y", 5)| +set @x = @@query_cache_size| +set global query_cache_size = 10*1024*1024| + +flush status| +flush query cache| +show status like 'Qcache_hits'| +call bug3583()| +show status like 'Qcache_hits'| +call bug3583()| +call bug3583()| +show status like 'Qcache_hits'| + +set global query_cache_size = @x| +flush status| +flush query cache| +delete from t1| +drop procedure bug3583| + +# +# BUG#4905: Stored procedure doesn't clear for "Rows affected" +# +--disable_warnings +drop procedure if exists bug4905| +--enable_warnings + +create table t3 (s1 int,primary key (s1))| + +--disable_warnings +drop procedure if exists bug4905| +--enable_warnings +create procedure bug4905() +begin + declare v int; + declare continue handler for sqlstate '23000' set v = 5; + + insert into t3 values (1); +end| + +call bug4905()| +select row_count()| +call bug4905()| +select row_count()| +call bug4905()| +select row_count()| +select * from t3| + +drop procedure bug4905| +drop table t3| + +# +# BUG#6022: Stored procedure shutdown problem with self-calling function. +# + +--disable_parsing # until we implement support for recursive stored functions. +--disable_warnings +drop function if exists bug6022| +--enable_warnings + +--disable_warnings +drop function if exists bug6022| +--enable_warnings +create function bug6022(x int) returns int +begin + if x < 0 then + return 0; + else + return bug6022(x-1); + end if; +end| + +select bug6022(5)| +drop function bug6022| +--enable_parsing + +# +# BUG#6029: Stored procedure specific handlers should have priority +# +--disable_warnings +drop procedure if exists bug6029| +--enable_warnings + +--disable_warnings +drop procedure if exists bug6029| +--enable_warnings +create procedure bug6029() +begin + declare exit handler for 1136 select '1136'; + declare exit handler for sqlstate '23000' select 'sqlstate 23000'; + declare continue handler for sqlexception select 'sqlexception'; + + insert into t3 values (1); + insert into t3 values (1,2); +end| + +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1)| +call bug6029()| +delete from t3| +call bug6029()| + +drop procedure bug6029| +drop table t3| + +# +# BUG#8540: Local variable overrides an alias +# +--disable_warnings +drop procedure if exists bug8540| +--enable_warnings + +create procedure bug8540() +begin + declare x int default 1; + select x as y, x+0 as z; +end| + +call bug8540()| +drop procedure bug8540| + +# +# BUG#6642: Stored procedure crash if expression with set function +# +create table t3 (s1 int)| + +--disable_warnings +drop procedure if exists bug6642| +--enable_warnings + +create procedure bug6642() + select abs(count(s1)) from t3| + +call bug6642()| +call bug6642()| +drop procedure bug6642| + +# +# BUG#7013: Stored procedure crash if group by ... with rollup +# +insert into t3 values (0),(1)| +--disable_warnings +drop procedure if exists bug7013| +--enable_warnings +create procedure bug7013() + select s1,count(s1) from t3 group by s1 with rollup| +call bug7013()| +call bug7013()| +drop procedure bug7013| + +# +# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure +# +--disable_warnings +drop table if exists t4| +--enable_warnings +create table t4 ( + a mediumint(8) unsigned not null auto_increment, + b smallint(5) unsigned not null, + c char(32) not null, + primary key (a) +) engine=myisam default charset=latin1| +insert into t4 values (1, 2, 'oneword')| +insert into t4 values (2, 2, 'anotherword')| + +--disable_warnings +drop procedure if exists bug7743| +--enable_warnings +create procedure bug7743 ( searchstring char(28) ) +begin + declare var mediumint(8) unsigned; + select a into var from t4 where b = 2 and c = binary searchstring limit 1; + select var; +end| + +call bug7743("oneword")| +call bug7743("OneWord")| +call bug7743("anotherword")| +call bug7743("AnotherWord")| +drop procedure bug7743| +drop table t4| + +# +# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes +# the server +# +delete from t3| +insert into t3 values(1)| +drop procedure if exists bug7992_1| +drop procedure if exists bug7992_2| +create procedure bug7992_1() +begin + declare i int; + select max(s1)+1 into i from t3; +end| +create procedure bug7992_2() + insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| + +call bug7992_1()| +call bug7992_1()| +call bug7992_2()| +call bug7992_2()| + +drop procedure bug7992_1| +drop procedure bug7992_2| +drop table t3| + +# +# BUG#8116: calling simple stored procedure twice in a row results +# in server crash +# +create table t3 ( userid bigint(20) not null default 0 )| + +--disable_warnings +drop procedure if exists bug8116| +--enable_warnings +create procedure bug8116(in _userid int) + select * from t3 where userid = _userid| + +call bug8116(42)| +call bug8116(42)| +drop procedure bug8116| +drop table t3| + +# +# BUG#6857: current_time() in STORED PROCEDURES +# +--disable_warnings +drop procedure if exists bug6857| +--enable_warnings +create procedure bug6857(counter int) +begin + declare t0, t1 int; + declare plus bool default 0; + + set t0 = current_time(); + while counter > 0 do + set counter = counter - 1; + end while; + set t1 = current_time(); + if t1 > t0 then + set plus = 1; + end if; + select plus; +end| + +# QQ: This is currently disabled. Not only does it slow down a normal test +# run, it makes running with valgrind (or similar tools) extremely +# painful. +# Make sure this takes at least one second on all machines in all builds. +# 30000 makes it about 3 seconds on an old 1.1GHz linux. +#call bug6857(300000)| + +drop procedure bug6857| + +# +# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not +# work properly. +--disable_warnings +drop procedure if exists bug8757| +--enable_warnings +create procedure bug8757() +begin + declare x int; + declare c1 cursor for select data from t1 limit 1; + + begin + declare y int; + declare c2 cursor for select i from t2 limit 1; + + open c2; + fetch c2 into y; + close c2; + select 2,y; + end; + open c1; + fetch c1 into x; + close c1; + select 1,x; +end| + +delete from t1| +delete from t2| +insert into t1 values ("x", 1)| +insert into t2 values ("y", 2, 0.0)| + +call bug8757()| + +delete from t1| +delete from t2| +drop procedure bug8757| + + +# +# BUG#8762: Stored Procedures: Inconsistent behavior +# of DROP PROCEDURE IF EXISTS statement. +--disable_warnings +drop procedure if exists bug8762| +--enable_warnings +# Doesn't exist +drop procedure if exists bug8762; create procedure bug8762() begin end| +# Does exist +drop procedure if exists bug8762; create procedure bug8762() begin end| +drop procedure bug8762| + + +# +# BUG#5240: Stored procedure crash if function has cursor declaration +# +--disable_warnings +drop function if exists bug5240| +--enable_warnings +create function bug5240 () returns int +begin + declare x int; + declare c cursor for select data from t1 limit 1; + + open c; + fetch c into x; + close c; + return x; +end| + +delete from t1| +insert into t1 values ("answer", 42)| +select id, bug5240() from t1| +drop function bug5240| + +# +# BUG#5278: Stored procedure packets out of order if SET PASSWORD. +# +--disable_warnings +drop function if exists bug5278| +--enable_warnings +create function bug5278 () returns char +begin + SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass'); + return 'okay'; +end| + +--error 1133 +select bug5278()| +--error 1133 +select bug5278()| +drop function bug5278| + +# +# BUG#7992: rolling back temporary Item tree changes in SP +# +--disable_warnings +drop procedure if exists p1| +--enable_warnings +create table t3(id int)| +insert into t3 values(1)| +create procedure bug7992() +begin + declare i int; + select max(id)+1 into i from t3; +end| + +call bug7992()| +call bug7992()| +drop procedure bug7992| +drop table t3| +delimiter ;| + +# +# BUG#8849: problem with insert statement with table alias's +# +# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP +# + +delimiter |; +create table t3 ( + lpitnumber int(11) default null, + lrecordtype int(11) default null +)| + +create table t4 ( + lbsiid int(11) not null default '0', + ltradingmodeid int(11) not null default '0', + ltradingareaid int(11) not null default '0', + csellingprice decimal(19,4) default null, + primary key (lbsiid,ltradingmodeid,ltradingareaid) +)| + +create table t5 ( + lbsiid int(11) not null default '0', + ltradingareaid int(11) not null default '0', + primary key (lbsiid,ltradingareaid) +)| + +--disable_warnings +drop procedure if exists bug8849| +--enable_warnings +create procedure bug8849() +begin + insert into t5 + ( + t5.lbsiid, + t5.ltradingareaid + ) + select distinct t3.lpitnumber, t4.ltradingareaid + from + t4 join t3 on + t3.lpitnumber = t4.lbsiid + and t3.lrecordtype = 1 + left join t4 as price01 on + price01.lbsiid = t4.lbsiid and + price01.ltradingmodeid = 1 and + t4.ltradingareaid = price01.ltradingareaid; +end| + +call bug8849()| +call bug8849()| +call bug8849()| +drop procedure bug8849| +drop tables t3,t4,t5| + +# +# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement +# +--disable_warnings +drop procedure if exists bug8937| +--enable_warnings +create procedure bug8937() +begin + declare s,x,y,z int; + declare a float; + + select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1; + select s,x,y,z; + select avg(data) into a from t1; + select a; +end| + +delete from t1| +insert into t1 (data) values (1), (2), (3), (4), (6)| +call bug8937()| + +drop procedure bug8937| +delete from t1| + + +# +# BUG#6900: Stored procedure inner handler ignored +# BUG#9074: STORED PROC: The scope of every handler declared is not +# properly applied +# +--disable_warnings +drop procedure if exists bug6900| +drop procedure if exists bug9074| +drop procedure if exists bug6900_9074| +--enable_warnings + +create table t3 (w char unique, x char)| +insert into t3 values ('a', 'b')| + +create procedure bug6900() +begin + declare exit handler for sqlexception select '1'; + + begin + declare exit handler for sqlexception select '2'; + + insert into t3 values ('x', 'y', 'z'); + end; +end| + +create procedure bug9074() +begin + declare x1, x2, x3, x4, x5, x6 int default 0; + + begin + declare continue handler for sqlstate '23000' set x5 = 1; + + insert into t3 values ('a', 'b'); + set x6 = 1; + end; + + begin1_label: + begin + declare continue handler for sqlstate '23000' set x1 = 1; + + insert into t3 values ('a', 'b'); + set x2 = 1; + + begin2_label: + begin + declare exit handler for sqlstate '23000' set x3 = 1; + + set x4= 1; + insert into t3 values ('a','b'); + set x4= 0; + end begin2_label; + end begin1_label; + + select x1, x2, x3, x4, x5, x6; +end| + +create procedure bug6900_9074(z int) +begin + declare exit handler for sqlstate '23000' select '23000'; + + begin + declare exit handler for sqlexception select 'sqlexception'; + + if z = 1 then + insert into t3 values ('a', 'b'); + else + insert into t3 values ('x', 'y', 'z'); + end if; + end; +end| + +call bug6900()| +call bug9074()| +call bug6900_9074(0)| +call bug6900_9074(1)| + +drop procedure bug6900| +drop procedure bug9074| +drop procedure bug6900_9074| +drop table t3| + + +# +# BUG#7185: Stored procedure crash if identifier is AVG +# +--disable_warnings +drop procedure if exists avg| +--enable_warnings +create procedure avg () +begin +end| + +call avg ()| +drop procedure avg| + + +# +# BUG#6129: Stored procedure won't display @@sql_mode value +# +--disable_warnings +drop procedure if exists bug6129| +--enable_warnings +set @old_mode= @@sql_mode; +set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO"; +create procedure bug6129() + select @@sql_mode| +call bug6129()| +set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"| +call bug6129()| +set @@sql_mode= "NO_ZERO_IN_DATE"| +call bug6129()| +set @@sql_mode=@old_mode; + +drop procedure bug6129| + + +# +# BUG#9856: Stored procedures: crash if handler for sqlexception, not found +# +--disable_warnings +drop procedure if exists bug9856| +--enable_warnings +create procedure bug9856() +begin + declare v int; + declare c cursor for select data from t1; + declare exit handler for sqlexception, not found select '16'; + + open c; + fetch c into v; + select v; +end| + +delete from t1| +call bug9856()| +call bug9856()| +drop procedure bug9856| + + +# +# BUG##9674: Stored Procs: Using declared vars in algebric operation causes +# system crash. +# +--disable_warnings +drop procedure if exists bug9674_1| +drop procedure if exists bug9674_2| +--enable_warnings +create procedure bug9674_1(out arg int) +begin + declare temp_in1 int default 0; + declare temp_fl1 int default 0; + + set temp_in1 = 100; + set temp_fl1 = temp_in1/10; + set arg = temp_fl1; +end| + +create procedure bug9674_2() +begin + declare v int default 100; + + select v/10; +end| + +call bug9674_1(@sptmp)| +call bug9674_1(@sptmp)| +select @sptmp| +call bug9674_2()| +call bug9674_2()| +drop procedure bug9674_1| +drop procedure bug9674_2| + + +# +# BUG#9598: stored procedure call within stored procedure overwrites IN variable +# +--disable_warnings +drop procedure if exists bug9598_1| +drop procedure if exists bug9598_2| +--enable_warnings +create procedure bug9598_1(in var_1 char(16), + out var_2 integer, out var_3 integer) +begin + set var_2 = 50; + set var_3 = 60; +end| + +create procedure bug9598_2(in v1 char(16), + in v2 integer, + in v3 integer, + in v4 integer, + in v5 integer) +begin + select v1,v2,v3,v4,v5; + call bug9598_1(v1,@tmp1,@tmp2); + select v1,v2,v3,v4,v5; +end| + +call bug9598_2('Test',2,3,4,5)| +select @tmp1, @tmp2| + +drop procedure bug9598_1| +drop procedure bug9598_2| + + +# +# BUG#9902: Crash with simple stored function using user defined variables +# +--disable_warnings +drop procedure if exists bug9902| +--enable_warnings +create function bug9902() returns int(11) +begin + set @x = @x + 1; + return @x; +end| + +set @qcs1 = @@query_cache_size| +set global query_cache_size = 100000| +set @x = 1| +insert into t1 values ("qc", 42)| +select bug9902() from t1| +select bug9902() from t1| +select @x| + +set global query_cache_size = @qcs1| +delete from t1| +drop function bug9902| + + +# +# BUG#9102: Stored proccedures: function which returns blob causes crash +# +--disable_warnings +drop function if exists bug9102| +--enable_warnings +create function bug9102() returns blob return 'a'| +select bug9102()| +drop function bug9102| + + +# +# BUG#7648: Stored procedure crash when invoking a function that returns a bit +# +--disable_warnings +drop function if exists bug7648| +--enable_warnings +create function bug7648() returns bit(8) return 'a'| +select bug7648()| +drop function bug7648| + + +# +# BUG#9775: crash if create function that returns enum or set +# +--disable_warnings +drop function if exists bug9775| +--enable_warnings +create function bug9775(v1 char(1)) returns enum('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('c')| +drop function bug9775| +create function bug9775(v1 int) returns enum('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3)| +drop function bug9775| + +create function bug9775(v1 char(1)) returns set('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| +drop function bug9775| +create function bug9775(v1 int) returns set('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| +drop function bug9775| + + +# +# BUG#8861: If Return is a YEAR data type, value is not shown in year format +# +--disable_warnings +drop function if exists bug8861| +--enable_warnings +create function bug8861(v1 int) returns year return v1| +select bug8861(05)| +set @x = bug8861(05)| +select @x| +drop function bug8861| + + +# +# BUG#9004: Inconsistent behaviour of SP re. warnings +# +--disable_warnings +drop procedure if exists bug9004_1| +drop procedure if exists bug9004_2| +--enable_warnings +create procedure bug9004_1(x char(16)) +begin + insert into t1 values (x, 42); + insert into t1 values (x, 17); +end| +create procedure bug9004_2(x char(16)) + call bug9004_1(x)| + +# Truncation warnings expected... +call bug9004_1('12345678901234567')| +call bug9004_2('12345678901234567890')| + +delete from t1| +drop procedure bug9004_1| +drop procedure bug9004_2| + +# +# BUG#7293: Stored procedure crash with soundex +# +--disable_warnings +drop procedure if exists bug7293| +--enable_warnings +insert into t1 values ('secret', 0)| +create procedure bug7293(p1 varchar(100)) +begin + if exists (select id from t1 where soundex(p1)=soundex(id)) then + select 'yes'; + end if; +end;| +call bug7293('secret')| +call bug7293 ('secrete')| +drop procedure bug7293| +delete from t1| + + +# +# BUG#9841: Unexpected read lock when trying to update a view in a +# stored procedure +# +--disable_warnings +drop procedure if exists bug9841| +drop view if exists v1| +--enable_warnings + +create view v1 as select * from t1, t2 where id = s| +create procedure bug9841 () + update v1 set data = 10| +call bug9841()| + +drop view v1| +drop procedure bug9841| + + +# +# BUG#5963 subqueries in SET/IF +# +--disable_warnings +drop procedure if exists bug5963| +--enable_warnings + +create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| +create table t3 (s1 int)| +insert into t3 values (5)| +call bug5963_1()| +call bug5963_1()| +drop procedure bug5963_1| +drop table t3| + +create procedure bug5963_2 (cfk_value int) +begin + if cfk_value in (select cpk from t3) then + set @x = 5; + end if; + end; +| +create table t3 (cpk int)| +insert into t3 values (1)| +call bug5963_2(1)| +call bug5963_2(1)| +drop procedure bug5963_2| +drop table t3| + + +# +# BUG#9559: Functions: Numeric Operations using -ve value gives incorrect +# results. +# +--disable_warnings +drop function if exists bug9559| +--enable_warnings +create function bug9559() + returns int +begin + set @y = -6/2; + return @y; +end| + +select bug9559()| + +drop function bug9559| + + +# +# BUG#10961: Stored procedures: crash if select * from dual +# +--disable_warnings +drop procedure if exists bug10961| +--enable_warnings +# "select * from dual" results in an error, so the cursor will not open +create procedure bug10961() +begin + declare v char; + declare x int; + declare c cursor for select * from dual; + declare continue handler for sqlexception select x; + + set x = 1; + open c; + set x = 2; + fetch c into v; + set x = 3; + close c; +end| + +call bug10961()| +call bug10961()| + +drop procedure bug10961| + +# +# BUG #6866: Second call of a stored procedure using a view with on expressions +# + +--disable_warnings +DROP PROCEDURE IF EXISTS bug6866| +--enable_warnings + +DROP VIEW IF EXISTS tv| +DROP TABLE IF EXISTS tt1,tt2,tt3| + +CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| +CREATE TABLE tt2 (a2 int, data2 varchar(10))| +CREATE TABLE tt3 (a3 int, data3 varchar(10))| + +INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| + +INSERT INTO tt2 VALUES (1, 'a')| +INSERT INTO tt2 VALUES (2, 'b')| +INSERT INTO tt2 VALUES (3, 'c')| + +INSERT INTO tt3 VALUES (4, 'd')| +INSERT INTO tt3 VALUES (5, 'e')| +INSERT INTO tt3 VALUES (6, 'f')| + +CREATE VIEW tv AS +SELECT tt1.*, tt2.data2, tt3.data3 + FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 + LEFT JOIN tt3 ON tt1.a3 = tt3.a3 + ORDER BY tt1.a1, tt2.a2, tt3.a3| + +CREATE PROCEDURE bug6866 (_a1 int) +BEGIN +SELECT * FROM tv WHERE a1 = _a1; +END| + +CALL bug6866(1)| +CALL bug6866(1)| +CALL bug6866(1)| + +DROP PROCEDURE bug6866; + +DROP VIEW tv| +DROP TABLE tt1, tt2, tt3| + +# +# BUG#10136: items cleunup +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug10136| +--enable_warnings +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin + declare done int default 3; + + repeat + select * from t3; + set done = done - 1; + until done <= 0 end repeat; + +end| +call bug10136()| +call bug10136()| +call bug10136()| +drop procedure bug10136| +drop table t3| + +# +# BUG#11529: crash server after use stored procedure +# +--disable_warnings +drop procedure if exists bug11529| +--enable_warnings +create procedure bug11529() +begin + declare c cursor for select id, data from t1 where data in (10,13); + + open c; + begin + declare vid char(16); + declare vdata int; + declare exit handler for not found begin end; + + while true do + fetch c into vid, vdata; + end while; + end; + close c; +end| + +insert into t1 values + ('Name1', 10), + ('Name2', 11), + ('Name3', 12), + ('Name4', 13), + ('Name5', 14)| + +call bug11529()| +call bug11529()| +delete from t1| +drop procedure bug11529| + + +# +# BUG#6063: Stored procedure labels are subject to restrictions (partial) +# BUG#7088: Stored procedures: labels won't work if character set is utf8 +# +--disable_warnings +drop procedure if exists bug6063| +drop procedure if exists bug7088_1| +drop procedure if exists bug7088_2| +--enable_warnings + +--disable_parsing # temporarily disabled until Bar fixes BUG#11986 +create procedure bug6063() + lâbel: begin end| +call bug6063()| +# QQ Known bug: this will not show the label correctly. +show create procedure bug6063| + +set character set utf8| +create procedure bug7088_1() + label1: begin end label1| +create procedure bug7088_2() + läbel1: begin end| +call bug7088_1()| +call bug7088_2()| +set character set default| +show create procedure bug7088_1| +show create procedure bug7088_2| + +drop procedure bug6063| +drop procedure bug7088_1| +drop procedure bug7088_2| +--enable_parsing + +# +# BUG#9565: "Wrong locking in stored procedure if a sub-sequent procedure +# is called". +# +--disable_warnings +drop procedure if exists bug9565_sub| +drop procedure if exists bug9565| +--enable_warnings +create procedure bug9565_sub() +begin + select * from t1; +end| +create procedure bug9565() +begin + insert into t1 values ("one", 1); + call bug9565_sub(); +end| +call bug9565()| +delete from t1| +drop procedure bug9565_sub| +drop procedure bug9565| + + +# +# BUG#9538: SProc: Creation fails if we try to SET system variable +# using @@var_name in proc +# +--disable_warnings +drop procedure if exists bug9538| +--enable_warnings +create procedure bug9538() + set @@sort_buffer_size = 1000000| + +set @x = @@sort_buffer_size| +set @@sort_buffer_size = 2000000| +select @@sort_buffer_size| +call bug9538()| +select @@sort_buffer_size| +set @@sort_buffer_size = @x| + +drop procedure bug9538| + + +# +# BUG#8692: Cursor fetch of empty string +# +--disable_warnings +drop procedure if exists bug8692| +--enable_warnings +create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| +insert into t3 values ('', '', '', '', '', '', NULL)| + +create procedure bug8692() +begin + declare v1 VARCHAR(10); + declare v2 VARCHAR(10); + declare v3 VARCHAR(10); + declare v4 VARCHAR(10); + declare v5 VARCHAR(10); + declare v6 VARCHAR(10); + declare v7 VARCHAR(10); + declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; + open c8692; + fetch c8692 into v1,v2,v3,v4,v5,v6,v7; + select v1, v2, v3, v4, v5, v6, v7; +end| + +call bug8692()| +drop procedure bug8692| +drop table t3| + +# +# Bug#10055 "Using stored function with information_schema causes empty +# result set" +# +--disable_warnings +drop function if exists bug10055| +--enable_warnings +create function bug10055(v char(255)) returns char(255) return lower(v)| +# This select should not crash server and should return all fields in t1 +select t.column_name, bug10055(t.column_name) +from information_schema.columns as t +where t.table_schema = 'test' and t.table_name = 't1'| +drop function bug10055| + +# +# Bug #12297 "SP crashes the server if data inserted inside a lon loop" +# The test for memleak bug, so actually there is no way to test it +# from the suite. The test below could be used to check SP memory +# consumption by passing large input parameter. +# + +--disable_warnings +drop procedure if exists bug12297| +--enable_warnings + +create procedure bug12297(lim int) +begin + set @x = 0; + repeat + insert into t1(id,data) + values('aa', @x); + set @x = @x + 1; + until @x >= lim + end repeat; +end| + +call bug12297(10)| +drop procedure bug12297| + +# +# Bug #11247 "Stored procedures: Function calls in long loops leak memory" +# One more memleak bug test. One could use this test to check that the memory +# isn't leaking by increasing the input value for p_bug11247. +# + +--disable_warnings +drop function if exists f_bug11247| +drop procedure if exists p_bug11247| +--enable_warnings + +create function f_bug11247(param int) + returns int +return param + 1| + +create procedure p_bug11247(lim int) +begin + declare v int default 0; + + while v < lim do + set v= f_bug11247(v); + end while; +end| + +call p_bug11247(10)| +drop function f_bug11247| +drop procedure p_bug11247| +# +# BUG#12168: "'DECLARE CONTINUE HANDLER FOR NOT FOUND ...' in conditional +# handled incorrectly" +# +--disable_warnings +drop procedure if exists bug12168| +drop table if exists t3, t4| +--enable_warnings + +create table t3 (a int)| +insert into t3 values (1),(2),(3),(4)| + +create table t4 (a int)| + +create procedure bug12168(arg1 char(1)) +begin + declare b, c integer; + if arg1 = 'a' then + begin + declare c1 cursor for select a from t3 where a % 2; + declare continue handler for not found set b = 1; + set b = 0; + open c1; + c1_repeat: repeat + fetch c1 into c; + if (b = 1) then + leave c1_repeat; + end if; + + insert into t4 values (c); + until b = 1 + end repeat; + end; + end if; + if arg1 = 'b' then + begin + declare c2 cursor for select a from t3 where not a % 2; + declare continue handler for not found set b = 1; + set b = 0; + open c2; + c2_repeat: repeat + fetch c2 into c; + if (b = 1) then + leave c2_repeat; + end if; + + insert into t4 values (c); + until b = 1 + end repeat; + end; + end if; +end| + +call bug12168('a')| +select * from t4| +truncate t4| +call bug12168('b')| +select * from t4| +truncate t4| +call bug12168('a')| +select * from t4| +truncate t4| +call bug12168('b')| +select * from t4| +truncate t4| +drop table t3, t4| +drop procedure if exists bug12168| + +# +# Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO +# query" +# One more memleak bug. Use the test to check memory consumption. +# + +--disable_warnings +drop table if exists t3| +drop procedure if exists bug11333| +--enable_warnings + +create table t3 (c1 char(128))| + +insert into t3 values + ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| + + +create procedure bug11333(i int) +begin + declare tmp varchar(128); + set @x = 0; + repeat + select c1 into tmp from t3 + where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + set @x = @x + 1; + until @x >= i + end repeat; +end| + +call bug11333(10)| + +drop procedure bug11333| +drop table t3| + +# +# BUG#9048: Creating a function with char binary IN parameter fails +# +--disable_warnings +drop function if exists bug9048| +--enable_warnings +create function bug9048(f1 char binary) returns char binary +begin + set f1= concat( 'hello', f1 ); + return f1; +end| +drop function bug9048| + +# Bug #12849 Stored Procedure: Crash on procedure call with CHAR type +# 'INOUT' parameter +# + +--disable_warnings +drop procedure if exists bug12849_1| +--enable_warnings +create procedure bug12849_1(inout x char) select x into x| +set @var='a'| +call bug12849_1(@var)| +select @var| +drop procedure bug12849_1| + +--disable_warnings +drop procedure if exists bug12849_2| +--enable_warnings +create procedure bug12849_2(inout foo varchar(15)) +begin +select concat(foo, foo) INTO foo; +end| +set @var='abcd'| +call bug12849_2(@var)| +select @var| +drop procedure bug12849_2| + +# +# BUG#13133: Local variables in stored procedures are not initialized correctly. +# +--disable_warnings +drop procedure if exists bug131333| +drop function if exists bug131333| +--enable_warnings +create procedure bug131333() +begin + begin + declare a int; + + select a; + set a = 1; + select a; + end; + begin + declare b int; + + select b; + end; +end| + +create function bug131333() + returns int +begin + begin + declare a int; + + set a = 1; + end; + begin + declare b int; + + return b; + end; +end| + +call bug131333()| +select bug131333()| + +drop procedure bug131333| +drop function bug131333| + +# +# BUG#12379: PROCEDURE with HANDLER calling FUNCTION with error get +# strange result +# +--disable_warnings +drop function if exists bug12379| +drop procedure if exists bug12379_1| +drop procedure if exists bug12379_2| +drop procedure if exists bug12379_3| +drop table if exists t3| +--enable_warnings + +create table t3 (c1 char(1) primary key not null)| + +create function bug12379() + returns integer +begin + insert into t3 values('X'); + insert into t3 values('X'); + return 0; +end| + +create procedure bug12379_1() +begin + declare exit handler for sqlexception select 42; + + select bug12379(); +END| +create procedure bug12379_2() +begin + declare exit handler for sqlexception begin end; + + select bug12379(); +end| +create procedure bug12379_3() +begin + select bug12379(); +end| + +--error 1062 +select bug12379()| +select 1| +call bug12379_1()| +select 2| +call bug12379_2()| +select 3| +--error 1062 +call bug12379_3()| +select 4| + +drop function bug12379| +drop procedure bug12379_1| +drop procedure bug12379_2| +drop procedure bug12379_3| +drop table t3| + +# +# Bug #13124 Stored Procedure using SELECT INTO crashes server +# + +--disable_warnings +drop procedure if exists bug13124| +--enable_warnings +create procedure bug13124() +begin + declare y integer; + set @x=y; +end| +call bug13124()| +drop procedure bug13124| + +# +# Bug #12979 Stored procedures: crash if inout decimal parameter +# + +# check NULL inout parameters processing + +--disable_warnings +drop procedure if exists bug12979_1| +--enable_warnings +create procedure bug12979_1(inout d decimal(5)) set d = d / 2| +set @bug12979_user_var = NULL| +call bug12979_1(@bug12979_user_var)| +drop procedure bug12979_1| + +# check NULL local variables processing + +--disable_warnings +drop procedure if exists bug12979_2| +--enable_warnings +create procedure bug12979_2() +begin +declare internal_var decimal(5); +set internal_var= internal_var / 2; +select internal_var; +end| +call bug12979_2()| +drop procedure bug12979_2| + + +# +# BUG#6127: Stored procedure handlers within handlers don't work +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug6127| +--enable_warnings +create table t3 (s1 int unique)| + +set @sm=@@sql_mode| +set sql_mode='traditional'| + +create procedure bug6127() +begin + declare continue handler for sqlstate '23000' + begin + declare continue handler for sqlstate '22003' + insert into t3 values (0); + + insert into t3 values (1000000000000000); + end; + + insert into t3 values (1); + insert into t3 values (1); +end| + +call bug6127()| +select * from t3| +--error ER_DUP_ENTRY +call bug6127()| +select * from t3| +set sql_mode=@sm| +drop table t3| +drop procedure bug6127| + + +# +# BUG#12589: Assert when creating temp. table from decimal stored procedure +# variable +# +--disable_warnings +drop procedure if exists bug12589_1| +drop procedure if exists bug12589_2| +drop procedure if exists bug12589_3| +--enable_warnings +create procedure bug12589_1() +begin + declare spv1 decimal(3,3); + set spv1= 123.456; + + set spv1 = 'test'; + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +create procedure bug12589_2() +begin + declare spv1 decimal(6,3); + set spv1= 123.456; + + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +create procedure bug12589_3() +begin + declare spv1 decimal(6,3); + set spv1= -123.456; + + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +# Note: The type of the field will match the value, not the declared +# type of the variable. (This is a type checking issue which +# might be changed later.) + +# Warning expected from "set spv1 = 'test'", the value is set to decimal "0". +call bug12589_1()| +# No warnings here +call bug12589_2()| +call bug12589_3()| +drop procedure bug12589_1| +drop procedure bug12589_2| +drop procedure bug12589_3| + +# +# BUG#7049: Stored procedure CALL errors are ignored +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug7049_1| +drop procedure if exists bug7049_2| +drop procedure if exists bug7049_3| +drop procedure if exists bug7049_4| +drop function if exists bug7049_1| +drop function if exists bug7049_2| +--enable_warnings + +create table t3 ( x int unique )| + +create procedure bug7049_1() +begin + insert into t3 values (42); + insert into t3 values (42); +end| + +create procedure bug7049_2() +begin + declare exit handler for sqlexception + select 'Caught it' as 'Result'; + + call bug7049_1(); + select 'Missed it' as 'Result'; +end| + +create procedure bug7049_3() + call bug7049_1()| + +create procedure bug7049_4() +begin + declare exit handler for sqlexception + select 'Caught it' as 'Result'; + + call bug7049_3(); + select 'Missed it' as 'Result'; +end| + +create function bug7049_1() + returns int +begin + insert into t3 values (42); + insert into t3 values (42); + return 42; +end| + +create function bug7049_2() + returns int +begin + declare x int default 0; + declare continue handler for sqlexception + set x = 1; + + set x = bug7049_1(); + return x; +end| + +call bug7049_2()| +select * from t3| +delete from t3| +call bug7049_4()| +select * from t3| +select bug7049_2()| + +drop table t3| +drop procedure bug7049_1| +drop procedure bug7049_2| +drop procedure bug7049_3| +drop procedure bug7049_4| +drop function bug7049_1| +drop function bug7049_2| + + +# +# BUG#13941: replace() string fuction behaves badly inside stored procedure +# (BUG#13914: IFNULL is returning garbage in stored procedure) +# +--disable_warnings +drop function if exists bug13941| +drop procedure if exists bug13941| +--enable_warnings + +create function bug13941(p_input_str text) + returns text +begin + declare p_output_str text; + + set p_output_str = p_input_str; + + set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); + set p_output_str = replace(p_output_str, 'test', 'prova'); + set p_output_str = replace(p_output_str, 'this', 'questo'); + set p_output_str = replace(p_output_str, ' a ', 'una '); + set p_output_str = replace(p_output_str, 'is', ''); + + return p_output_str; +end| + +create procedure bug13941(out sout varchar(128)) +begin + set sout = 'Local'; + set sout = ifnull(sout, 'DEF'); +end| + +# Note: The bug showed different behaviour in different types of builds, +# giving garbage results in some, and seemingly working in others. +# Running with valgrind (or purify) is the safe way to check that it's +# really working correctly. +select bug13941('this is a test')| +call bug13941(@a)| +select @a| + +drop function bug13941| +drop procedure bug13941| + + +# +# BUG#13095: Cannot create VIEWs in prepared statements +# + +delimiter ;| + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13095; +DROP TABLE IF EXISTS bug13095_t1; +DROP VIEW IF EXISTS bug13095_v1; +--enable_warnings + +delimiter |; + +CREATE PROCEDURE bug13095(tbl_name varchar(32)) +BEGIN + SET @str = + CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; + + SET @str = + CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; + + SET @str = + CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; + + SELECT * FROM bug13095_v1; + + SET @str = + "DROP VIEW bug13095_v1"; + SELECT @str; + PREPARE stmt FROM @str; + EXECUTE stmt; +END| + +delimiter ;| + +CALL bug13095('bug13095_t1'); + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13095; +DROP VIEW IF EXISTS bug13095_v1; +DROP TABLE IF EXISTS bug13095_t1; +--enable_warnings + +delimiter |; + +# +# BUG#14210: "Simple query with > operator on large table gives server +# crash" +# Check that cursors work in case when HEAP tables are converted to +# MyISAM +# +--disable_warnings +drop procedure if exists bug14210| +--enable_warnings +set @@session.max_heap_table_size=16384| +select @@session.max_heap_table_size| +# To trigger the memory corruption the original table must be InnoDB. +# No harm if it's not, so don't warn if the suite is run with --skip-innodb +--disable_warnings +create table t3 (a char(255)) engine=InnoDB| +--enable_warnings +create procedure bug14210_fill_table() +begin + declare table_size, max_table_size int default 0; + select @@session.max_heap_table_size into max_table_size; + delete from t3; + insert into t3 (a) values (repeat('a', 255)); + repeat + insert into t3 select a from t3; + select count(*)*255 from t3 into table_size; + until table_size > max_table_size*2 end repeat; +end| +call bug14210_fill_table()| +drop procedure bug14210_fill_table| +create table t4 like t3| + +create procedure bug14210() +begin + declare a char(255); + declare done int default 0; + declare c cursor for select * from t3; + declare continue handler for sqlstate '02000' set done = 1; + open c; + repeat + fetch c into a; + if not done then + insert into t4 values (upper(a)); + end if; + until done end repeat; + close c; +end| +call bug14210()| +select count(*) from t4| + +drop table t3, t4| +drop procedure bug14210| +set @@session.max_heap_table_size=default| + + +# +# BUG#1473: Dumping of stored functions seems to cause corruption in +# the function body +# +--disable_warnings +drop function if exists bug14723| +drop procedure if exists bug14723| +--enable_warnings + +delimiter ;;| +/*!50003 create function bug14723() + returns bigint(20) +main_loop: begin + return 42; +end */;; +show create function bug14723;; +select bug14723();; + +/*!50003 create procedure bug14723() +main_loop: begin + select 42; +end */;; +show create procedure bug14723;; +call bug14723();; + +delimiter |;; + +drop function bug14723| +drop procedure bug14723| + +# +# Bug#14845 "mysql_stmt_fetch returns MYSQL_NO_DATA when COUNT(*) is 0" +# Check that when fetching from a cursor, COUNT(*) works properly. +# +create procedure bug14845() +begin + declare a char(255); + declare done int default 0; + declare c cursor for select count(*) from t1 where 1 = 0; + declare continue handler for sqlstate '02000' set done = 1; + open c; + repeat + fetch c into a; + if not done then + select a; + end if; + until done end repeat; + close c; +end| +call bug14845()| +drop procedure bug14845| + +# +# BUG#13549 "Server crash with nested stored procedures". +# Server should not crash when during execution of stored procedure +# we have to parse trigger/function definition and this new trigger/ +# function has more local variables declared than invoking stored +# procedure and last of these variables is used in argument of NOT +# operator. +# +--disable_warnings +drop procedure if exists bug13549_1| +drop procedure if exists bug13549_2| +--enable_warnings +CREATE PROCEDURE `bug13549_2`() +begin + call bug13549_1(); +end| +CREATE PROCEDURE `bug13549_1`() +begin + declare done int default 0; + set done= not done; +end| +CALL bug13549_2()| +drop procedure bug13549_2| +drop procedure bug13549_1| + +# +# BUG#10100: function (and stored procedure?) recursivity problem +# +--disable_warnings +drop function if exists bug10100f| +drop procedure if exists bug10100p| +drop procedure if exists bug10100t| +drop procedure if exists bug10100pt| +drop procedure if exists bug10100pv| +drop procedure if exists bug10100pd| +drop procedure if exists bug10100pc| +--enable_warnings +# routines with simple recursion +create function bug10100f(prm int) returns int +begin + if prm > 1 then + return prm * bug10100f(prm - 1); + end if; + return 1; +end| +create procedure bug10100p(prm int, inout res int) +begin + set res = res * prm; + if prm > 1 then + call bug10100p(prm - 1, res); + end if; +end| +create procedure bug10100t(prm int) +begin + declare res int; + set res = 1; + call bug10100p(prm, res); + select res; +end| + +# a procedure which use tables and recursion +create table t3 (a int)| +insert into t3 values (0)| +create view v1 as select a from t3; +create procedure bug10100pt(level int, lim int) +begin + if level < lim then + update t3 set a=level; + FLUSH TABLES; + call bug10100pt(level+1, lim); + else + select * from t3; + end if; +end| +# view & recursion +create procedure bug10100pv(level int, lim int) +begin + if level < lim then + update v1 set a=level; + FLUSH TABLES; + call bug10100pv(level+1, lim); + else + select * from v1; + end if; +end| +# dynamic sql & recursion +prepare stmt2 from "select * from t3;"; +create procedure bug10100pd(level int, lim int) +begin + if level < lim then + select level; + prepare stmt1 from "update t3 set a=a+2"; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + deallocate prepare stmt1; + execute stmt2; + select * from t3; + call bug10100pd(level+1, lim); + else + execute stmt2; + end if; +end| +# cursor & recursion +create procedure bug10100pc(level int, lim int) +begin + declare lv int; + declare c cursor for select a from t3; + open c; + if level < lim then + select level; + fetch c into lv; + select lv; + update t3 set a=level+lv; + FLUSH TABLES; + call bug10100pc(level+1, lim); + else + select * from t3; + end if; + close c; +end| + +set @@max_sp_recursion_depth=4| +select @@max_sp_recursion_depth| +-- error ER_SP_NO_RECURSION +select bug10100f(3)| +-- error ER_SP_NO_RECURSION +select bug10100f(6)| +call bug10100t(5)| +call bug10100pt(1,5)| +call bug10100pv(1,5)| +update t3 set a=1| +call bug10100pd(1,5)| +select * from t3| +update t3 set a=1| +call bug10100pc(1,5)| +select * from t3| +set @@max_sp_recursion_depth=0| +select @@max_sp_recursion_depth| +-- error ER_SP_NO_RECURSION +select bug10100f(5)| +-- error ER_SP_RECURSION_LIMIT +call bug10100t(5)| + +#end of the stack checking +set @@max_sp_recursion_depth=255| +set @var=1| +#disable log because error about stack overrun contains numbers which +#depend on a system +-- disable_result_log +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100p(255, @var)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pt(1,255)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pv(1,255)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pd(1,255)| +-- error ER_STACK_OVERRUN_NEED_MORE +call bug10100pc(1,255)| +-- enable_result_log +set @@max_sp_recursion_depth=0| + +deallocate prepare stmt2| + +drop function bug10100f| +drop procedure bug10100p| +drop procedure bug10100t| +drop procedure bug10100pt| +drop procedure bug10100pv| +drop procedure bug10100pd| +drop procedure bug10100pc| +drop view v1| + +# +# BUG#13729: Stored procedures: packet error after exception handled +# +--disable_warnings +drop procedure if exists bug13729| +drop table if exists t3| +--enable_warnings + +create table t3 (s1 int, primary key (s1))| + +insert into t3 values (1),(2)| + +create procedure bug13729() +begin + declare continue handler for sqlexception select 55; + + update t3 set s1 = 1; +end| + +call bug13729()| +# Used to cause Packets out of order +select * from t3| + +drop procedure bug13729| +drop table t3| + +# +# BUG#14643: Stored Procedure: Continuing after failed var. initialization +# crashes server. +# +--disable_warnings +drop procedure if exists bug14643_1| +drop procedure if exists bug14643_2| +--enable_warnings + +create procedure bug14643_1() +begin + declare continue handler for sqlexception select 'boo' as 'Handler'; + + begin + declare v int default undefined_var; + + if v = 1 then + select 1; + else + select v, isnull(v); + end if; + end; +end| + +create procedure bug14643_2() +begin + declare continue handler for sqlexception select 'boo' as 'Handler'; + + case undefined_var + when 1 then + select 1; + else + select 2; + end case; + + select undefined_var; +end| + +call bug14643_1()| +call bug14643_2()| + +drop procedure bug14643_1| +drop procedure bug14643_2| + +# +# BUG#14304: auto_increment field incorrect set in SP +# +--disable_warnings +drop procedure if exists bug14304| +drop table if exists t3, t4| +--enable_warnings + +create table t3(a int primary key auto_increment)| +create table t4(a int primary key auto_increment)| + +create procedure bug14304() +begin + insert into t3 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 select null as a; + + insert into t3 set a=null; + insert into t3 set a=null; + + select * from t3; +end| + +call bug14304()| + +drop procedure bug14304| +drop table t3, t4| + +# +# BUG#14376: MySQL crash on scoped variable (re)initialization +# +--disable_warnings +drop procedure if exists bug14376| +--enable_warnings + +create procedure bug14376() +begin + declare x int default x; +end| + +# Not the error we want, but that's what we got for now... +--error ER_BAD_FIELD_ERROR +call bug14376()| +drop procedure bug14376| + +create procedure bug14376() +begin + declare x int default 42; + + begin + declare x int default x; + + select x; + end; +end| + +call bug14376()| + +drop procedure bug14376| + +create procedure bug14376(x int) +begin + declare x int default x; + + select x; +end| + +call bug14376(4711)| + +drop procedure bug14376| + +# +# Bug#5967 "Stored procedure declared variable used instead of column" +# The bug should be fixed later. +# Test precedence of names of parameters, variable declarations, +# variable declarations in nested compound statements, table columns, +# table columns in cursor declarations. +# According to the standard, table columns take precedence over +# variable declarations. In MySQL 5.0 it's vice versa. +# + +--disable_warnings +drop procedure if exists bug5967| +drop table if exists t3| +--enable_warnings +create table t3 (a varchar(255))| +insert into t3 (a) values ("a - table column")| +create procedure bug5967(a varchar(255)) +begin + declare i varchar(255); + declare c cursor for select a from t3; + select a; + select a from t3 into i; + select i as 'Parameter takes precedence over table column'; open c; + fetch c into i; + close c; + select i as 'Parameter takes precedence over table column in cursors'; + begin + declare a varchar(255) default 'a - local variable'; + declare c1 cursor for select a from t3; + select a as 'A local variable takes precedence over parameter'; + open c1; + fetch c1 into i; + close c1; + select i as 'A local variable takes precedence over parameter in cursors'; + begin + declare a varchar(255) default 'a - local variable in a nested compound statement'; + declare c2 cursor for select a from t3; + select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; + select a from t3 into i; + select i as 'A local variable in a nested compound statement takes precedence over table column'; + open c2; + fetch c2 into i; + close c2; + select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; + end; + end; +end| +call bug5967("a - stored procedure parameter")| +drop procedure bug5967| + +# +# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server" +# +--disable_warnings +drop procedure if exists bug13012| +--enable_warnings +create procedure bug13012() +BEGIN + REPAIR TABLE t1; + BACKUP TABLE t1 to '../tmp'; + DROP TABLE t1; + RESTORE TABLE t1 FROM '../tmp'; +END| +call bug13012()| +drop procedure bug13012| +create view v1 as select * from t1| +create procedure bug13012() +BEGIN + REPAIR TABLE t1,t2,t3,v1; + OPTIMIZE TABLE t1,t2,t3,v1; + ANALYZE TABLE t1,t2,t3,v1; +END| +call bug13012()| +call bug13012()| +call bug13012()| +drop procedure bug13012| +drop view v1; +select * from t1| + +# +# A test case for Bug#15392 "Server crashes during prepared statement +# execute": make sure that stored procedure check for error conditions +# properly and do not continue execution if an error has been set. +# +# It's necessary to use several DBs because in the original code +# the successful return of mysql_change_db overrode the error from +# execution. +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +create schema mysqltest1| +create schema mysqltest2| +create schema mysqltest3| +use mysqltest3| + +create procedure mysqltest1.p1 (out prequestid varchar(100)) +begin + call mysqltest2.p2('call mysqltest3.p3(1, 2)'); +end| + +create procedure mysqltest2.p2(in psql text) +begin + declare lsql text; + set @lsql= psql; + prepare lstatement from @lsql; + execute lstatement; + deallocate prepare lstatement; +end| + +create procedure mysqltest3.p3(in p1 int) +begin + select p1; +end| + +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +use test| + +# +# Bug#15441 "Running SP causes Server to Crash": check that an SP variable +# can not be used in VALUES() function. +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15441| +--enable_warnings +create table t3 (id int not null primary key, county varchar(25))| +insert into t3 (id, county) values (1, 'York')| + +# First check that a stored procedure that refers to a parameter in VALUES() +# function won't parse. + +create procedure bug15441(c varchar(25)) +begin + update t3 set id=2, county=values(c); +end| +--error ER_BAD_FIELD_ERROR +call bug15441('county')| +drop procedure bug15441| + +# Now check the case when there is an ambiguity between column names +# and stored procedure parameters: the parser shall resolve the argument +# of VALUES() function to the column name. + +# It's hard to deduce what county refers to in every case (INSERT statement): +# 1st county refers to the column +# 2nd county refers to the procedure parameter +# 3d and 4th county refers to the column, again, but +# for 4th county it has the value of SP parameter + +# In UPDATE statement, just check that values() function returns NULL for +# non- INSERT...UPDATE statements, as stated in the manual. + +create procedure bug15441(county varchar(25)) +begin + declare c varchar(25) default "hello"; + + insert into t3 (id, county) values (1, county) + on duplicate key update county= values(county); + select * from t3; + + update t3 set id=2, county=values(id); + select * from t3; +end| +call bug15441('Yale')| +drop table t3| +drop procedure bug15441| + +# +# BUG#14498: Stored procedures: hang if undefined variable and exception +# +--disable_warnings +drop procedure if exists bug14498_1| +drop procedure if exists bug14498_2| +drop procedure if exists bug14498_3| +drop procedure if exists bug14498_4| +drop procedure if exists bug14498_5| +--enable_warnings + +create procedure bug14498_1() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + if v then + select 'yes' as 'v'; + else + select 'no' as 'v'; + end if; + select 'done' as 'End'; +end| + +create procedure bug14498_2() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + while v do + select 'yes' as 'v'; + end while; + select 'done' as 'End'; +end| + +create procedure bug14498_3() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + repeat + select 'maybe' as 'v'; + until v end repeat; + select 'done' as 'End'; +end| + +create procedure bug14498_4() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + case v + when 1 then + select '1' as 'v'; + when 2 then + select '2' as 'v'; + else + select '?' as 'v'; + end case; + select 'done' as 'End'; +end| + +create procedure bug14498_5() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + case + when v = 1 then + select '1' as 'v'; + when v = 2 then + select '2' as 'v'; + else + select '?' as 'v'; + end case; + select 'done' as 'End'; +end| + +call bug14498_1()| +call bug14498_2()| +call bug14498_3()| +call bug14498_4()| +call bug14498_5()| + +drop procedure bug14498_1| +drop procedure bug14498_2| +drop procedure bug14498_3| +drop procedure bug14498_4| +drop procedure bug14498_5| + +# +# BUG#15231: Stored procedure bug with not found condition handler +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| +--enable_warnings + +create table t3 (id int not null)| + +create procedure bug15231_1() +begin + declare xid integer; + declare xdone integer default 0; + declare continue handler for not found set xdone = 1; + + set xid=null; + call bug15231_2(xid); + select xid, xdone; +end| + +create procedure bug15231_2(inout ioid integer) +begin + select "Before NOT FOUND condition is triggered" as '1'; + select id into ioid from t3 where id=ioid; + select "After NOT FOUND condtition is triggered" as '2'; + + if ioid is null then + set ioid=1; + end if; +end| + +create procedure bug15231_3() +begin + declare exit handler for sqlwarning + select 'Caught it (wrong)' as 'Result'; + + call bug15231_4(); +end| + +create procedure bug15231_4() +begin + declare x decimal(2,1); + + set x = 'zap'; + select 'Missed it (correct)' as 'Result'; +end| + +call bug15231_1()| +call bug15231_3()| + +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| + + +# +# BUG#15011: error handler in nested block not activated +# +--disable_warnings +drop procedure if exists bug15011| +--enable_warnings + +create table t3 (c1 int primary key)| + +insert into t3 values (1)| + +create procedure bug15011() + deterministic +begin + declare continue handler for 1062 + select 'Outer' as 'Handler'; + + begin + declare continue handler for 1062 + select 'Inner' as 'Handler'; + + insert into t3 values (1); + end; +end| + +call bug15011()| + +drop procedure bug15011| +drop table t3| + + +# +# BUG#NNNN: New bug synopsis +# +#--disable_warnings +#drop procedure if exists bugNNNN| +#--enable_warnings +#create procedure bugNNNN... + +# Add bugs above this line. Use existing tables t1 and t2 when +# practical, or create table t3, t4 etc temporarily (and drop them). +delimiter ;| +drop table t1,t2; diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test index f7ba9803fda..3854297ec0c 100644 --- a/mysql-test/t/sp_notembedded.test +++ b/mysql-test/t/sp_notembedded.test @@ -128,6 +128,7 @@ call bug6807()| drop procedure bug6807| + # # BUG#10100: function (and stored procedure?) recursivity problem # @@ -152,7 +153,7 @@ create procedure bug10100p(prm int, inout res int) begin set res = res * prm; if prm > 1 then - call bug10100p(prm - 1, res); + call bug10100p(prm - 1, res); end if; end| create procedure bug10100t(prm int) diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 9e09b215951..733403f482e 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1963,12 +1963,6 @@ select * from (select max(fld) from t1) as foo; drop table t1; # -# BUG #10308: purge log with subselect -# - -purge master logs before (select adddate(current_timestamp(), interval -4 day)); - -# # Test for bug #11762: subquery with an aggregate function in HAVING # diff --git a/mysql-test/t/system_mysql_db_fix.test b/mysql-test/t/system_mysql_db_fix.test index 18e1efb3120..14132f5af11 100644 --- a/mysql-test/t/system_mysql_db_fix.test +++ b/mysql-test/t/system_mysql_db_fix.test @@ -81,7 +81,8 @@ engine=MyISAM; INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y'); INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N','N'); --- exec $MYSQL_FIX_SYSTEM_TABLES --database=test +# Call the "shell script" $MYSQL_FIX_SYSTEM_TABLES using system +-- system $MYSQL_FIX_SYSTEM_TABLES --database=test > /dev/null -- enable_query_log -- enable_result_log diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 2d505fdfece..9121283fb32 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -1,3 +1,5 @@ +# mysqltest should be fixed +-- source include/not_embedded.inc # # Test of temporary tables # diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index c3cc8e3f8e8..0ac57394c2f 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1, t2, t3; +drop table if exists t1, t2, t3, t4; drop view if exists v1; drop database if exists mysqltest; drop function if exists f1; @@ -959,6 +959,92 @@ create trigger test.t1_bi before insert on t1 for each row set @a:=0; drop trigger t1_bi; connection default; +# +# Test for bug #13525 "Rename table does not keep info of triggers" +# +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +insert into t1 values (101); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +rename table t1 to t2; +# Trigger should work after rename +insert into t2 values (102); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# Let us check that the same works for simple ALTER TABLE ... RENAME +alter table t2 rename to t3; +insert into t3 values (103); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# And for more complex ALTER TABLE +alter table t3 rename to t4, add column val int default 0; +insert into t4 values (104, 1); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# .TRN file should be updated with new table name +drop trigger t1_bi; +drop table t4; +# Rename between different databases if triggers exist should fail +create database mysqltest; +use mysqltest; +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +insert into t1 values (101); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +--error ER_TRG_IN_WRONG_SCHEMA +rename table t1 to test.t2; +insert into t1 values (102); +select @a; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test' or event_object_schema = 'mysqltest'; +# There should be no fantom .TRN files +--error ER_TRG_DOES_NOT_EXIST +drop trigger test.t1_bi; +drop trigger t1_bi; +drop table t1; +drop database mysqltest; +use test; +# And now let us check that the properly handle rename if there is some +# error during it (that we rollback such renames completely). +create table t1 (id int); +create trigger t1_bi before insert on t1 for each row set @a:=new.id; +create trigger t1_ai after insert on t1 for each row set @b:=new.id; +insert into t1 values (101); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +# Trick which makes update of second .TRN file impossible +system echo dummy >$MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +system chmod 000 $MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +--error 1 +rename table t1 to t2; +# 't1' should be still there and triggers should work correctly +insert into t1 values (102); +select @a, @b; +select trigger_schema, trigger_name, event_object_schema, + event_object_table, action_statement from information_schema.triggers + where event_object_schema = 'test'; +system chmod 600 $MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +system rm $MYSQLTEST_VARDIR/master-data/test/t1_ai.TRN~; +# Let us check that updates to .TRN files were rolled back too +drop trigger t1_bi; +drop trigger t1_ai; +drop table t1; + # Test for bug #16829 "Firing trigger with RETURN crashes the server" # RETURN is not supposed to be used anywhere except functions, so error # should be returned when one attempts to create trigger with RETURN. diff --git a/mysql-test/t/upgrade.test b/mysql-test/t/upgrade.test index 826f486e4c0..42e32b686c2 100644 --- a/mysql-test/t/upgrade.test +++ b/mysql-test/t/upgrade.test @@ -1,28 +1,31 @@ +-- source include/not_embedded.inc + --disable_warnings -drop database if exists `testdb1`; -drop database if exists `testdb-1`; -drop database if exists `#mysql50#testdb-1`; +drop database if exists `mysqltest1`; +drop database if exists `mysqltest-1`; +drop database if exists `#mysql50#mysqltest-1`; --enable_warnings -create database `testdb1`; -create database `#mysql50#testdb-1`; -create table `testdb1`.`t1` (a int); -create table `testdb1`.`#mysql50#t-1` (a int); -create table `#mysql50#testdb-1`.`t1` (a int); -create table `#mysql50#testdb-1`.`#mysql50#t-1` (a int); -show create database `testdb1`; + +create database `mysqltest1`; +create database `#mysql50#mysqltest-1`; +create table `mysqltest1`.`t1` (a int); +create table `mysqltest1`.`#mysql50#t-1` (a int); +create table `#mysql50#mysqltest-1`.`t1` (a int); +create table `#mysql50#mysqltest-1`.`#mysql50#t-1` (a int); +show create database `mysqltest1`; --error 1049 -show create database `testdb-1`; -show create database `#mysql50#testdb-1`; -show tables in `testdb1`; -show tables in `#mysql50#testdb-1`; +show create database `mysqltest-1`; +show create database `#mysql50#mysqltest-1`; +show tables in `mysqltest1`; +show tables in `#mysql50#mysqltest-1`; --exec $MYSQL_CHECK --all-databases --fix-db-names --fix-table-names -show create database `testdb1`; -show create database `testdb-1`; +show create database `mysqltest1`; +show create database `mysqltest-1`; --error 1049 -show create database `#mysql50#testdb-1`; -show tables in `testdb1`; -show tables in `testdb-1`; -drop database `testdb1`; -drop database `testdb-1`; +show create database `#mysql50#mysqltest-1`; +show tables in `mysqltest1`; +show tables in `mysqltest-1`; +drop database `mysqltest1`; +drop database `mysqltest-1`; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 5d1b5a80a9b..294a254390f 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2375,3 +2375,18 @@ SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x; DROP VIEW v1; DROP TABLE t1; + +# +# BUG#15943: mysql_next_result hangs on invalid SHOW CREATE VIEW +# + +delimiter //; +drop table if exists t1; +drop view if exists v1; +create table t1 (id int); +create view v1 as select * from t1; +drop table t1; +show create view v1; +drop view v1; +// +delimiter ;// diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test index 1327436d6c3..a3a8aa6a4c3 100644 --- a/mysql-test/t/view_grant.test +++ b/mysql-test/t/view_grant.test @@ -717,3 +717,5 @@ create definer=some_user@`` sql security invoker view v1 as select 1; create definer=some_user@localhost sql security invoker view v1 as select 1; show create view v1; drop view v1; + + diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test index e88d95674ed..f7ce987f29d 100644 --- a/mysql-test/t/xml.test +++ b/mysql-test/t/xml.test @@ -23,6 +23,7 @@ SELECT extractValue(@xml,'/*/*'); SELECT extractValue(@xml,'/*/*/*'); SELECT extractValue(@xml,'/a/child::*'); +SELECT extractValue(@xml,'/a/self::*'); SELECT extractValue(@xml,'/a/descendant::*'); SELECT extractValue(@xml,'/a/descendant-or-self::*'); SELECT extractValue(@xml,'/a/attribute::*'); @@ -231,3 +232,33 @@ select extractvalue('<a><b>B</b></a>','/a|b'); select extractvalue('<a>a<b>B</b></a>','/a|/b'); select extractvalue('<a>a<b>B</b></a>','/a|b'); select extractvalue('<a>a<b>B</b></a>','a|/b'); + +# +# Bug#16312 XML: extractvalue() crash if angle brackets +# +--error 1105 +select extractvalue('<a>A</a>','/<a>'); + +# +# Bug#16313 XML: extractvalue() ignores '!' in names +# +--error 1105 +select extractvalue('<a><b>b</b><b!>b!</b!></a>','//b!'); + +# +# Bug #16315 XML: extractvalue() handles self badly +# +select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant::*'); +select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/self::*'); +select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant-or-self::*'); +# Bug #16320 XML: extractvalue() won't accept names containing underscores +# +select extractvalue('<A_B>A</A_B>','/A_B'); + +# +# Bug#16316: XML: extractvalue() is case-sensitive with contains() +# +select extractvalue('<a>Jack</a>','/a[contains(../a,"J")]'); +select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]'); +select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin); +select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]'); diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 4d6c0d1e189..121342bec87 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -51,7 +51,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ my_quick.c my_lockmem.c my_static.c \ my_sync.c my_getopt.c my_mkdir.c \ default_modify.c default.c \ - my_compress.c checksum.c raid.cc \ + my_compress.c checksum.c \ my_net.c my_semaphore.c my_port.c my_sleep.c \ charset.c charset-def.c my_bitmap.c my_bit.c md5.c \ my_gethostbyname.c rijndael.c my_aes.c sha1.c \ diff --git a/mysys/mf_dirname.c b/mysys/mf_dirname.c index 98da72a206c..378fe7080b8 100644 --- a/mysys/mf_dirname.c +++ b/mysys/mf_dirname.c @@ -109,7 +109,7 @@ char *convert_dirname(char *to, const char *from, const char *from_end) #if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2) { - for (; *from && from != from_end; from++) + for (; from != from_end && *from ; from++) { if (*from == '/') *to++= FN_LIBCHAR; diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index 91575d66368..70edb507b5f 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -84,7 +84,7 @@ void create_last_word_mask(MY_BITMAP *map) } } -static inline void bitmap_lock(MY_BITMAP *map) +static inline void bitmap_lock(MY_BITMAP *map __attribute__((unused))) { #ifdef THREAD if (map->mutex) @@ -92,7 +92,7 @@ static inline void bitmap_lock(MY_BITMAP *map) #endif } -static inline void bitmap_unlock(MY_BITMAP *map) +static inline void bitmap_unlock(MY_BITMAP *map __attribute__((unused))) { #ifdef THREAD if (map->mutex) diff --git a/mysys/my_static.c b/mysys/my_static.c index 8448afdc158..17094548dbd 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -92,13 +92,6 @@ struct st_irem *sf_malloc_root = NULL; int volatile my_have_got_alarm=0; /* declare variable to reset */ ulong my_time_to_wait_for_lock=2; /* In seconds */ - /* - We need to have this define here as otherwise linking will fail - on OSF1 when compiling --without-raid --with-debug - */ - -const char *raid_type_string[]={"none","striped"}; - /* from errors.c */ #ifdef SHARED_LIBRARY char * NEAR globerrs[GLOBERRS]; /* my_error_messages is here */ diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c index 603248e186b..84be3a7a34a 100644 --- a/mysys/my_symlink2.c +++ b/mysys/my_symlink2.c @@ -34,9 +34,11 @@ File my_create_with_symlink(const char *linkname, const char *filename, int create_link; char abs_linkname[FN_REFLEN]; DBUG_ENTER("my_create_with_symlink"); + DBUG_PRINT("enter", ("linkname: %s filename: %s", linkname, filename)); if (my_disable_symlinks) { + DBUG_PRINT("info", ("Symlinks disabled")); /* Create only the file, not the link and file */ create_link= 0; if (linkname) diff --git a/mysys/raid.cc b/mysys/raid.cc deleted file mode 100644 index 29819a878c4..00000000000 --- a/mysys/raid.cc +++ /dev/null @@ -1,799 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - - 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; either version 2 of the License, or - (at your option) any later version. - - 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* - - RAID support for MySQL. Raid 0 (stiping) only implemented yet. - - Why RAID? Why it must be in MySQL? - - This is because then you can: - 1. Have bigger tables than your OS limit. In time of writing this - we are hitting to 2GB limit under linux/ext2 - 2. You can get more speed from IO bottleneck by putting - Raid dirs on different physical disks. - 3. Getting more fault tolerance (not implemented yet) - - Why not to use RAID: - - 1. You are losing some processor power to calculate things, - do more syscalls and interrupts. - - Functionality is supplied by two classes: RaidFd and RaidName. - RaidFd supports funtionality over file descriptors like - open/create/write/seek/close. RaidName supports functionality - like rename/delete where we have no relations to filedescriptors. - RaidName can be prorably unchanged for different Raid levels. RaidFd - have to be virtual I think ;). - You can speed up some calls in MySQL code by skipping RAID code. - For example LOAD DATA INFILE never needs to read RAID-ed files. - This can be done adding proper "#undef my_read" or similar undef-s - in your code. Check out the raid.h! - - Some explanation about _seek_vector[] - This is seek cache. RAID seeks too much and we cacheing this. We - fool it and just storing new position in file to _seek_vector. - When there is no seeks to do, we are putting RAID_SEEK_DONE into it. - Any other value requires seeking to that position. - - TODO: - - - - Implement other fancy things like RAID 1 (mirroring) and RAID 5. - Should not to be very complex. - - - Optimize big blob writes by resorting write buffers and writing - big chunks at once instead of doing many syscalls. - after thinking I - found this is useless. This is because same thing one can do with just - increasing RAID_CHUNKSIZE. Monty, what do you think? tonu. - - - If needed, then implement missing syscalls. One known to miss is stat(); - - - Make and use a thread safe dynamic_array buffer. The used one - will not work if needs to be extended at the same time someone is - accessing it. - - - tonu@mysql.com & monty@mysql.com -*/ - -#ifdef USE_PRAGMA_IMPLEMENTATION -#pragma implementation // gcc: Class implementation -#endif - -#include "mysys_priv.h" -#include <my_dir.h> -#include <m_string.h> -#include <assert.h> - -#if defined(USE_RAID) && !defined(MYSQL_CLIENT) - -#define RAID_SEEK_DONE ~(off_t) 0 -#define RAID_SIZE_UNKNOWN ~(my_off_t) 0 - -DYNAMIC_ARRAY RaidFd::_raid_map; - - -/* --------------- C compatibility ---------------*/ - -extern "C" { - - void init_raid(void) - { - /* Allocate memory for global file to raid map */ - my_init_dynamic_array(&RaidFd::_raid_map, sizeof(RaidFd*), 4096, 1024); - } - void end_raid(void) - { - /* Free memory used by raid */ - delete_dynamic(&RaidFd::_raid_map); - } - - bool is_raid(File fd) - { - return RaidFd::IsRaid(fd); - } - - File my_raid_create(const char *FileName, int CreateFlags, int access_flags, - uint raid_type, uint raid_chunks, ulong raid_chunksize, - myf MyFlags) - { - DBUG_ENTER("my_raid_create"); - DBUG_PRINT("enter",("Filename: %s CreateFlags: %d access_flags: %d MyFlags: %d", - FileName, CreateFlags, access_flags, MyFlags)); - if (raid_type) - { - RaidFd *raid = new RaidFd(raid_type, raid_chunks , raid_chunksize); - File res = raid->Create(FileName,CreateFlags,access_flags,MyFlags); - if (res < 0 || set_dynamic(&RaidFd::_raid_map,(char*) &raid,res)) - { - delete raid; - DBUG_RETURN(-1); - } - DBUG_RETURN(res); - } - else - DBUG_RETURN(my_create(FileName, CreateFlags, access_flags, MyFlags)); - } - - File my_raid_open(const char *FileName, int Flags, - uint raid_type, uint raid_chunks, ulong raid_chunksize, - myf MyFlags) - { - DBUG_ENTER("my_raid_open"); - DBUG_PRINT("enter",("Filename: %s Flags: %d MyFlags: %d", - FileName, Flags, MyFlags)); - if (raid_type) - { - RaidFd *raid = new RaidFd(raid_type, raid_chunks , raid_chunksize); - File res = raid->Open(FileName,Flags,MyFlags); - if (res < 0 || set_dynamic(&RaidFd::_raid_map,(char*) &raid,res)) - { - delete raid; - DBUG_RETURN(-1); - } - DBUG_RETURN(res); - } - else - DBUG_RETURN(my_open(FileName, Flags, MyFlags)); - } - - my_off_t my_raid_seek(File fd, my_off_t pos,int whence,myf MyFlags) - { - DBUG_ENTER("my_raid_seek"); - DBUG_PRINT("enter",("Fd: %d pos: %lu whence: %d MyFlags: %d", - fd, (ulong) pos, whence, MyFlags)); - - if (is_raid(fd)) - { - assert(pos != MY_FILEPOS_ERROR); - - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Seek(pos,whence,MyFlags)); - } - else - DBUG_RETURN(my_seek(fd, pos, whence, MyFlags)); - } - - my_off_t my_raid_tell(File fd,myf MyFlags) - { - DBUG_ENTER("my_raid_tell"); - DBUG_PRINT("enter",("Fd: %d MyFlags: %d", - fd, MyFlags)); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Tell(MyFlags)); - } - else - DBUG_RETURN(my_tell(fd, MyFlags)); - } - - uint my_raid_write(File fd,const byte *Buffer, uint Count, myf MyFlags) - { - DBUG_ENTER("my_raid_write"); - DBUG_PRINT("enter",("Fd: %d Buffer: 0x%lx Count: %u MyFlags: %d", - fd, Buffer, Count, MyFlags)); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Write(Buffer,Count,MyFlags)); - } else - DBUG_RETURN(my_write(fd,Buffer,Count,MyFlags)); - } - - uint my_raid_read(File fd, byte *Buffer, uint Count, myf MyFlags) - { - DBUG_ENTER("my_raid_read"); - DBUG_PRINT("enter",("Fd: %d Buffer: 0x%lx Count: %u MyFlags: %d", - fd, Buffer, Count, MyFlags)); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Read(Buffer,Count,MyFlags)); - } else - DBUG_RETURN(my_read(fd,Buffer,Count,MyFlags)); - } - - uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, - myf MyFlags) - { - DBUG_ENTER("my_raid_pread"); - DBUG_PRINT("enter", - ("Fd: %d Buffer: 0x%lx Count: %u offset: %u MyFlags: %d", - Filedes, Buffer, Count, offset, MyFlags)); - if (is_raid(Filedes)) - { - assert(offset != MY_FILEPOS_ERROR); - - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,Filedes,RaidFd**)); - /* Returning value isn't important because real seek is done later. */ - raid->Seek(offset,MY_SEEK_SET,MyFlags); - DBUG_RETURN(raid->Read(Buffer,Count,MyFlags)); - } - else - DBUG_RETURN(my_pread(Filedes, Buffer, Count, offset, MyFlags)); - } - - uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count, - my_off_t offset, myf MyFlags) - { - DBUG_ENTER("my_raid_pwrite"); - DBUG_PRINT("enter", - ("Fd: %d Buffer: 0x %lx Count: %u offset: %u MyFlags: %d", - Filedes, Buffer, Count, offset, MyFlags)); - if (is_raid(Filedes)) - { - assert(offset != MY_FILEPOS_ERROR); - - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,Filedes,RaidFd**)); - /* Returning value isn't important because real seek is done later. */ - raid->Seek(offset,MY_SEEK_SET,MyFlags); - DBUG_RETURN(raid->Write(Buffer,Count,MyFlags)); - } - else - DBUG_RETURN(my_pwrite(Filedes, Buffer, Count, offset, MyFlags)); - } - - int my_raid_lock(File fd, int locktype, my_off_t start, my_off_t length, - myf MyFlags) - { - DBUG_ENTER("my_raid_lock"); - DBUG_PRINT("enter",("Fd: %d start: %u length: %u MyFlags: %d", - fd, start, length, MyFlags)); - if (my_disable_locking) - DBUG_RETURN(0); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Lock(locktype, start, length, MyFlags)); - } - else - DBUG_RETURN(my_lock(fd, locktype, start, length, MyFlags)); - } - - int my_raid_close(File fd, myf MyFlags) - { - DBUG_ENTER("my_raid_close"); - DBUG_PRINT("enter",("Fd: %d MyFlags: %d", - fd, MyFlags)); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - RaidFd *tmp=0; - set_dynamic(&RaidFd::_raid_map,(char*) &tmp,fd); - int res = raid->Close(MyFlags); - delete raid; - DBUG_RETURN(res); - } - else - DBUG_RETURN(my_close(fd, MyFlags)); - } - - int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags) - { - DBUG_ENTER("my_raid_chsize"); - DBUG_PRINT("enter",("Fd: %d newlength: %u MyFlags: %d", - fd, newlength, MyFlags)); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Chsize(fd, newlength, filler, MyFlags)); - } - else - DBUG_RETURN(my_chsize(fd, newlength, filler, MyFlags)); - } - - int my_raid_rename(const char *from, const char *to, - uint raid_chunks, myf MyFlags) - { - char from_tmp[FN_REFLEN]; - char to_tmp[FN_REFLEN]; - DBUG_ENTER("my_raid_rename"); - - uint from_pos = dirname_length(from); - uint to_pos = dirname_length(to); - memcpy(from_tmp, from, from_pos); - memcpy(to_tmp, to, to_pos); - for (uint i = 0 ; i < raid_chunks ; i++ ) - { - sprintf(from_tmp+from_pos,"%02x/%s", i, from + from_pos); - sprintf(to_tmp+to_pos,"%02x/%s", i, to+ to_pos); - /* Convert if not unix */ - unpack_filename(from_tmp, from_tmp); - unpack_filename(to_tmp,to_tmp); - if (my_rename(from_tmp, to_tmp, MyFlags)) - DBUG_RETURN(-1); - } - DBUG_RETURN(0); - } - - int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags) - { - char from_tmp[FN_REFLEN]; - uint from_pos = dirname_length(from); - DBUG_ENTER("my_raid_delete"); - - if (!raid_chunks) - DBUG_RETURN(my_delete(from,MyFlags)); - for (uint i = 0 ; i < raid_chunks ; i++ ) - { - memcpy(from_tmp, from, from_pos); - sprintf(from_tmp+from_pos,"%02x/%s", i, from + from_pos); - /* Convert if not unix */ - unpack_filename(from_tmp, from_tmp); - if (my_delete(from_tmp, MyFlags)) - DBUG_RETURN(-1); - } - DBUG_RETURN(0); - } - - int my_raid_redel(const char *old_name, const char *new_name, - uint raid_chunks, myf MyFlags) - { - char new_name_buff[FN_REFLEN], old_name_buff[FN_REFLEN]; - char *new_end, *old_end; - uint i,old_length,new_length; - int error=0; - DBUG_ENTER("my_raid_redel"); - - old_end=old_name_buff+dirname_part(old_name_buff,old_name); - old_length=dirname_length(old_name); - new_end=new_name_buff+dirname_part(new_name_buff,new_name); - new_length=dirname_length(new_name); - for (i=0 ; i < raid_chunks ; i++) - { - MY_STAT status; - sprintf(new_end,"%02x",i); - if (my_stat(new_name_buff,&status, MYF(0))) - { - DBUG_PRINT("info",("%02x exists, skipping directory creation",i)); - } - else - { - if (my_mkdir(new_name_buff,0777,MYF(0))) - { - DBUG_PRINT("error",("mkdir failed for %02x",i)); - DBUG_RETURN(-1); - } - } - strxmov(strend(new_end),"/",new_name+new_length,NullS); - sprintf(old_end,"%02x/%s",i, old_name+old_length); - if (my_redel(old_name_buff, new_name_buff, MyFlags)) - error=1; - } - DBUG_RETURN(error); - } -} - -int my_raid_fstat(int fd, MY_STAT *stat_area, myf MyFlags ) -{ - DBUG_ENTER("my_raid_fstat"); - if (is_raid(fd)) - { - RaidFd *raid= (*dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); - DBUG_RETURN(raid->Fstat(fd, stat_area, MyFlags)); - } - else - DBUG_RETURN(my_fstat(fd, stat_area, MyFlags)); -} - - -/* -------------- RaidFd base class begins ----------------*/ -/* - RaidFd - raided file is identified by file descriptor - this is useful when we open/write/read/close files -*/ - - -bool RaidFd:: -IsRaid(File fd) -{ - DBUG_ENTER("RaidFd::IsRaid"); - DBUG_RETURN((uint) fd < _raid_map.elements && - *dynamic_element(&RaidFd::_raid_map,fd,RaidFd**)); -} - - -RaidFd:: -RaidFd(uint raid_type, uint raid_chunks, ulong raid_chunksize) - :_raid_type(raid_type), _raid_chunks(raid_chunks), - _raid_chunksize(raid_chunksize), _position(0), _size(RAID_SIZE_UNKNOWN), - _fd_vector(0) -{ - DBUG_ENTER("RaidFd::RaidFd"); - DBUG_PRINT("enter",("RaidFd_type: %u Disks: %u Chunksize: %d", - raid_type, raid_chunks, raid_chunksize)); - - /* TODO: Here we should add checks if the malloc fails */ - _seek_vector=0; /* In case of errors */ - my_multi_malloc(MYF(MY_WME), - &_seek_vector,sizeof(off_t)*_raid_chunks, - &_fd_vector, sizeof(File) *_raid_chunks, - NullS); - if (!RaidFd::_raid_map.buffer) - { /* Not initied */ - pthread_mutex_lock(&THR_LOCK_open); /* Ensure that no other thread */ - if (!RaidFd::_raid_map.buffer) /* has done init in between */ - init_raid(); - pthread_mutex_unlock(&THR_LOCK_open); - } - DBUG_VOID_RETURN; -} - - -RaidFd:: -~RaidFd() { - DBUG_ENTER("RaidFd::~RaidFd"); - /* We don't have to free _fd_vector ! */ - my_free((char*) _seek_vector, MYF(MY_ALLOW_ZERO_PTR)); - DBUG_VOID_RETURN; -} - - -File RaidFd:: -Create(const char *FileName, int CreateFlags, int access_flags, myf MyFlags) -{ - char RaidFdFileName[FN_REFLEN]; - DBUG_ENTER("RaidFd::Create"); - DBUG_PRINT("enter", - ("FileName: %s CreateFlags: %d access_flags: %d MyFlags: %d", - FileName, CreateFlags, access_flags, MyFlags)); - char DirName[FN_REFLEN]; - uint pos = dirname_part(DirName, FileName); - MY_STAT status; - if (!_seek_vector) - DBUG_RETURN(-1); /* Not enough memory */ - - uint i = _raid_chunks-1; - do - { - /* Create subdir */ - (void)sprintf(RaidFdFileName,"%s%02x", DirName,i); - unpack_dirname(RaidFdFileName,RaidFdFileName); /* Convert if not unix */ - if (my_stat(RaidFdFileName,&status, MYF(0))) - { - DBUG_PRINT("info",("%02x exists, skipping directory creation",i)); - } - else - { - if (my_mkdir(RaidFdFileName,0777,MYF(0))) - { - DBUG_PRINT("error",("mkdir failed for %d",i)); - goto error; - } - } - /* Create file */ - sprintf(RaidFdFileName,"%s%02x/%s",DirName, i, FileName + pos); - unpack_filename(RaidFdFileName,RaidFdFileName); /* Convert if not unix */ - _fd = my_create(RaidFdFileName, CreateFlags ,access_flags, (myf)MyFlags); - if (_fd < 0) - goto error; - _fd_vector[i]=_fd; - _seek_vector[i]=RAID_SEEK_DONE; - } while (i--); - _size=0; - DBUG_RETURN(_fd); /* Last filenr is pointer to map */ - -error: - { - int save_errno=my_errno; - while (++i < _raid_chunks) - { - my_close(_fd_vector[i],MYF(0)); - sprintf(RaidFdFileName,"%s%02x/%s",DirName, i, FileName + pos); - unpack_filename(RaidFdFileName,RaidFdFileName); - my_delete(RaidFdFileName,MYF(0)); - } - my_errno=save_errno; - } - DBUG_RETURN(-1); -} - - -File RaidFd:: -Open(const char *FileName, int Flags, myf MyFlags) -{ - DBUG_ENTER("RaidFd::Open"); - DBUG_PRINT("enter",("FileName: %s Flags: %d MyFlags: %d", - FileName, Flags, MyFlags)); - char DirName[FN_REFLEN]; - uint pos = dirname_part(DirName, FileName); - if (!_seek_vector) - DBUG_RETURN(-1); /* Not enough memory */ - - for( uint i = 0 ; i < _raid_chunks ; i++ ) - { - char RaidFdFileName[FN_REFLEN]; - sprintf(RaidFdFileName,"%s%02x/%s",DirName, i, FileName + pos); - unpack_filename(RaidFdFileName,RaidFdFileName); /* Convert if not unix */ - _fd = my_open(RaidFdFileName, Flags, MyFlags); - if (_fd < 0) - { - int save_errno=my_errno; - while (i-- != 0) - my_close(_fd_vector[i],MYF(0)); - my_errno=save_errno; - DBUG_RETURN(_fd); - } - _fd_vector[i]=_fd; - _seek_vector[i]=RAID_SEEK_DONE; - } - Seek(0L,MY_SEEK_END,MYF(0)); // Trick. We just need to know, how big the file is - DBUG_PRINT("info",("MYD file logical size: %llu", _size)); - DBUG_RETURN(_fd); -} - - -int RaidFd:: -Write(const byte *Buffer, uint Count, myf MyFlags) -{ - DBUG_ENTER("RaidFd::Write"); - DBUG_PRINT("enter",("Count: %d MyFlags: %d", - Count, MyFlags)); - const byte *bufptr = Buffer; - uint res=0, GotBytes, ReadNowCount; - - // Loop until data is written - do { - Calculate(); - // Do seeks when neccessary - if (_seek_vector[_this_block] != RAID_SEEK_DONE) - { - if (my_seek(_fd_vector[_this_block], _seek_vector[_this_block], - MY_SEEK_SET, - MyFlags) == MY_FILEPOS_ERROR) - DBUG_RETURN(-1); - _seek_vector[_this_block]=RAID_SEEK_DONE; - } - ReadNowCount = min(Count, _remaining_bytes); - GotBytes = my_write(_fd_vector[_this_block], bufptr, ReadNowCount, - MyFlags); - DBUG_PRINT("loop",("Wrote bytes: %d", GotBytes)); - if (GotBytes == MY_FILE_ERROR) - DBUG_RETURN(-1); - res+= GotBytes; - if (MyFlags & (MY_NABP | MY_FNABP)) - GotBytes=ReadNowCount; - bufptr += GotBytes; - Count -= GotBytes; - _position += GotBytes; - } while(Count); - set_if_bigger(_size,_position); - DBUG_RETURN(res); -} - - -int RaidFd:: -Read(const byte *Buffer, uint Count, myf MyFlags) -{ - DBUG_ENTER("RaidFd::Read"); - DBUG_PRINT("enter",("Count: %d MyFlags: %d", - Count, MyFlags)); - byte *bufptr = (byte *)Buffer; - uint res= 0, GotBytes, ReadNowCount; - - // Loop until all data is read (Note that Count may be 0) - while (Count) - { - Calculate(); - // Do seek when neccessary - if (_seek_vector[_this_block] != RAID_SEEK_DONE) - { - if (my_seek(_fd_vector[_this_block], _seek_vector[_this_block], - MY_SEEK_SET, - MyFlags) == MY_FILEPOS_ERROR) - DBUG_RETURN(-1); - _seek_vector[_this_block]=RAID_SEEK_DONE; - } - // and read - ReadNowCount = min(Count, _remaining_bytes); - GotBytes = my_read(_fd_vector[_this_block], bufptr, ReadNowCount, - MyFlags & ~(MY_NABP | MY_FNABP)); - DBUG_PRINT("loop",("Got bytes: %u", GotBytes)); - if (GotBytes == MY_FILE_ERROR) - DBUG_RETURN(-1); - if (!GotBytes) // End of file. - { - DBUG_RETURN((MyFlags & (MY_NABP | MY_FNABP)) ? -1 : (int) res); - } - res+= GotBytes; - bufptr += GotBytes; - Count -= GotBytes; - _position += GotBytes; - } - DBUG_RETURN((MyFlags & (MY_NABP | MY_FNABP)) ? 0 : res); -} - - -int RaidFd:: -Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags) -{ - DBUG_ENTER("RaidFd::Lock"); - DBUG_PRINT("enter",("locktype: %d start: %lu length: %lu MyFlags: %d", - locktype, start, length, MyFlags)); - my_off_t bufptr = start; - // Loop until all data is locked - while(length) - { - Calculate(); - for (uint i = _this_block ; (i < _raid_chunks) && length ; i++ ) - { - uint ReadNowCount = min(length, _remaining_bytes); - uint GotBytes = my_lock(_fd_vector[i], locktype, bufptr, ReadNowCount, - MyFlags); - if ((int) GotBytes == -1) - DBUG_RETURN(-1); - bufptr += ReadNowCount; - length -= ReadNowCount; - Calculate(); - } - } - DBUG_RETURN(0); -} - - -int RaidFd:: -Close(myf MyFlags) -{ - DBUG_ENTER("RaidFd::Close"); - DBUG_PRINT("enter",("MyFlags: %d", - MyFlags)); - for (uint i = 0 ; i < _raid_chunks ; ++i ) - { - int err = my_close(_fd_vector[i], MyFlags); - if (err != 0) - DBUG_RETURN(err); - } - /* _fd_vector is erased when RaidFd is released */ - DBUG_RETURN(0); -} - - -my_off_t RaidFd:: -Seek(my_off_t pos,int whence,myf MyFlags) -{ - DBUG_ENTER("RaidFd::Seek"); - DBUG_PRINT("enter",("Pos: %lu Whence: %d MyFlags: %d", - (ulong) pos, whence, MyFlags)); - switch (whence) { - case MY_SEEK_CUR: - // FIXME: This is wrong, what is going on there - // Just I am relied on fact that MySQL 3.23.7 never uses MY_SEEK_CUR - // for anything else except things like ltell() - break; - case MY_SEEK_SET: - if ( _position != pos) // we can be already in right place - { - uint i; - off_t _rounds; - _position = pos; - Calculate(); - _rounds = _total_block / _raid_chunks; // INT() assumed - _rounds*= _raid_chunksize; - for (i = 0; i < _raid_chunks ; i++ ) - if ( i < _this_block ) - _seek_vector[i] = _rounds + _raid_chunksize; - else if ( i == _this_block ) - _seek_vector[i] = _rounds + _raid_chunksize -_remaining_bytes; - else // if ( i > _this_block ) - _seek_vector[i] = _rounds; - } - break; - case MY_SEEK_END: - if (_size==RAID_SIZE_UNKNOWN) // We don't know table size yet - { - uint i; - _position = 0; - for (i = 0; i < _raid_chunks ; i++ ) - { - my_off_t newpos = my_seek(_fd_vector[i], 0L, MY_SEEK_END, MyFlags); - if (newpos == MY_FILEPOS_ERROR) - DBUG_RETURN (MY_FILEPOS_ERROR); - _seek_vector[i]=RAID_SEEK_DONE; - _position += newpos; - } - _size=_position; - } - else if (_position != _size) // Aren't we also already in the end? - { - uint i; - off_t _rounds; - _position = _size; - Calculate(); - _rounds = _total_block / _raid_chunks; // INT() assumed - _rounds*= _raid_chunksize; - for (i = 0; i < _raid_chunks ; i++ ) - if ( i < _this_block ) - _seek_vector[i] = _rounds + _raid_chunksize; - else if ( i == _this_block ) - _seek_vector[i] = _rounds + _raid_chunksize - _remaining_bytes; - else // if ( i > _this_block ) - _seek_vector[i] = _rounds; - _position=_size; - } - } - DBUG_RETURN(_position); -} - - -my_off_t RaidFd:: -Tell(myf MyFlags) -{ - DBUG_ENTER("RaidFd::Tell"); - DBUG_PRINT("enter",("MyFlags: %d _position %d", - MyFlags,_position)); - DBUG_RETURN(_position); -} - -int RaidFd:: -Chsize(File fd, my_off_t newlength, int filler, myf MyFlags) -{ - DBUG_ENTER("RaidFd::Chsize"); - DBUG_PRINT("enter",("Fd: %d, newlength: %d, MyFlags: %d", - fd, newlength,MyFlags)); - _position = newlength; - Calculate(); - uint _rounds = _total_block / _raid_chunks; // INT() assumed - for (uint i = 0; i < _raid_chunks ; i++ ) - { - int newpos; - if ( i < _this_block ) - newpos = my_chsize(_fd_vector[i], - _this_block * _raid_chunksize + (_rounds + 1) * - _raid_chunksize, filler, MyFlags); - else if ( i == _this_block ) - newpos = my_chsize(_fd_vector[i], - _this_block * _raid_chunksize + _rounds * - _raid_chunksize + (newlength % _raid_chunksize), - filler, MyFlags); - else // this means: i > _this_block - newpos = my_chsize(_fd_vector[i], - _this_block * _raid_chunksize + _rounds * - _raid_chunksize, filler, MyFlags); - if (newpos) - DBUG_RETURN(1); - } - DBUG_RETURN(0); -} - - -int RaidFd:: -Fstat(int fd, MY_STAT *stat_area, myf MyFlags ) -{ - DBUG_ENTER("RaidFd::Fstat"); - DBUG_PRINT("enter",("fd: %d MyFlags: %d",fd,MyFlags)); - uint i; - int error=0; - MY_STAT status; - stat_area->st_size=0; - stat_area->st_mtime=0; - stat_area->st_atime=0; - stat_area->st_ctime=0; - - for(i=0 ; i < _raid_chunks ; i++) - { - if (my_fstat(_fd_vector[i],&status,MyFlags)) - error=1; - stat_area->st_size+=status.st_size; - set_if_bigger(stat_area->st_mtime,status.st_mtime); - set_if_bigger(stat_area->st_atime,status.st_atime); - set_if_bigger(stat_area->st_ctime,status.st_ctime); - } - DBUG_RETURN(error); -} - -#endif /* defined(USE_RAID) && !defined(MYSQL_CLIENT) */ diff --git a/mysys/raid2.c b/mysys/raid2.c deleted file mode 100644 index 94b085b0074..00000000000 --- a/mysys/raid2.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - RAID support for MySQL. For full comments, check raid.cc - This is in a separate file to not cause problems on OS that can't - put C++ files in archives. -*/ - -#include "mysys_priv.h" - -const char *raid_type_string[]={"none","striped"}; - -const char *my_raid_type(int raid_type) -{ - return raid_type_string[raid_type]; -} diff --git a/plugin/fulltext/Makefile.am b/plugin/fulltext/Makefile.am index 0a3186829da..e5a70a23beb 100644 --- a/plugin/fulltext/Makefile.am +++ b/plugin/fulltext/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES= -I$(top_builddir)/include +INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include noinst_LTLIBRARIES= mypluglib.la mypluglib_la_SOURCES= plugin_example.c mypluglib_la_LDFLAGS= -module -rpath $(pkglibdir) diff --git a/scripts/make_win_src_distribution.sh b/scripts/make_win_src_distribution.sh index 893ae6c188a..22c0ea7c839 100644 --- a/scripts/make_win_src_distribution.sh +++ b/scripts/make_win_src_distribution.sh @@ -249,7 +249,7 @@ copy_dir_dirs() { # Input directories to be copied # -for i in client dbug extra storage/heap include storage/archive storage/example \ +for i in client dbug extra storage/heap include storage/archive storage/csv \ include/mysql libmysql libmysqld storage/myisam storage/example \ storage/myisammrg mysys regex sql strings sql-common sql/examples \ tools vio zlib diff --git a/scripts/mysql_create_system_tables.sh b/scripts/mysql_create_system_tables.sh index 94450d23f1e..287a83fbc99 100644 --- a/scripts/mysql_create_system_tables.sh +++ b/scripts/mysql_create_system_tables.sh @@ -874,8 +874,8 @@ $c_pp $c_gl $c_sl $c_ev -CREATE DATABASE IF NOT EXISTS cluster_replication; -CREATE TABLE IF NOT EXISTS cluster_replication.binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; +CREATE DATABASE IF NOT EXISTS cluster; +CREATE TABLE IF NOT EXISTS cluster.binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; END_OF_DATA diff --git a/scripts/mysql_fix_privilege_tables.sh b/scripts/mysql_fix_privilege_tables.sh index 073964d4bde..8c0c539f3f2 100644 --- a/scripts/mysql_fix_privilege_tables.sh +++ b/scripts/mysql_fix_privilege_tables.sh @@ -163,11 +163,7 @@ s_echo() } s_echo "This script updates all the mysql privilege tables to be usable by" -s_echo "MySQL 4.0 and above." -s_echo "" -s_echo "This is needed if you want to use the new GRANT functions," -s_echo "CREATE AGGREGATE FUNCTION, stored procedures, or" -s_echo "more secure passwords in 4.1" +s_echo "MySQL 5.1 and above." s_echo "" if test $verbose = 1 diff --git a/scripts/mysql_fix_privilege_tables.sql b/scripts/mysql_fix_privilege_tables.sql index 0fbaf7bec8a..478d6b48c73 100644 --- a/scripts/mysql_fix_privilege_tables.sql +++ b/scripts/mysql_fix_privilege_tables.sql @@ -630,6 +630,9 @@ CREATE TABLE event ( # EVENT privilege # +SET @hadEventPriv := 0; +SELECT @hadEventPriv :=1 FROM user WHERE Event_priv LIKE '%'; + ALTER TABLE user add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL AFTER Create_user_priv; ALTER TABLE db add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL; ALTER TABLE event DROP PRIMARY KEY; @@ -667,6 +670,8 @@ ALTER TABLE event ADD sql_mode 'HIGH_NOT_PRECEDENCE' ) DEFAULT '' NOT NULL AFTER on_completion; +UPDATE user SET Event_priv=Super_priv WHERE @hadEventPriv = 0; + -- -- TRIGGER privilege -- @@ -680,3 +685,9 @@ ALTER TABLE db ADD Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT ALTER TABLE tables_priv MODIFY Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') COLLATE utf8_general_ci DEFAULT '' NOT NULL; UPDATE user SET Trigger_priv=Super_priv WHERE @hadTriggerPriv = 0; + +# Activate the new, possible modified privilege tables +# This should not be needed, but gives us some extra testing that the above +# changes was correct + +flush privileges; diff --git a/scripts/mysql_upgrade.sh b/scripts/mysql_upgrade.sh index db5dc6a9516..c9f375b6c5b 100644 --- a/scripts/mysql_upgrade.sh +++ b/scripts/mysql_upgrade.sh @@ -39,6 +39,7 @@ parse_arguments() { --ldata=*|--data=*|--datadir=*) DATADIR=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --force) force=1 ;; --verbose) verbose=1 ;; + --help) help_option=1 ;; *) if test -n "$pick_args" then @@ -84,10 +85,27 @@ bindir= MY_BASEDIR_VERSION= verbose=0 force=0 +help_option=0 parse_arguments `$print_defaults $defaults mysqld mysql_upgrade` parse_arguments PICK-ARGS-FROM-ARGV "$@" +if test $help_option = 1 +then + echo "MySQL utility script to upgrade database to the current server version" + echo "" + echo "It takes the following arguments:" + echo " --help Show this help message" + echo " --basedir Specifies the directory where MySQL is installed" + echo " --datadir Specifies the data directory" + echo " --force Mysql_upgrade.info file will be ignored" + echo " --user Username for server login if not current user" + echo " --verbose Display more output about the process" + echo "" + + exit 0 +fi + # # Try to find where binaries are installed # diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index a584c384712..83bc8ce8954 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -213,15 +213,10 @@ then chown $user $mysql_unix_port_dir fi -# Use the mysqld-max binary by default if the user doesn't specify a binary +# If the user doesn't specify a binary, we assume name "mysqld" if test -z "$MYSQLD" then - if test -x $ledir/mysqld-max - then - MYSQLD=mysqld-max - else - MYSQLD=mysqld - fi + MYSQLD=mysqld fi if test ! -x $ledir/$MYSQLD diff --git a/server-tools/instance-manager/guardian.cc b/server-tools/instance-manager/guardian.cc index 291b685ef1b..7a532263846 100644 --- a/server-tools/instance-manager/guardian.cc +++ b/server-tools/instance-manager/guardian.cc @@ -256,7 +256,6 @@ int Guardian_thread::init() Instance *instance; Instance_map::Iterator iterator(instance_map); - instance_map->lock(); /* clear the list of guarded instances */ free_root(&alloc, MYF(0)); init_alloc_root(&alloc, MEM_ROOT_BLOCK_SIZE, 0); @@ -272,7 +271,6 @@ int Guardian_thread::init() } } - instance_map->unlock(); return 0; } diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index 7dfe0ae688b..543c9c31bfa 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -80,19 +80,44 @@ static void delete_instance(void *u) static int process_option(void *ctx, const char *group, const char *option) { Instance_map *map= NULL; + + map = (Instance_map*) ctx; + return map->process_one_option(group, option); +} + +C_MODE_END + + +/* + Process one option from the configuration file. + + SYNOPSIS + Instance_map::process_one_option() + group group name + option option string (e.g. "--name=value") + + DESCRIPTION + This is an auxiliary function and should not be used externally. + It is used only by flush_instances(), which pass it to + process_option(). The caller ensures proper locking + of the instance map object. +*/ + +int Instance_map::process_one_option(const char *group, const char *option) +{ Instance *instance= NULL; static const char prefix[]= { 'm', 'y', 's', 'q', 'l', 'd' }; - map = (Instance_map*) ctx; if (strncmp(group, prefix, sizeof prefix) == 0 && ((my_isdigit(default_charset_info, group[sizeof prefix])) || group[sizeof(prefix)] == '\0')) { - if ((instance= map->find(group, strlen(group))) == NULL) + if (!(instance= (Instance *) hash_search(&hash, (byte *) group, + strlen(group)))) { - if ((instance= new Instance) == 0) + if (!(instance= new Instance)) goto err; - if (instance->init(group) || map->add_instance(instance)) + if (instance->init(group) || my_hash_insert(&hash, (byte *) instance)) goto err_instance; } @@ -108,8 +133,6 @@ err: return 1; } -C_MODE_END - Instance_map::Instance_map(const char *default_mysqld_path_arg): mysqld_path(default_mysqld_path_arg) @@ -144,30 +167,61 @@ void Instance_map::unlock() pthread_mutex_unlock(&LOCK_instance_map); } +/* + Re-read instance configuration file. + + SYNOPSIS + Instance_map::flush_instances() + + DESCRIPTION + This function will: + - clear the current list of instances. This removes both + running and stopped instances. + - load a new instance configuration from the file. + - pass on the new map to the guardian thread: it will start + all instances that are marked `guarded' and not yet started. + Note, as the check whether an instance is started is currently + very simple (returns true if there is a MySQL server running + at the given port), this function has some peculiar + side-effects: + * if the port number of a running instance was changed, the + old instance is forgotten, even if it was running. The new + instance will be started at the new port. + * if the configuration was changed in a way that two + instances swapped their port numbers, the guardian thread + will not notice that and simply report that both instances + are configured successfully and running. + In order to avoid such side effects one should never call + FLUSH INSTANCES without prior stop of all running instances. + + TODO + FLUSH INSTANCES should return an error if it's called + while there is a running instance. +*/ int Instance_map::flush_instances() { int rc; + /* + Guardian thread relies on the instance map repository for guarding + instances. This is why refreshing instance map, we need (1) to stop + guardian (2) reload the instance map (3) reinitialize the guardian + with new instances. + */ guardian->lock(); pthread_mutex_lock(&LOCK_instance_map); hash_free(&hash); hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0, get_instance_key, delete_instance, 0); - pthread_mutex_unlock(&LOCK_instance_map); rc= load(); guardian->init(); + pthread_mutex_unlock(&LOCK_instance_map); guardian->unlock(); return rc; } -int Instance_map::add_instance(Instance *instance) -{ - return my_hash_insert(&hash, (byte *) instance); -} - - Instance * Instance_map::find(const char *name, uint name_len) { @@ -190,10 +244,9 @@ int Instance_map::complete_initialization() if ((instance= new Instance) == 0) goto err; - if (instance->init("mysqld") || add_instance(instance)) + if (instance->init("mysqld") || my_hash_insert(&hash, (byte *) instance)) goto err_instance; - /* After an instance have been added to the instance_map, hash_free should handle it's deletion => goto err, not diff --git a/server-tools/instance-manager/instance_map.h b/server-tools/instance-manager/instance_map.h index 51971db4c2f..d3de42f4d80 100644 --- a/server-tools/instance-manager/instance_map.h +++ b/server-tools/instance-manager/instance_map.h @@ -63,22 +63,25 @@ public: void lock(); void unlock(); int init(); + /* + Process a given option and assign it to appropricate instance. This is + required for the option handler, passed to my_search_option_files(). + */ + int process_one_option(const char *group, const char *option); Instance_map(const char *default_mysqld_path_arg); ~Instance_map(); - /* loads options from config files */ - int load(); - /* adds instance to internal hash */ - int add_instance(Instance *instance); - /* inits instances argv's after all options have been loaded */ - int complete_initialization(); - public: const char *mysqld_path; Guardian_thread *guardian; private: + /* loads options from config files */ + int load(); + /* inits instances argv's after all options have been loaded */ + int complete_initialization(); +private: enum { START_HASH_SIZE = 16 }; pthread_mutex_t LOCK_instance_map; HASH hash; diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index 3ecd5fbc0d0..95f9029f648 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -135,15 +135,6 @@ void manager(const Options &options) if (instance_map.init() || user_map.init()) return; - - if (instance_map.load()) - { - log_error("Cannot init instances repository. This might be caused by " - "the wrong config file options. For instance, missing mysqld " - "binary. Aborting."); - return; - } - if (user_map.load(options.password_file_name)) return; @@ -207,12 +198,13 @@ void manager(const Options &options) shutdown_complete= FALSE; - /* init list of guarded instances */ - guardian_thread.lock(); - - guardian_thread.init(); - - guardian_thread.unlock(); + if (instance_map.flush_instances()) + { + log_error("Cannot init instances repository. This might be caused by " + "the wrong config file options. For instance, missing mysqld " + "binary. Aborting."); + return; + } /* After the list of guarded instances have been initialized, diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc index 8119e8fc0ea..e7d366e7457 100644 --- a/server-tools/instance-manager/options.cc +++ b/server-tools/instance-manager/options.cc @@ -79,6 +79,7 @@ enum options { #endif OPT_MONITORING_INTERVAL, OPT_PORT, + OPT_WAIT_TIMEOUT, OPT_BIND_ADDRESS }; @@ -151,6 +152,11 @@ static struct my_option my_long_options[] = { "version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "wait-timeout", OPT_WAIT_TIMEOUT, "The number of seconds IM waits " + "for activity on a connection before closing it.", + (gptr *) &net_read_timeout, (gptr *) &net_read_timeout, 0, GET_ULONG, + REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0 }, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 } }; diff --git a/server-tools/instance-manager/priv.h b/server-tools/instance-manager/priv.h index af6d2837933..52d7aa1d23d 100644 --- a/server-tools/instance-manager/priv.h +++ b/server-tools/instance-manager/priv.h @@ -28,6 +28,8 @@ #define SERVER_DEFAULT_PORT 3306 #define DEFAULT_MONITORING_INTERVAL 20 #define DEFAULT_PORT 2273 +/* three-week timeout should be enough */ +#define LONG_TIMEOUT ((ulong) 3600L*24L*21L) /* the pid of the manager process (of the signal thread on the LinuxThreads) */ extern pid_t manager_pid; diff --git a/sql/Makefile.am b/sql/Makefile.am index 78eb4857620..b0824110792 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -65,7 +65,8 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \ parse_file.h sql_view.h sql_trigger.h \ sql_array.h sql_cursor.h event.h event_priv.h \ - sql_plugin.h authors.h + sql_plugin.h authors.h sql_partition.h \ + partition_info.h partition_element.h mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ @@ -101,7 +102,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ sp_cache.cc parse_file.cc sql_trigger.cc \ event_executor.cc event.cc event_timed.cc \ sql_plugin.cc sql_binlog.cc \ - handlerton.cc sql_tablespace.cc + handlerton.cc sql_tablespace.cc partition_info.cc EXTRA_mysqld_SOURCES = ha_innodb.cc ha_berkeley.cc ha_archive.cc \ ha_innodb.h ha_berkeley.h ha_archive.h \ ha_blackhole.cc ha_federated.cc ha_ndbcluster.cc \ diff --git a/sql/event.cc b/sql/event.cc index 3fa41996995..8eca4b1dcd3 100644 --- a/sql/event.cc +++ b/sql/event.cc @@ -49,11 +49,11 @@ - Consider using conditional variable when doing shutdown instead of waiting till all worker threads end. - - Make event_timed::get_show_create_event() work + - Make Event_timed::get_show_create_event() work - Add logging to file - - Move comparison code to class event_timed + - Move comparison code to class Event_timed Warning: - For now parallel execution is not possible because the same sp_head cannot be @@ -69,7 +69,7 @@ time_t mysql_event_last_create_time= 0L; static TABLE_FIELD_W_TYPE event_table_fields[EVEX_FIELD_COUNT] = { { - {(char *) STRING_WITH_LEN("db")}, + {(char *) STRING_WITH_LEN("db")}, {(char *) STRING_WITH_LEN("char(64)")}, {(char *) STRING_WITH_LEN("utf8")} }, @@ -120,6 +120,7 @@ static TABLE_FIELD_W_TYPE event_table_fields[EVEX_FIELD_COUNT] = { { {(char *) STRING_WITH_LEN("last_executed")}, {(char *) STRING_WITH_LEN("datetime")}, + {NULL, 0} }, { {(char *) STRING_WITH_LEN("starts")}, @@ -162,25 +163,25 @@ static TABLE_FIELD_W_TYPE event_table_fields[EVEX_FIELD_COUNT] = { LEX_STRING interval_type_to_name[] = { - {(char *) STRING_WITH_LEN("YEAR")}, - {(char *) STRING_WITH_LEN("QUARTER")}, - {(char *) STRING_WITH_LEN("MONTH")}, - {(char *) STRING_WITH_LEN("DAY")}, - {(char *) STRING_WITH_LEN("HOUR")}, - {(char *) STRING_WITH_LEN("MINUTE")}, - {(char *) STRING_WITH_LEN("WEEK")}, - {(char *) STRING_WITH_LEN("SECOND")}, - {(char *) STRING_WITH_LEN("MICROSECOND")}, - {(char *) STRING_WITH_LEN("YEAR_MONTH")}, - {(char *) STRING_WITH_LEN("DAY_HOUR")}, - {(char *) STRING_WITH_LEN("DAY_MINUTE")}, - {(char *) STRING_WITH_LEN("DAY_SECOND")}, - {(char *) STRING_WITH_LEN("HOUR_MINUTE")}, - {(char *) STRING_WITH_LEN("HOUR_SECOND")}, - {(char *) STRING_WITH_LEN("MINUTE_SECOND")}, - {(char *) STRING_WITH_LEN("DAY_MICROSECOND")}, - {(char *) STRING_WITH_LEN("HOUR_MICROSECOND")}, - {(char *) STRING_WITH_LEN("MINUTE_MICROSECOND")}, + {(char *) STRING_WITH_LEN("YEAR")}, + {(char *) STRING_WITH_LEN("QUARTER")}, + {(char *) STRING_WITH_LEN("MONTH")}, + {(char *) STRING_WITH_LEN("DAY")}, + {(char *) STRING_WITH_LEN("HOUR")}, + {(char *) STRING_WITH_LEN("MINUTE")}, + {(char *) STRING_WITH_LEN("WEEK")}, + {(char *) STRING_WITH_LEN("SECOND")}, + {(char *) STRING_WITH_LEN("MICROSECOND")}, + {(char *) STRING_WITH_LEN("YEAR_MONTH")}, + {(char *) STRING_WITH_LEN("DAY_HOUR")}, + {(char *) STRING_WITH_LEN("DAY_MINUTE")}, + {(char *) STRING_WITH_LEN("DAY_SECOND")}, + {(char *) STRING_WITH_LEN("HOUR_MINUTE")}, + {(char *) STRING_WITH_LEN("HOUR_SECOND")}, + {(char *) STRING_WITH_LEN("MINUTE_SECOND")}, + {(char *) STRING_WITH_LEN("DAY_MICROSECOND")}, + {(char *) STRING_WITH_LEN("HOUR_MICROSECOND")}, + {(char *) STRING_WITH_LEN("MINUTE_MICROSECOND")}, {(char *) STRING_WITH_LEN("SECOND_MICROSECOND")} }; @@ -188,10 +189,10 @@ LEX_STRING interval_type_to_name[] = { /* Inits the scheduler queue - prioritized queue from mysys/queue.c - + Synopsis evex_queue_init() - + queue - pointer the the memory to be initialized as queue. has to be allocated from the caller @@ -211,10 +212,10 @@ evex_queue_init(EVEX_QUEUE_TYPE *queue) /* Compares 2 LEX strings regarding case. - + Synopsis my_time_compare() - + s - first LEX_STRING t - second LEX_STRING cs - charset @@ -223,7 +224,7 @@ evex_queue_init(EVEX_QUEUE_TYPE *queue) -1 - s < t 0 - s == t 1 - s > t - + Notes TIME.second_part is not considered during comparison */ @@ -237,18 +238,18 @@ int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs) /* Compares 2 TIME structures - + Synopsis my_time_compare() - + a - first TIME b - second time - + RETURNS: -1 - a < b 0 - a == b 1 - a > b - + Notes TIME.second_part is not considered during comparison */ @@ -275,42 +276,42 @@ my_time_compare(TIME *a, TIME *b) /* - Compares the execute_at members of 2 event_timed instances - + Compares the execute_at members of 2 Event_timed instances + Synopsis event_timed_compare() - - a - first event_timed object - b - second event_timed object - + + a - first Event_timed object + b - second Event_timed object + RETURNS: -1 - a->execute_at < b->execute_at 0 - a->execute_at == b->execute_at 1 - a->execute_at > b->execute_at - + Notes execute_at.second_part is not considered during comparison */ int -event_timed_compare(event_timed *a, event_timed *b) +event_timed_compare(Event_timed *a, Event_timed *b) { return my_time_compare(&a->execute_at, &b->execute_at); } /* - Compares the execute_at members of 2 event_timed instances. + Compares the execute_at members of 2 Event_timed instances. Used as callback for the prioritized queue when shifting elements inside. - + Synopsis event_timed_compare() vptr - not used (set it to NULL) - a - first event_timed object - b - second event_timed object - + a - first Event_timed object + b - second Event_timed object + RETURNS: -1 - a->execute_at < b->execute_at 0 - a->execute_at == b->execute_at @@ -323,7 +324,7 @@ event_timed_compare(event_timed *a, event_timed *b) int event_timed_compare_q(void *vptr, byte* a, byte *b) { - return event_timed_compare((event_timed *)a, (event_timed *)b); + return event_timed_compare((Event_timed *)a, (Event_timed *)b); } @@ -333,18 +334,16 @@ event_timed_compare_q(void *vptr, byte* a, byte *b) For YEAR_MONTH - expression is in months DAY_MINUTE - expression is in minutes - + Synopsis event_reconstruct_interval_expression() buf - preallocated String buffer to add the value to interval - the interval type (for instance YEAR_MONTH) expression - the value in the lowest entity - + RETURNS 0 - OK 1 - Error - - */ int @@ -369,7 +368,7 @@ event_reconstruct_interval_expression(String *buf, goto common_1_lev_code; case INTERVAL_HOUR_MINUTE: case INTERVAL_MINUTE_SECOND: - multipl= 60; + multipl= 60; common_1_lev_code: buf->append('\''); end= longlong10_to_str(expression/multipl, tmp_buff, 10); @@ -378,7 +377,7 @@ common_1_lev_code: break; case INTERVAL_DAY_MINUTE: { - int tmp_expr= expr; + ulonglong tmp_expr= expr; tmp_expr/=(24*60); buf->append('\''); @@ -396,7 +395,7 @@ common_1_lev_code: break; case INTERVAL_HOUR_SECOND: { - int tmp_expr= expr; + ulonglong tmp_expr= expr; buf->append('\''); end= longlong10_to_str(tmp_expr/3600, tmp_buff, 10); @@ -413,7 +412,7 @@ common_1_lev_code: break; case INTERVAL_DAY_SECOND: { - int tmp_expr= expr; + ulonglong tmp_expr= expr; tmp_expr/=(24*3600); buf->append('\''); @@ -438,6 +437,7 @@ common_1_lev_code: case INTERVAL_HOUR_MICROSECOND: case INTERVAL_MINUTE_MICROSECOND: case INTERVAL_SECOND_MICROSECOND: + case INTERVAL_MICROSECOND: my_error(ER_NOT_SUPPORTED_YET, MYF(0), "MICROSECOND"); return 1; break; @@ -472,16 +472,15 @@ common_1_lev_code: table The table pointer RETURN - 1 Cannot lock table + 1 Cannot lock table 2 The table is corrupted - different number of fields - 0 OK + 0 OK */ int evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) { TABLE_LIST tables; - bool not_used; DBUG_ENTER("open_proc_table"); bzero((char*) &tables, sizeof(tables)); @@ -494,7 +493,7 @@ evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) if (table_check_intact(tables.table, EVEX_FIELD_COUNT, event_table_fields, &mysql_event_last_create_time, - ER_EVENT_CANNOT_LOAD_FROM_TABLE)) + ER_CANNOT_LOAD_FROM_TABLE)) { close_thread_tables(thd); DBUG_RETURN(2); @@ -520,7 +519,7 @@ evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table) */ inline int -evex_db_find_event_aux(THD *thd, event_timed *et, TABLE *table) +evex_db_find_event_aux(THD *thd, Event_timed *et, TABLE *table) { return evex_db_find_event_by_name(thd, et->dbname, et->name, et->definer, table); @@ -589,26 +588,26 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, thd THD table the row to fill out et Event's data - + Returns 0 - ok EVEX_GENERAL_ERROR - bad data - EVEX_GET_FIELD_FAILED - field count does not match. table corrupted? + EVEX_GET_FIELD_FAILED - field count does not match. table corrupted? DESCRIPTION Used both when an event is created and when it is altered. */ static int -evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update) +evex_fill_row(THD *thd, TABLE *table, Event_timed *et, my_bool is_update) { enum evex_table_field field_num; DBUG_ENTER("evex_fill_row"); - DBUG_PRINT("info", ("dbname=[%s]", et->dbname.str)); - DBUG_PRINT("info", ("name =[%s]", et->name.str)); - DBUG_PRINT("info", ("body =[%s]", et->body.str)); + DBUG_PRINT("info", ("dbname=[%s]", et->dbname.str)); + DBUG_PRINT("info", ("name =[%s]", et->name.str)); + DBUG_PRINT("info", ("body =[%s]", et->body.str)); if (table->field[field_num= EVEX_FIELD_DB]-> store(et->dbname.str, et->dbname.length, system_charset_info)) @@ -618,10 +617,11 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update) store(et->name.str, et->name.length, system_charset_info)) goto trunc_err; - // both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull() - table->field[EVEX_FIELD_ON_COMPLETION]->store((longlong)et->on_completion); + /* both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull() */ + table->field[EVEX_FIELD_ON_COMPLETION]->store((longlong)et->on_completion, + true); - table->field[EVEX_FIELD_STATUS]->store((longlong)et->status); + table->field[EVEX_FIELD_STATUS]->store((longlong)et->status, true); /* Change the SQL_MODE only if body was present in an ALTER EVENT and of course @@ -629,70 +629,76 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update) */ if (et->body.str) { - table->field[EVEX_FIELD_SQL_MODE]->store((longlong)thd->variables.sql_mode); + table->field[EVEX_FIELD_SQL_MODE]->store((longlong)thd->variables.sql_mode, + true); if (table->field[field_num= EVEX_FIELD_BODY]-> store(et->body.str, et->body.length, system_charset_info)) goto trunc_err; } - if (et->starts.year) - { - table->field[EVEX_FIELD_STARTS]->set_notnull();// set NULL flag to OFF - table->field[EVEX_FIELD_STARTS]-> - store_time(&et->starts, MYSQL_TIMESTAMP_DATETIME); - } - - if (et->ends.year) - { - table->field[EVEX_FIELD_ENDS]->set_notnull(); - table->field[EVEX_FIELD_ENDS]-> - store_time(&et->ends, MYSQL_TIMESTAMP_DATETIME); - } - if (et->expression) { table->field[EVEX_FIELD_INTERVAL_EXPR]->set_notnull(); - table->field[EVEX_FIELD_INTERVAL_EXPR]->store((longlong)et->expression); + table->field[EVEX_FIELD_INTERVAL_EXPR]->store((longlong)et->expression,true); table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_notnull(); /* In the enum (C) intervals start from 0 but in mysql enum valid values start from 1. Thus +1 offset is needed! */ - table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->store((longlong)et->interval+1); + table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->store((longlong)et->interval+1, + true); table->field[EVEX_FIELD_EXECUTE_AT]->set_null(); + + if (!et->starts_null) + { + table->field[EVEX_FIELD_STARTS]->set_notnull(); + table->field[EVEX_FIELD_STARTS]-> + store_time(&et->starts, MYSQL_TIMESTAMP_DATETIME); + } + + if (!et->ends_null) + { + table->field[EVEX_FIELD_ENDS]->set_notnull(); + table->field[EVEX_FIELD_ENDS]-> + store_time(&et->ends, MYSQL_TIMESTAMP_DATETIME); + } } else if (et->execute_at.year) { - // fix_fields already called in init_execute_at table->field[EVEX_FIELD_INTERVAL_EXPR]->set_null(); table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_null(); - + table->field[EVEX_FIELD_STARTS]->set_null(); + table->field[EVEX_FIELD_ENDS]->set_null(); + table->field[EVEX_FIELD_EXECUTE_AT]->set_notnull(); table->field[EVEX_FIELD_EXECUTE_AT]->store_time(&et->execute_at, - MYSQL_TIMESTAMP_DATETIME); - - table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_null(); + MYSQL_TIMESTAMP_DATETIME); } else { DBUG_ASSERT(is_update); - // it is normal to be here when the action is update - // this is an error if the action is create. something is borked + /* + it is normal to be here when the action is update + this is an error if the action is create. something is borked + */ } ((Field_timestamp *)table->field[EVEX_FIELD_MODIFIED])->set_time(); - if (et->comment.length) - if (table->field[field_num= EVEX_FIELD_COMMENT]-> - store(et->comment.str, et->comment.length, system_charset_info)) + if (et->comment.str) + { + if (table->field[field_num= EVEX_FIELD_COMMENT]->store(et->comment.str, + et->comment.length, + system_charset_info)) goto trunc_err; + } DBUG_RETURN(0); trunc_err: - my_error(ER_EVENT_DATA_TOO_LONG, MYF(0)); + my_error(ER_EVENT_DATA_TOO_LONG, MYF(0), table->field[field_num]->field_name); DBUG_RETURN(EVEX_GENERAL_ERROR); } @@ -703,25 +709,24 @@ trunc_err: SYNOPSIS db_create_event() thd THD - et event_timed object containing information for the event + et Event_timed object containing information for the event create_if_not - if an warning should be generated in case event exists rows_affected - how many rows were affected - + Return value 0 - OK EVEX_GENERAL_ERROR - Failure DESCRIPTION - Creates an event. Relies on evex_fill_row which is shared with + Creates an event. Relies on evex_fill_row which is shared with db_update_event. The name of the event is inside "et". */ static int -db_create_event(THD *thd, event_timed *et, my_bool create_if_not, +db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, uint *rows_affected) { int ret= 0; TABLE *table; - char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; char olddb[128]; bool dbchanged= false; DBUG_ENTER("db_create_event"); @@ -734,16 +739,16 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not, my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); goto err; } - + DBUG_PRINT("info", ("check existance of an event with the same name")); if (!evex_db_find_event_aux(thd, et, table)) { if (create_if_not) { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, - ER_EVENT_ALREADY_EXISTS, ER(ER_EVENT_ALREADY_EXISTS), - et->name.str); - goto ok; + ER_EVENT_ALREADY_EXISTS, ER(ER_EVENT_ALREADY_EXISTS), + et->name.str); + goto ok; } my_error(ER_EVENT_ALREADY_EXISTS, MYF(0), et->name.str); goto err; @@ -755,8 +760,8 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not, my_error(ER_BAD_DB_ERROR, MYF(0)); goto err; } - - restore_record(table, s->default_values); // Get default values for fields + + restore_record(table, s->default_values); // Get default values for fields if (system_charset_info->cset->numchars(system_charset_info, et->dbname.str, et->dbname.str + et->dbname.length) @@ -782,7 +787,7 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not, if (!(et->expression) && !(et->execute_at.year)) { DBUG_PRINT("error", ("neither expression nor execute_at are set!")); - my_error(ER_EVENT_NEITHER_M_EXPR_NOR_M_AT, MYF(0)); + my_error(ER_EVENT_NEITHER_M_EXPR_NOR_M_AT, MYF(0)); goto err; } @@ -796,7 +801,10 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not, ((Field_timestamp *)table->field[EVEX_FIELD_CREATED])->set_time(); - // evex_fill_row() calls my_error() in case of error so no need to handle it here + /* + evex_fill_row() calls my_error() in case of error so no need to + handle it here + */ if ((ret= evex_fill_row(thd, table, et, false))) goto err; @@ -805,7 +813,8 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not, my_error(ER_EVENT_STORE_FAILED, MYF(0), et->name.str, ret); goto err; } - + +#ifdef USE_THIS_CODE_AS_TEMPLATE_WHEN_EVENT_REPLICATION_IS_AGREED if (mysql_bin_log.is_open()) { thd->clear_error(); @@ -813,7 +822,8 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not, thd->binlog_query(THD::MYSQL_QUERY_TYPE, thd->query, thd->query_length, FALSE, FALSE); } - +#endif + *rows_affected= 1; ok: if (dbchanged) @@ -839,14 +849,14 @@ err: thd THD sp_name the name of the event to alter et event's data - + NOTES sp_name is passed since this is the name of the event to alter in case of RENAME TO. */ static int -db_update_event(THD *thd, event_timed *et, sp_name *new_name) +db_update_event(THD *thd, Event_timed *et, sp_name *new_name) { TABLE *table; int ret= EVEX_OPEN_TABLE_FAILED; @@ -864,7 +874,7 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name) goto err; } - // first look whether we overwrite + /* first look whether we overwrite */ if (new_name) { if (!sortcmp_lex_string(et->name, new_name->m_name, system_charset_info) && @@ -890,19 +900,18 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name) if (EVEX_KEY_NOT_FOUND == evex_db_find_event_aux(thd, et, table)) { my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), et->name.str); - goto err; + goto err; } - store_record(table,record[1]); - - // Don't update create on row update. + + /* Don't update create on row update. */ table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; - // evex_fill_row() calls my_error() in case of error so no need to handle it here + /* evex_fill_row() calls my_error() in case of error so no need to handle it here */ if ((ret= evex_fill_row(thd, table, et, true))) goto err; - + if (new_name) { table->field[EVEX_FIELD_DB]-> @@ -917,7 +926,7 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name) goto err; } - // close mysql.event or we crash later when loading the event from disk + /* close mysql.event or we crash later when loading the event from disk */ close_thread_tables(thd); DBUG_RETURN(0); @@ -939,20 +948,19 @@ err: definer who owns the event ett event's data if event is found tbl TABLE object to use when not NULL - + NOTES 1) Use sp_name for look up, return in **ett if found 2) tbl is not closed at exit */ static int -db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, event_timed **ett, +db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, Event_timed **ett, TABLE *tbl, MEM_ROOT *root) { TABLE *table; int ret; - char *ptr; - event_timed *et=NULL; + Event_timed *et=NULL; DBUG_ENTER("db_find_event"); DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str)); @@ -974,7 +982,7 @@ db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, event_timed **ett, my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), name->m_name.str); goto done; } - et= new event_timed; + et= new Event_timed; /* 1)The table should not be closed beforehand. ::load_from_row() only loads @@ -984,7 +992,7 @@ db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, event_timed **ett, */ if ((ret= et->load_from_row(root, table))) { - my_error(ER_EVENT_CANNOT_LOAD_FROM_TABLE, MYF(0)); + my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0)); goto done; } @@ -994,7 +1002,7 @@ done: delete et; et= 0; } - // don't close the table if we haven't opened it ourselves + /* don't close the table if we haven't opened it ourselves */ if (!tbl && table) close_thread_tables(thd); *ett= et; @@ -1012,11 +1020,10 @@ done: spn the name of the event to alter definer who is the owner use_lock whether to obtain a lock on LOCK_event_arrays or not - + RETURN VALUE 0 - OK < 0 - error (in this case underlying functions call my_error()). - */ static int @@ -1025,7 +1032,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, LEX_STRING definer, { int ret= 0; MEM_ROOT *tmp_mem_root; - event_timed *ett; + Event_timed *ett; Open_tables_state backup; DBUG_ENTER("db_load_and_compile_event"); @@ -1035,7 +1042,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, LEX_STRING definer, thd->mem_root= &evex_mem_root; thd->reset_n_backup_open_tables_state(&backup); - // no need to use my_error() here because db_find_event() has done it + /* no need to use my_error() here because db_find_event() has done it */ ret= db_find_event(thd, spn, &definer, &ett, NULL, NULL); thd->restore_backup_open_tables_state(&backup); if (ret) @@ -1082,12 +1089,12 @@ done: use_lock - whether to lock the mutex LOCK_event_arrays or not in case it has been already locked outside is_drop - if an event is currently being executed then we can also delete - the event_timed instance, so we alarm the event that it should + the Event_timed instance, so we alarm the event that it should drop itself if this parameter is set to TRUE. It's false on ALTER EVENT. RETURNS - 0 - OK (always) + 0 OK (always) */ static int @@ -1109,8 +1116,8 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock, for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) { - event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, event_timed*); - DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?",db->str,name->str, et->dbname.str, + Event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, Event_timed*); + DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?",db->str,name->str, et->dbname.str, et->name.str)); if (!sortcmp_lex_string(*name, et->name, system_charset_info) && !sortcmp_lex_string(*db, et->dbname, system_charset_info)) @@ -1130,7 +1137,7 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock, } DBUG_PRINT("evex_remove_from_cache", ("delete from queue")); evex_queue_delete_element(&EVEX_EQ_NAME, i); - // ok, we have cleaned + /* ok, we have cleaned */ ret= 0; goto done; } @@ -1154,14 +1161,14 @@ done: create_options Options specified when in the query. We are interested whether there is IF NOT EXISTS rows_affected How many rows were affected - + NOTES - in case there is an event with the same name (db) and IF NOT EXISTS is specified, an warning is put into the W stack. */ int -evex_create_event(THD *thd, event_timed *et, uint create_options, +evex_create_event(THD *thd, Event_timed *et, uint create_options, uint *rows_affected) { int ret = 0; @@ -1184,7 +1191,7 @@ evex_create_event(THD *thd, event_timed *et, uint create_options, VOID(pthread_mutex_unlock(&LOCK_evex_running)); done: - // No need to close the table, it will be closed in sql_parse::do_command + /* No need to close the table, it will be closed in sql_parse::do_command */ DBUG_RETURN(ret); } @@ -1198,7 +1205,7 @@ done: thd THD et event's data new_name set in case of RENAME TO. - + NOTES et contains data about dbname and event name. new_name is the new name of the event, if not null (this means @@ -1206,10 +1213,10 @@ done: */ int -evex_update_event(THD *thd, event_timed *et, sp_name *new_name, +evex_update_event(THD *thd, Event_timed *et, sp_name *new_name, uint *rows_affected) { - int ret, i; + int ret; bool need_second_pass= true; DBUG_ENTER("evex_update_event"); @@ -1258,10 +1265,9 @@ done: et event's name drop_if_exists if set and the event not existing => warning onto the stack rows_affected affected number of rows is returned heres - */ -int db_drop_event(THD *thd, event_timed *et, bool drop_if_exists, +int db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, uint *rows_affected) { TABLE *table; @@ -1291,8 +1297,8 @@ int db_drop_event(THD *thd, event_timed *et, bool drop_if_exists, if (drop_if_exists) { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, - ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), - "Event", et->name.str); + ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), + "Event", et->name.str); ret= 0; } else my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), et->name.str); @@ -1302,7 +1308,7 @@ int db_drop_event(THD *thd, event_timed *et, bool drop_if_exists, done: /* - evex_drop_event() is used by event_timed::drop therefore + evex_drop_event() is used by Event_timed::drop therefore we have to close our thread tables. */ close_thread_tables(thd); @@ -1324,10 +1330,9 @@ done: */ int -evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists, +evex_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, uint *rows_affected) { - TABLE *table; int ret= 0; DBUG_ENTER("evex_drop_event"); @@ -1337,7 +1342,7 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists, if (evex_is_running) ret= evex_remove_from_cache(&et->dbname, &et->name, true, true); VOID(pthread_mutex_unlock(&LOCK_evex_running)); - + if (ret == 1) ret= 0; else if (ret == 0) @@ -1357,18 +1362,17 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists, thd THD spn the name of the event (db, name) definer the definer of the event - + RETURNS 0 - OK 1 - Error during writing to the wire - */ int evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) { int ret; - event_timed *et= NULL; + Event_timed *et= NULL; Open_tables_state backup; DBUG_ENTER("evex_update_event"); @@ -1379,14 +1383,14 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) thd->restore_backup_open_tables_state(&backup); if (!ret && et) - { + { Protocol *protocol= thd->protocol; char show_str_buf[768]; String show_str(show_str_buf, sizeof(show_str_buf), system_charset_info); List<Item> field_list; byte *sql_mode_str; ulong sql_mode_len=0; - + show_str.length(0); show_str.set_charset(system_charset_info); @@ -1412,19 +1416,18 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info); - protocol->store(show_str.c_ptr(), show_str.length(), system_charset_info); ret= protocol->write(); send_eof(thd); } - + DBUG_RETURN(ret); } /* evex_drop_db_events - Drops all events in the selected database - + thd - Thread db - ASCIIZ the name of the database @@ -1438,17 +1441,16 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer) 1. Go through the in-memory cache, if the scheduler is working and for every event whose dbname matches the database we drop check whether is currently in execution: - - event_timed::can_spawn() returns true -> the event is not + - Event_timed::can_spawn() returns true -> the event is not being executed in a child thread. The reason not to use - event_timed::is_running() is that the latter shows only if + Event_timed::is_running() is that the latter shows only if it is being executed, which is 99% of the time in the thread but there are some initiliazations before and after the anonymous SP is being called. So if we delete in this moment -=> *boom*, so we have to check whether the thread has been spawned and can_spawn() is the right method. - - event_timed::can_spawn() returns false -> being runned ATM + - Event_timed::can_spawn() returns false -> being runned ATM just set the flags so it should drop itself. - */ int @@ -1456,7 +1458,6 @@ evex_drop_db_events(THD *thd, char *db) { TABLE *table; READ_RECORD read_record_info; - MYSQL_LOCK *lock; int ret= 0; uint i; LEX_STRING db_lex= {db, strlen(db)}; @@ -1464,7 +1465,6 @@ evex_drop_db_events(THD *thd, char *db) DBUG_ENTER("evex_drop_db_events"); DBUG_PRINT("info",("dropping events from %s", db)); - VOID(pthread_mutex_lock(&LOCK_event_arrays)); if ((ret= evex_open_event_table(thd, TL_WRITE, &table))) @@ -1482,7 +1482,7 @@ evex_drop_db_events(THD *thd, char *db) for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) { - event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, event_timed*); + Event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, Event_timed*); if (sortcmp_lex_string(et->dbname, db_lex, system_charset_info)) continue; @@ -1505,7 +1505,7 @@ evex_drop_db_events(THD *thd, char *db) else if (ret == EVEX_KEY_NOT_FOUND) { sql_print_error("Expected to find event %s.%s of %s on disk-not there.", - et->dbname.str, et->name.str, et->definer.str); + et->dbname.str, et->name.str, et->definer.str); } et->free_sp(); delete et; @@ -1521,7 +1521,7 @@ evex_drop_db_events(THD *thd, char *db) } DBUG_PRINT("info",("%d elements in the queue", evex_queue_num_elements(EVEX_EQ_NAME))); - evex_queue_delete_element(&EVEX_EQ_NAME, i);// 1 is top + evex_queue_delete_element(&EVEX_EQ_NAME, i);// 0 is top DBUG_PRINT("info",("%d elements in the queue", evex_queue_num_elements(EVEX_EQ_NAME))); /* @@ -1559,7 +1559,7 @@ skip_memory: LEX_STRING et_db_lex= {et_db, strlen(et_db)}; if (!sortcmp_lex_string(et_db_lex, db_lex, system_charset_info)) { - event_timed ett; + Event_timed ett; char *ptr; if ((ptr= get_field(thd->mem_root, table->field[EVEX_FIELD_STATUS])) @@ -1598,7 +1598,7 @@ end: VOID(pthread_mutex_unlock(&LOCK_event_arrays)); end_read_record(&read_record_info); - thd->version--; // Force close to free memory + thd->version--; /* Force close to free memory */ close_thread_tables(thd); diff --git a/sql/event.h b/sql/event.h index 4adacdd4e3a..d070f93c575 100644 --- a/sql/event.h +++ b/sql/event.h @@ -35,6 +35,7 @@ #define EVEX_BODY_TOO_LONG SP_BODY_TOO_LONG #define EVEX_BAD_PARAMS -21 #define EVEX_NOT_RUNNING -22 +#define EVEX_MICROSECOND_UNSUP -23 #define EVENT_EXEC_NO_MORE (1L << 0) #define EVENT_NOT_USED (1L << 1) @@ -75,10 +76,10 @@ enum evex_table_field EVEX_FIELD_COUNT /* a cool trick to count the number of fields :) */ } ; -class event_timed +class Event_timed { - event_timed(const event_timed &); /* Prevent use of these */ - void operator=(event_timed &); + Event_timed(const Event_timed &); /* Prevent use of these */ + void operator=(Event_timed &); my_bool in_spawned_thread; ulong locked_by_thread_id; my_bool running; @@ -102,6 +103,9 @@ public: TIME starts; TIME ends; TIME execute_at; + my_bool starts_null; + my_bool ends_null; + my_bool execute_at_null; longlong expression; interval_type interval; @@ -118,7 +122,7 @@ public: bool free_sphead_on_delete; uint flags;//all kind of purposes - event_timed():in_spawned_thread(0),locked_by_thread_id(0), + Event_timed():in_spawned_thread(0),locked_by_thread_id(0), running(0), status_changed(false), last_executed_changed(false), expression(0), created(0), modified(0), on_completion(MYSQL_EVENT_ON_COMPLETION_DROP), @@ -131,7 +135,7 @@ public: init(); } - ~event_timed() + ~Event_timed() { pthread_mutex_destroy(&this->LOCK_running); if (free_sphead_on_delete) @@ -255,15 +259,15 @@ protected: int -evex_create_event(THD *thd, event_timed *et, uint create_options, +evex_create_event(THD *thd, Event_timed *et, uint create_options, uint *rows_affected); int -evex_update_event(THD *thd, event_timed *et, sp_name *new_name, +evex_update_event(THD *thd, Event_timed *et, sp_name *new_name, uint *rows_affected); int -evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists, +evex_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, uint *rows_affected); int @@ -292,7 +296,7 @@ shutdown_events(); // auxiliary int -event_timed_compare(event_timed **a, event_timed **b); +event_timed_compare(Event_timed **a, Event_timed **b); diff --git a/sql/event_executor.cc b/sql/event_executor.cc index b6c6981fd7d..92acf154c75 100644 --- a/sql/event_executor.cc +++ b/sql/event_executor.cc @@ -38,9 +38,9 @@ extern ulong thread_created; extern const char *my_localhost; extern pthread_attr_t connection_attrib; -pthread_mutex_t LOCK_event_arrays, // mutex for when working with the queue - LOCK_workers_count, // mutex for when inc/dec uint workers_count - LOCK_evex_running; // mutes for managing bool evex_is_running +pthread_mutex_t LOCK_event_arrays, // mutex for when working with the queue + LOCK_workers_count, // mutex for when inc/dec uint workers_count + LOCK_evex_running; // mutes for managing bool evex_is_running bool evex_is_running= false; @@ -48,14 +48,14 @@ bool evex_is_running= false; ulonglong evex_main_thread_id= 0; ulong opt_event_executor; my_bool event_executor_running_global_var; -static my_bool evex_mutexes_initted= false; +static my_bool evex_mutexes_initted= FALSE; static uint workers_count; static int evex_load_events_from_db(THD *thd); bool -evex_print_warnings(THD *thd, event_timed *et); +evex_print_warnings(THD *thd, Event_timed *et); /* TODO Andrey: Check for command line option whether to start @@ -107,7 +107,7 @@ evex_init_mutexes() if (evex_mutexes_initted) return; - evex_mutexes_initted= true; + evex_mutexes_initted= TRUE; pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST); @@ -132,10 +132,9 @@ evex_check_system_tables() { THD *thd= current_thd; TABLE_LIST tables; - bool not_used; Open_tables_state backup; - // thd is 0x0 during boot of the server. Later it's !=0x0 + /* thd is 0x0 during boot of the server. Later it's !=0x0 */ if (!thd) return; @@ -151,7 +150,7 @@ evex_check_system_tables() else { table_check_intact(tables.table, MYSQL_DB_FIELD_COUNT, mysql_db_table_fields, - &mysql_db_table_last_check,ER_EVENT_CANNOT_LOAD_FROM_TABLE); + &mysql_db_table_last_check,ER_CANNOT_LOAD_FROM_TABLE); close_thread_tables(thd); } @@ -182,7 +181,7 @@ evex_check_system_tables() SYNOPSIS init_events() - + NOTES Inits the mutexes used by the scheduler. Done at server start. */ @@ -191,11 +190,10 @@ int init_events() { pthread_t th; - DBUG_ENTER("init_events"); DBUG_PRINT("info",("Starting events main thread")); - + evex_check_system_tables(); evex_init_mutexes(); @@ -207,7 +205,7 @@ init_events() if (event_executor_running_global_var) { #ifndef DBUG_FAULTY_THR - //TODO Andrey: Change the error code returned! + /* TODO Andrey: Change the error code returned! */ if (pthread_create(&th, &connection_attrib, event_executor_main,(void*)NULL)) DBUG_RETURN(ER_SLAVE_THREAD); #else @@ -224,7 +222,7 @@ init_events() SYNOPSIS shutdown_events() - + NOTES Destroys the mutexes. */ @@ -233,14 +231,17 @@ void shutdown_events() { DBUG_ENTER("shutdown_events"); - - VOID(pthread_mutex_lock(&LOCK_evex_running)); - VOID(pthread_mutex_unlock(&LOCK_evex_running)); - pthread_mutex_destroy(&LOCK_event_arrays); - pthread_mutex_destroy(&LOCK_workers_count); - pthread_mutex_destroy(&LOCK_evex_running); - + if (evex_mutexes_initted) + { + evex_mutexes_initted= FALSE; + VOID(pthread_mutex_lock(&LOCK_evex_running)); + VOID(pthread_mutex_unlock(&LOCK_evex_running)); + + pthread_mutex_destroy(&LOCK_event_arrays); + pthread_mutex_destroy(&LOCK_workers_count); + pthread_mutex_destroy(&LOCK_evex_running); + } DBUG_VOID_RETURN; } @@ -251,11 +252,11 @@ shutdown_events() SYNOPSIS init_event_thread() thd - the THD of the thread. Has to be allocated by the caller. - + NOTES 1. The host of the thead is my_localhost 2. thd->net is initted with NULL - no communication. - + Returns 0 - OK -1 - Error @@ -272,7 +273,7 @@ init_event_thread(THD* thd) my_net_init(&thd->net, 0); thd->net.read_timeout = slave_net_timeout; thd->slave_thread= 0; - thd->options= OPTION_AUTO_IS_NULL; + thd->options|= OPTION_AUTO_IS_NULL; thd->client_capabilities= CLIENT_LOCAL_FILES; thd->real_id=pthread_self(); VOID(pthread_mutex_lock(&LOCK_thread_count)); @@ -302,7 +303,7 @@ init_event_thread(THD* thd) /* This function waits till the time next event in the queue should be executed. - + Returns WAIT_STATUS_READY There is an event to be executed right now WAIT_STATUS_EMPTY_QUEUE No events or the last event was dropped. @@ -314,7 +315,7 @@ init_event_thread(THD* thd) static int executor_wait_till_next_event_exec(THD *thd) { - event_timed *et; + Event_timed *et; TIME time_now; int t2sleep; @@ -327,9 +328,9 @@ executor_wait_till_next_event_exec(THD *thd) if (!evex_queue_num_elements(EVEX_EQ_NAME)) { VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - DBUG_RETURN(1); + DBUG_RETURN(WAIT_STATUS_EMPTY_QUEUE); } - et= evex_queue_first_element(&EVEX_EQ_NAME, event_timed*); + et= evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*); DBUG_ASSERT(et); if (et->status == MYSQL_EVENT_DISABLED) { @@ -337,14 +338,14 @@ executor_wait_till_next_event_exec(THD *thd) if (et->dropped) et->drop(thd); delete et; - evex_queue_delete_element(&EVEX_EQ_NAME, 1);// 1 is top + evex_queue_delete_element(&EVEX_EQ_NAME, 0);// 0 is top, internally 1 VOID(pthread_mutex_unlock(&LOCK_event_arrays)); sql_print_information("Event found disabled, dropping."); DBUG_RETURN(1); } - + DBUG_PRINT("evex main thread",("computing time to sleep till next exec")); - // set the internal clock of thd + /* set the internal clock of thd */ thd->end_time(); my_tz_UTC->gmt_sec_to_TIME(&time_now, thd->query_start()); t2sleep= evex_time_diff(&et->execute_at, &time_now); @@ -353,26 +354,33 @@ executor_wait_till_next_event_exec(THD *thd) DBUG_PRINT("evex main thread",("unlocked LOCK_event_arrays")); if (t2sleep > 0) { + ulonglong modified= et->modified; /* We sleep t2sleep seconds but we check every second whether this thread has been killed, or there is a new candidate */ while (t2sleep-- && !thd->killed && event_executor_running_global_var && evex_queue_num_elements(EVEX_EQ_NAME) && - (evex_queue_first_element(&EVEX_EQ_NAME, event_timed*) == et)) + (evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*) == et && + evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*)->modified == + modified)) { - DBUG_PRINT("evex main thread",("will sleep a bit more")); + DBUG_PRINT("evex main thread",("will sleep a bit more.")); my_sleep(1000000); } + DBUG_PRINT("info",("saved_modified=%llu current=%llu", modified, + evex_queue_num_elements(EVEX_EQ_NAME)? + evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*)->modified: + (ulonglong)~0)); } - int ret= 0; + int ret= WAIT_STATUS_READY; if (!evex_queue_num_elements(EVEX_EQ_NAME)) - ret= 1; - else if (evex_queue_first_element(&EVEX_EQ_NAME, event_timed*) != et) - ret= 2; + ret= WAIT_STATUS_EMPTY_QUEUE; + else if (evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*) != et) + ret= WAIT_STATUS_NEW_TOP_EVENT; if (thd->killed && event_executor_running_global_var) - ret= 3; + ret= WAIT_STATUS_STOP_EXECUTOR; DBUG_RETURN(ret); } @@ -385,8 +393,8 @@ executor_wait_till_next_event_exec(THD *thd) SYNOPSIS event_executor_main() - arg - unused - + arg unused + NOTES 1. The host of the thead is my_localhost 2. thd->net is initted with NULL - no communication. @@ -399,17 +407,15 @@ event_executor_main(void *arg) THD *thd; /* needs to be first for thread_stack */ uint i=0, j=0; my_ulonglong cnt= 0; - TIME time_now; DBUG_ENTER("event_executor_main"); - DBUG_PRINT("event_executor_main", ("EVEX thread started")); + DBUG_PRINT("event_executor_main", ("EVEX thread started")); - // init memory root + /* init memory root */ init_alloc_root(&evex_mem_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC); - - // needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff + /* needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff*/ my_thread_init(); if (sizeof(my_time_t) != sizeof(time_t)) @@ -420,14 +426,14 @@ event_executor_main(void *arg) goto err_no_thd; } - //TODO Andrey: Check for NULL - if (!(thd = new THD)) // note that contructor of THD uses DBUG_ ! + /* note that contructor of THD uses DBUG_ ! */ + if (!(thd = new THD)) { sql_print_error("SCHEDULER: Cannot create THD for the main thread."); goto err_no_thd; } - thd->thread_stack = (char*)&thd; // remember where our stack is - + thd->thread_stack = (char*)&thd; // remember where our stack is + pthread_detach_this_thread(); if (init_event_thread(thd)) @@ -469,8 +475,8 @@ event_executor_main(void *arg) while (!thd->killed) { TIME time_now; - event_timed *et; - + Event_timed *et; + cnt++; DBUG_PRINT("info", ("EVEX External Loop %d thd->k", cnt)); @@ -486,7 +492,7 @@ event_executor_main(void *arg) my_sleep(1000000);// sleep 1s continue; } - + restart_ticking: switch (executor_wait_till_next_event_exec(thd)) { case WAIT_STATUS_READY: // time to execute the event on top @@ -496,7 +502,7 @@ restart_ticking: DBUG_PRINT("evex main thread",("no more events")); continue; break; - case WAIT_STATUS_NEW_TOP_EVENT: // new event on top in the queue + case WAIT_STATUS_NEW_TOP_EVENT: // new event on top in the queue DBUG_PRINT("evex main thread",("restart ticking")); goto restart_ticking; case WAIT_STATUS_STOP_EXECUTOR: @@ -518,11 +524,10 @@ restart_ticking: DBUG_PRINT("evex main thread",("empty queue")); continue; } - et= evex_queue_first_element(&EVEX_EQ_NAME, event_timed*); + et= evex_queue_first_element(&EVEX_EQ_NAME, Event_timed*); DBUG_PRINT("evex main thread",("got event from the queue")); - if (et->execute_at.year > 1969 && - my_time_compare(&time_now, &et->execute_at) == -1) + if (!et->execute_at_null && my_time_compare(&time_now,&et->execute_at) == -1) { DBUG_PRINT("evex main thread",("still not the time for execution")); VOID(pthread_mutex_unlock(&LOCK_event_arrays)); @@ -569,8 +574,11 @@ restart_ticking: #else event_executor_worker((void *) et); #endif - if ((et->execute_at.year && !et->expression) || - TIME_to_ulonglong_datetime(&et->execute_at) == 0) + /* + 1. For one-time event : year is > 0 and expression is 0 + 2. For recurring, expression is != -=> check execute_at_null in this case + */ + if ((et->execute_at.year && !et->expression) || et->execute_at_null) et->flags |= EVENT_EXEC_NO_MORE; if ((et->flags & EVENT_EXEC_NO_MORE) || et->status == MYSQL_EVENT_DISABLED) @@ -580,10 +588,10 @@ restart_ticking: } DBUG_PRINT("evex main thread",("unlocking")); VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - }// while + }/* while */ finish: - // First manifest that this thread does not work and then destroy + /* First manifest that this thread does not work and then destroy */ VOID(pthread_mutex_lock(&LOCK_evex_running)); evex_is_running= false; evex_main_thread_id= 0; @@ -607,7 +615,7 @@ finish: break; } VOID(pthread_mutex_unlock(&LOCK_workers_count)); - my_sleep(1000000);// 1s + my_sleep(1000000);// 1s } /* @@ -618,14 +626,14 @@ finish: VOID(pthread_mutex_lock(&LOCK_event_arrays)); for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) { - event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, event_timed*); + Event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, Event_timed*); et->free_sp(); delete et; } VOID(pthread_mutex_unlock(&LOCK_event_arrays)); - // ... then we can thrash the whole queue at once + /* ... then we can thrash the whole queue at once */ evex_queue_destroy(&EVEX_EQ_NAME); - + thd->proc_info = "Clearing"; DBUG_ASSERT(thd->net.buff != 0); net_end(&thd->net); // destructor will not free it, because we are weird @@ -653,7 +661,7 @@ err_no_thd: my_thread_end(); pthread_exit(0); #endif - DBUG_RETURN(0);// Can't return anything here + DBUG_RETURN(0); // Can't return anything here } @@ -663,14 +671,14 @@ err_no_thd: SYNOPSIS event_executor_worker() - arg - the event_timed object to be processed + arg The Event_timed object to be processed */ pthread_handler_t event_executor_worker(void *event_void) { THD *thd; /* needs to be first for thread_stack */ - event_timed *event = (event_timed *) event_void; + Event_timed *event = (Event_timed *) event_void; MEM_ROOT worker_mem_root; DBUG_ENTER("event_executor_worker"); @@ -680,12 +688,12 @@ event_executor_worker(void *event_void) #ifndef DBUG_FAULTY_THR my_thread_init(); - if (!(thd = new THD)) // note that contructor of THD uses DBUG_ ! + if (!(thd = new THD)) /* note that contructor of THD uses DBUG_ ! */ { sql_print_error("SCHEDULER: Cannot create a THD structure in an worker."); goto err_no_thd; } - thd->thread_stack = (char*)&thd; // remember where our stack is + thd->thread_stack = (char*)&thd; // remember where our stack is thd->mem_root= &worker_mem_root; pthread_detach_this_thread(); @@ -695,7 +703,7 @@ event_executor_worker(void *event_void) thd->init_for_queries(); - // make this thread visible it has no vio -> show processlist needs this flag + /* make this thread visible it has no vio -> show processlist needs this flag */ thd->system_thread= 1; VOID(pthread_mutex_lock(&LOCK_thread_count)); @@ -707,6 +715,7 @@ event_executor_worker(void *event_void) thd= current_thd; #endif + thd->enable_slow_log= TRUE; { int ret; sql_print_information("SCHEDULER: Executing event %s.%s of %s [EXPR:%d]", @@ -723,6 +732,8 @@ event_executor_worker(void *event_void) sql_print_information("SCHEDULER: COMPILE ERROR for event %s.%s of", event->dbname.str, event->name.str, event->definer.str); + else if (ret == EVEX_MICROSECOND_UNSUP) + sql_print_information("SCHEDULER: MICROSECOND is not supported"); } event->spawn_thread_finish(thd); @@ -743,7 +754,7 @@ err: DBUG_ASSERT(thd->net.buff != 0); net_end(&thd->net); // destructor will not free it, because we are weird THD_CHECK_SENTRY(thd); - + VOID(pthread_mutex_lock(&LOCK_thread_count)); THD_CHECK_SENTRY(thd); delete thd; @@ -766,7 +777,7 @@ err_no_thd: /* Loads all ENABLED events from mysql.event into the prioritized queue. Called during scheduler main thread initialization. Compiles - the events. Creates event_timed instances for every ENABLED event + the events. Creates Event_timed instances for every ENABLED event from mysql.event. SYNOPSIS @@ -774,9 +785,9 @@ err_no_thd: thd - Thread context. Used for memory allocation in some cases. RETURNS - 0 - OK - -1 - Error - + 0 OK + !0 Error + NOTES Reports the error to the console */ @@ -786,10 +797,9 @@ evex_load_events_from_db(THD *thd) { TABLE *table; READ_RECORD read_record_info; - MYSQL_LOCK *lock; int ret= -1; uint count= 0; - + DBUG_ENTER("evex_load_events_from_db"); if ((ret= evex_open_event_table(thd, TL_READ, &table))) @@ -803,8 +813,8 @@ evex_load_events_from_db(THD *thd) init_read_record(&read_record_info, thd, table ,NULL,1,0); while (!(read_record_info.read_record(&read_record_info))) { - event_timed *et; - if (!(et= new event_timed)) + Event_timed *et; + if (!(et= new Event_timed)) { DBUG_PRINT("evex_load_events_from_db", ("Out of memory")); ret= -1; @@ -824,18 +834,24 @@ evex_load_events_from_db(THD *thd) delete et; continue; } - + DBUG_PRINT("evex_load_events_from_db", ("Event %s loaded from row. Time to compile", et->name.str)); - if ((ret= et->compile(thd, &evex_mem_root))) - { + switch (ret= et->compile(thd, &evex_mem_root)) { + case EVEX_MICROSECOND_UNSUP: + sql_print_error("SCHEDULER: mysql.event is tampered. MICROSECOND is not " + "supported but found in mysql.event"); + goto end; + case EVEX_COMPILE_ERROR: sql_print_error("SCHEDULER: Error while compiling %s.%s. Aborting load.", et->dbname.str, et->name.str); goto end; + default: + break; } - - // let's find when to be executed + + /* let's find when to be executed */ if (et->compute_next_execution_time()) { sql_print_error("SCHEDULER: Error while computing execution time of %s.%s." @@ -856,11 +872,13 @@ evex_load_events_from_db(THD *thd) end: VOID(pthread_mutex_unlock(&LOCK_event_arrays)); end_read_record(&read_record_info); - - thd->version--; // Force close to free memory + + /* Force close to free memory */ + thd->version--; close_thread_tables(thd); - sql_print_information("SCHEDULER: Loaded %d event%s", count, (count == 1)?"":"s"); + if (!ret) + sql_print_information("SCHEDULER: Loaded %d event%s", count, (count == 1)?"":"s"); DBUG_PRINT("info", ("Status code %d. Loaded %d event(s)", ret, count)); DBUG_RETURN(ret); @@ -876,15 +894,15 @@ end: event_executor_worker() thd - Thread context (unused) car - the new value - + Returns - 0 - OK (always) + 0 OK (always) */ bool sys_var_event_executor::update(THD *thd, set_var *var) { - // here start the thread if not running. + /* here start the thread if not running. */ DBUG_ENTER("sys_var_event_executor::update"); VOID(pthread_mutex_lock(&LOCK_evex_running)); *value= var->save_result.ulong_value; @@ -916,32 +934,33 @@ static sql_print_xxx_func sql_print_xxx_handlers[3] = Prints the stack of infos, warnings, errors from thd to the console so it can be fetched by the logs-into-tables and checked later. - + Synopsis evex_print_warnings thd - thread used during the execution of the event et - the event itself - + Returns 0 - OK (always) */ bool -evex_print_warnings(THD *thd, event_timed *et) -{ +evex_print_warnings(THD *thd, Event_timed *et) +{ MYSQL_ERROR *err; DBUG_ENTER("evex_show_warnings"); char msg_buf[1024]; char prefix_buf[512]; String prefix(prefix_buf, sizeof(prefix_buf), system_charset_info); prefix.length(0); - + List_iterator_fast<MYSQL_ERROR> it(thd->warn_list); while ((err= it++)) { String err_msg(msg_buf, sizeof(msg_buf), system_charset_info); - err_msg.length(0);// set it to 0 or we start adding at the end + /* set it to 0 or we start adding at the end. That's the trick ;) */ + err_msg.length(0); if (!prefix.length()) { prefix.append("SCHEDULER: ["); @@ -955,7 +974,7 @@ evex_print_warnings(THD *thd, event_timed *et) append_identifier(thd,&prefix, et->name.str, et->name.length); prefix.append("] ", 2); } - + err_msg.append(prefix); err_msg.append(err->msg, strlen(err->msg), system_charset_info); err_msg.append("]"); diff --git a/sql/event_priv.h b/sql/event_priv.h index 4f575a96212..6b23136847e 100644 --- a/sql/event_priv.h +++ b/sql/event_priv.h @@ -44,7 +44,7 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, int event_timed_compare_q(void *vptr, byte* a, byte *b); -int db_drop_event(THD *thd, event_timed *et, bool drop_if_exists, +int db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists, uint *rows_affected); diff --git a/sql/event_timed.cc b/sql/event_timed.cc index a1ec7f6b718..a8620197668 100644 --- a/sql/event_timed.cc +++ b/sql/event_timed.cc @@ -26,13 +26,13 @@ extern int yyparse(void *thd); Init all member variables SYNOPSIS - event_timed::init() + Event_timed::init() */ void -event_timed::init() +Event_timed::init() { - DBUG_ENTER("event_timed::init"); + DBUG_ENTER("Event_timed::init"); dbname.str= name.str= body.str= comment.str= 0; dbname.length= name.length= body.length= comment.length= 0; @@ -41,6 +41,7 @@ event_timed::init() set_zero_time(&ends, MYSQL_TIMESTAMP_DATETIME); set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); set_zero_time(&last_executed, MYSQL_TIMESTAMP_DATETIME); + starts_null= ends_null= execute_at_null= TRUE; definer_user.str= definer_host.str= 0; definer_user.length= definer_host.length= 0; @@ -55,16 +56,15 @@ event_timed::init() Set a name of the event SYNOPSIS - event_timed::init_name() + Event_timed::init_name() thd THD spn the name extracted in the parser */ void -event_timed::init_name(THD *thd, sp_name *spn) +Event_timed::init_name(THD *thd, sp_name *spn) { - DBUG_ENTER("event_timed::init_name"); - uint n; /* Counter for nul trimming */ + DBUG_ENTER("Event_timed::init_name"); /* During parsing, we must use thd->mem_root */ MEM_ROOT *root= thd->mem_root; @@ -99,7 +99,7 @@ event_timed::init_name(THD *thd, sp_name *spn) Set body of the event - what should be executed. SYNOPSIS - event_timed::init_body() + Event_timed::init_body() thd THD NOTE @@ -108,14 +108,14 @@ event_timed::init_name(THD *thd, sp_name *spn) */ void -event_timed::init_body(THD *thd) +Event_timed::init_body(THD *thd) { - DBUG_ENTER("event_timed::init_body"); + DBUG_ENTER("Event_timed::init_body"); DBUG_PRINT("info", ("body=[%s] body_begin=0x%ld end=0x%ld", body_begin, body_begin, thd->lex->ptr)); body.length= thd->lex->ptr - body_begin; - // Trim nuls at the end + /* Trim nuls at the end */ while (body.length && body_begin[body.length-1] == '\0') body.length--; @@ -135,7 +135,7 @@ event_timed::init_body(THD *thd) Set time for execution for one time events. SYNOPSIS - event_timed::init_execute_at() + Event_timed::init_execute_at() expr when (datetime) RETURN VALUE @@ -146,23 +146,26 @@ event_timed::init_body(THD *thd) */ int -event_timed::init_execute_at(THD *thd, Item *expr) +Event_timed::init_execute_at(THD *thd, Item *expr) { my_bool not_used; TIME ltime; - my_time_t my_time_tmp; TIME time_tmp; - DBUG_ENTER("event_timed::init_execute_at"); + DBUG_ENTER("Event_timed::init_execute_at"); if (expr->fix_fields(thd, &expr)) DBUG_RETURN(EVEX_PARSE_ERROR); - - /* Let's check whether time is in the past */ - thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, + + /* no starts and/or ends in case of execute_at */ + DBUG_PRINT("info", ("starts_null && ends_null should be 1 is %d", + (starts_null && ends_null))); + DBUG_ASSERT(starts_null && ends_null); + + /* let's check whether time is in the past */ + thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t) thd->query_start()); - if ((not_used= expr->get_date(<ime, TIME_NO_ZERO_DATE))) DBUG_RETURN(ER_WRONG_VALUE); @@ -177,7 +180,7 @@ event_timed::init_execute_at(THD *thd, Item *expr) */ my_tz_UTC->gmt_sec_to_TIME(<ime, TIME_to_timestamp(thd,<ime, ¬_used)); - + execute_at_null= FALSE; execute_at= ltime; DBUG_RETURN(0); } @@ -187,7 +190,7 @@ event_timed::init_execute_at(THD *thd, Item *expr) Set time for execution for transient events. SYNOPSIS - event_timed::init_interval() + Event_timed::init_interval() expr how much? new_interval what is the interval @@ -195,16 +198,16 @@ event_timed::init_execute_at(THD *thd, Item *expr) 0 OK EVEX_PARSE_ERROR fix_fields failed EVEX_BAD_PARAMS Interval is not positive + EVEX_MICROSECOND_UNSUP Microseconds are not supported. */ int -event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) +Event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) { - longlong tmp; String value; INTERVAL interval; - DBUG_ENTER("event_timed::init_interval"); + DBUG_ENTER("Event_timed::init_interval"); if (expr->fix_fields(thd, &expr)) DBUG_RETURN(EVEX_PARSE_ERROR); @@ -245,15 +248,16 @@ event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) case INTERVAL_DAY_MINUTE: expression= (interval.day* 24 + interval.hour) * 60 + interval.minute; break; - case INTERVAL_HOUR_SECOND: // day is anyway 0 + case INTERVAL_HOUR_SECOND: /* day is anyway 0 */ case INTERVAL_DAY_SECOND: /* DAY_SECOND having problems because of leap seconds? */ expression= ((interval.day* 24 + interval.hour) * 60 + interval.minute)*60 + interval.second; break; - case INTERVAL_MINUTE_MICROSECOND: // day and hour are 0 - case INTERVAL_HOUR_MICROSECOND:// day is anyway 0 + case INTERVAL_MINUTE_MICROSECOND: /* day and hour are 0 */ + case INTERVAL_HOUR_MICROSECOND: /* day is anyway 0 */ case INTERVAL_DAY_MICROSECOND: + DBUG_RETURN(EVEX_MICROSECOND_UNSUP); expression= ((((interval.day*24) + interval.hour)*60+interval.minute)*60 + interval.second) * 1000000L + interval.second_part; break; @@ -264,10 +268,11 @@ event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) expression= interval.minute * 60 + interval.second; break; case INTERVAL_SECOND_MICROSECOND: + DBUG_RETURN(EVEX_MICROSECOND_UNSUP); expression= interval.second * 1000000L + interval.second_part; break; - default: - break; + case INTERVAL_MICROSECOND: + DBUG_RETURN(EVEX_MICROSECOND_UNSUP); } if (interval.neg || expression > EVEX_MAX_INTERVAL_VALUE) DBUG_RETURN(EVEX_BAD_PARAMS); @@ -281,7 +286,7 @@ event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) Set activation time. SYNOPSIS - event_timed::init_starts() + Event_timed::init_starts() expr how much? interval what is the interval @@ -299,12 +304,12 @@ event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval) */ int -event_timed::init_starts(THD *thd, Item *new_starts) +Event_timed::init_starts(THD *thd, Item *new_starts) { my_bool not_used; TIME ltime, time_tmp; - DBUG_ENTER("event_timed::init_starts"); + DBUG_ENTER("Event_timed::init_starts"); if (new_starts->fix_fields(thd, &new_starts)) DBUG_RETURN(EVEX_PARSE_ERROR); @@ -329,6 +334,7 @@ event_timed::init_starts(THD *thd, Item *new_starts) my_tz_UTC->gmt_sec_to_TIME(<ime, TIME_to_timestamp(thd, <ime, ¬_used)); starts= ltime; + starts_null= FALSE; DBUG_RETURN(0); } @@ -337,7 +343,7 @@ event_timed::init_starts(THD *thd, Item *new_starts) Set deactivation time. SYNOPSIS - event_timed::init_ends() + Event_timed::init_ends() thd THD new_ends when? @@ -356,31 +362,44 @@ event_timed::init_starts(THD *thd, Item *new_starts) */ int -event_timed::init_ends(THD *thd, Item *new_ends) +Event_timed::init_ends(THD *thd, Item *new_ends) { - TIME ltime; - my_time_t my_time_tmp; + TIME ltime, ltime_now; my_bool not_used; - DBUG_ENTER("event_timed::init_ends"); + DBUG_ENTER("Event_timed::init_ends"); if (new_ends->fix_fields(thd, &new_ends)) DBUG_RETURN(EVEX_PARSE_ERROR); - /* The field was already fixed in init_ends */ + DBUG_PRINT("info", ("convert to TIME")); if ((not_used= new_ends->get_date(<ime, TIME_NO_ZERO_DATE))) DBUG_RETURN(EVEX_BAD_PARAMS); /* - This may result in a 1970-01-01 date if ltime is > 2037-xx-xx. - CONVERT_TZ has similar problem. + This may result in a 1970-01-01 date if ltime is > 2037-xx-xx ? + CONVERT_TZ has similar problem ? */ + DBUG_PRINT("info", ("get the UTC time")); my_tz_UTC->gmt_sec_to_TIME(<ime, TIME_to_timestamp(thd, <ime, ¬_used)); - if (starts.year && my_time_compare(&starts, <ime) != -1) + /* Check whether ends is after starts */ + DBUG_PRINT("info", ("ENDS after STARTS?")); + if (!starts_null && my_time_compare(&starts, <ime) != -1) + DBUG_RETURN(EVEX_BAD_PARAMS); + + /* + The parser forces starts to be provided but one day STARTS could be + set before NOW() and in this case the following check should be done. + Check whether ENDS is not in the past. + */ + DBUG_PRINT("info", ("ENDS after NOW?")); + my_tz_UTC->gmt_sec_to_TIME(<ime_now, thd->query_start()); + if (my_time_compare(<ime_now, <ime) == 1) DBUG_RETURN(EVEX_BAD_PARAMS); ends= ltime; + ends_null= FALSE; DBUG_RETURN(0); } @@ -389,18 +408,18 @@ event_timed::init_ends(THD *thd, Item *new_ends) Sets comment. SYNOPSIS - event_timed::init_comment() + Event_timed::init_comment() thd THD - used for memory allocation comment the string. */ void -event_timed::init_comment(THD *thd, LEX_STRING *set_comment) +Event_timed::init_comment(THD *thd, LEX_STRING *set_comment) { - DBUG_ENTER("event_timed::init_comment"); + DBUG_ENTER("Event_timed::init_comment"); comment.str= strmake_root(thd->mem_root, set_comment->str, - comment.length= set_comment->length); + comment.length= set_comment->length); DBUG_VOID_RETURN; } @@ -410,13 +429,13 @@ event_timed::init_comment(THD *thd, LEX_STRING *set_comment) Inits definer (definer_user and definer_host) during parsing. SYNOPSIS - event_timed::init_definer() + Event_timed::init_definer() */ int -event_timed::init_definer(THD *thd) +Event_timed::init_definer(THD *thd) { - DBUG_ENTER("event_timed::init_definer"); + DBUG_ENTER("Event_timed::init_definer"); DBUG_PRINT("info",("init definer_user thd->mem_root=0x%lx " "thd->sec_ctx->priv_user=0x%lx", thd->mem_root, @@ -451,7 +470,7 @@ event_timed::init_definer(THD *thd) Loads an event from a row from mysql.event SYNOPSIS - event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) + Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) NOTES This method is silent on errors and should behave like that. Callers @@ -460,16 +479,14 @@ event_timed::init_definer(THD *thd) */ int -event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) +Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) { - longlong created; - longlong modified; char *ptr; - event_timed *et; + Event_timed *et; uint len; bool res1, res2; - DBUG_ENTER("event_timed::load_from_row"); + DBUG_ENTER("Event_timed::load_from_row"); if (!table) goto error; @@ -511,35 +528,44 @@ event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) et->definer_user.str= strmake_root(mem_root, et->definer.str, len); et->definer_user.length= len; - len= et->definer.length - len - 1; //1 is because of @ - et->definer_host.str= strmake_root(mem_root, ptr + 1, len);//1: because of @ + len= et->definer.length - len - 1; //1 is because of @ + et->definer_host.str= strmake_root(mem_root, ptr + 1, len);/* 1:because of @*/ et->definer_host.length= len; + + et->starts_null= table->field[EVEX_FIELD_STARTS]->is_null(); + res1= table->field[EVEX_FIELD_STARTS]->get_date(&et->starts,TIME_NO_ZERO_DATE); - res1= table->field[EVEX_FIELD_STARTS]-> - get_date(&et->starts, TIME_NO_ZERO_DATE); - - res2= table->field[EVEX_FIELD_ENDS]-> - get_date(&et->ends, TIME_NO_ZERO_DATE); - - et->expression= table->field[EVEX_FIELD_INTERVAL_EXPR]->val_int(); - + et->ends_null= table->field[EVEX_FIELD_ENDS]->is_null(); + res2= table->field[EVEX_FIELD_ENDS]->get_date(&et->ends, TIME_NO_ZERO_DATE); + + if (!table->field[EVEX_FIELD_INTERVAL_EXPR]->is_null()) + et->expression= table->field[EVEX_FIELD_INTERVAL_EXPR]->val_int(); + else + et->expression= 0; /* If res1 and res2 are true then both fields are empty. Hence if EVEX_FIELD_EXECUTE_AT is empty there is an error. */ - if (res1 && res2 && !et->expression && table->field[EVEX_FIELD_EXECUTE_AT]-> - get_date(&et->execute_at, TIME_NO_ZERO_DATE)) + et->execute_at_null= table->field[EVEX_FIELD_EXECUTE_AT]->is_null(); + DBUG_ASSERT(!(et->starts_null && et->ends_null && !et->expression && + et->execute_at_null)); + if (!et->expression && + table->field[EVEX_FIELD_EXECUTE_AT]->get_date(&et->execute_at, + TIME_NO_ZERO_DATE)) goto error; /* In DB the values start from 1 but enum interval_type starts from 0 */ - et->interval= (interval_type) + if (!table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->is_null()) + et->interval= (interval_type) ((ulonglong) table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->val_int() - 1); + else + et->interval= (interval_type) 0; - et->modified= table->field[EVEX_FIELD_CREATED]->val_int(); - et->created= table->field[EVEX_FIELD_MODIFIED]->val_int(); + et->created= table->field[EVEX_FIELD_CREATED]->val_int(); + et->modified= table->field[EVEX_FIELD_MODIFIED]->val_int(); /* ToDo Andrey : Ask PeterG & Serg what to do in this case. @@ -565,20 +591,20 @@ event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) #endif last_executed_changed= false; - // ToDo : Andrey . Find a way not to allocate ptr on event_mem_root + /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ if ((ptr= get_field(mem_root, table->field[EVEX_FIELD_STATUS])) == NullS) goto error; DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", et->name.str, ptr)); et->status= (ptr[0]=='E'? MYSQL_EVENT_ENABLED:MYSQL_EVENT_DISABLED); - // ToDo : Andrey . Find a way not to allocate ptr on event_mem_root + /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ if ((ptr= get_field(mem_root, table->field[EVEX_FIELD_ON_COMPLETION])) == NullS) goto error; et->on_completion= (ptr[0]=='D'? MYSQL_EVENT_ON_COMPLETION_DROP: - MYSQL_EVENT_ON_COMPLETION_PRESERVE); + MYSQL_EVENT_ON_COMPLETION_PRESERVE); et->comment.str= get_field(mem_root, table->field[EVEX_FIELD_COMMENT]); if (et->comment.str != NullS) @@ -667,7 +693,7 @@ bool get_next_time(TIME *next, TIME *start, int i_value, interval_type i_type) Computes next execution time. SYNOPSIS - event_timed::compute_next_execution_time() + Event_timed::compute_next_execution_time() NOTES The time is set in execute_at, if no more executions the latter is set to @@ -675,13 +701,13 @@ bool get_next_time(TIME *next, TIME *start, int i_value, interval_type i_type) */ bool -event_timed::compute_next_execution_time() +Event_timed::compute_next_execution_time() { TIME time_now; my_time_t now; int tmp; - DBUG_ENTER("event_timed::compute_next_execution_time"); + DBUG_ENTER("Event_timed::compute_next_execution_time"); if (status == MYSQL_EVENT_DISABLED) { @@ -695,14 +721,11 @@ event_timed::compute_next_execution_time() /* Let's check whether it was executed */ if (last_executed.year) { - DBUG_PRINT("compute_next_execution_time", - ("One-time event %s was already executed", name.str)); - if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) - { - DBUG_PRINT("compute_next_execution_time", - ("One-time event will be dropped.")); - dropped= true; - } + DBUG_PRINT("info",("One-time event %s.%s of was already executed", + dbname.str, name.str, definer.str)); + dropped= (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP); + DBUG_PRINT("info",("One-time event will be dropped=%d.", dropped)); + status= MYSQL_EVENT_DISABLED; status_changed= true; } @@ -728,11 +751,12 @@ event_timed::compute_next_execution_time() last_executed.second); #endif - /* If time_now is after ends don't execute anymore */ - if (ends.year && (tmp= my_time_compare(&ends, &time_now)) == -1) + /* if time_now is after ends don't execute anymore */ + if (!ends_null && (tmp= my_time_compare(&ends, &time_now)) == -1) { /* time_now is after ends. don't execute anymore */ set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); + execute_at_null= TRUE; if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) dropped= true; status= MYSQL_EVENT_DISABLED; @@ -746,7 +770,7 @@ event_timed::compute_next_execution_time() Let's check whether time_now is before starts. If so schedule for starts. */ - if (starts.year && (tmp= my_time_compare(&time_now, &starts)) < 1) + if (!starts_null && (tmp= my_time_compare(&time_now, &starts)) < 1) { if (tmp == 0 && my_time_compare(&starts, &last_executed) == 0) { @@ -762,11 +786,12 @@ event_timed::compute_next_execution_time() time_now before starts. Scheduling for starts */ execute_at= starts; + execute_at_null= FALSE; goto ret; } } - if (starts.year && ends.year) + if (!starts_null && !ends_null) { /* Both starts and m_ends are set and time_now is between them (incl.) @@ -775,7 +800,10 @@ event_timed::compute_next_execution_time() If not set then schedule for now. */ if (!last_executed.year) + { execute_at= time_now; + execute_at_null= FALSE; + } else { TIME next_exec; @@ -788,15 +816,19 @@ event_timed::compute_next_execution_time() { /* Next execution after ends. No more executions */ set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); + execute_at_null= TRUE; if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) dropped= true; } else + { execute_at= next_exec; + execute_at_null= FALSE; + } } goto ret; } - else if (!starts.year && !ends.year) + else if (starts_null && ends_null) { /* Both starts and m_ends are not set, so we schedule for the next @@ -812,11 +844,12 @@ event_timed::compute_next_execution_time() /* last_executed not set. Schedule the event for now */ execute_at= time_now; } + execute_at_null= FALSE; } else { - /* Either starts or m_ends is set */ - if (starts.year) + /* either starts or m_ends is set */ + if (!starts_null) { /* - starts is set. @@ -831,6 +864,7 @@ event_timed::compute_next_execution_time() } else execute_at= starts; + execute_at_null= FALSE; } else { @@ -853,11 +887,15 @@ event_timed::compute_next_execution_time() if (my_time_compare(&ends, &next_exec) == -1) { set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME); + execute_at_null= TRUE; if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP) dropped= true; } else + { execute_at= next_exec; + execute_at_null= FALSE; + } } } goto ret; @@ -875,19 +913,19 @@ err: time according to thd->query_start(), so the THD's clock. SYNOPSIS - event_timed::drop() + Event_timed::drop() thd thread context */ void -event_timed::mark_last_executed(THD *thd) +Event_timed::mark_last_executed(THD *thd) { TIME time_now; thd->end_time(); my_tz_UTC->gmt_sec_to_TIME(&time_now, (my_time_t) thd->query_start()); - last_executed= time_now; // was execute_at + last_executed= time_now; /* was execute_at */ #ifdef ANDREY_0 last_executed= execute_at; #endif @@ -899,7 +937,7 @@ event_timed::mark_last_executed(THD *thd) Drops the event SYNOPSIS - event_timed::drop() + Event_timed::drop() thd thread context RETURN VALUE @@ -912,11 +950,10 @@ event_timed::mark_last_executed(THD *thd) */ int -event_timed::drop(THD *thd) +Event_timed::drop(THD *thd) { - TABLE *table; uint tmp= 0; - DBUG_ENTER("event_timed::drop"); + DBUG_ENTER("Event_timed::drop"); DBUG_RETURN(db_drop_event(thd, this, false, &tmp)); } @@ -926,7 +963,7 @@ event_timed::drop(THD *thd) Saves status and last_executed_at to the disk if changed. SYNOPSIS - event_timed::update_fields() + Event_timed::update_fields() thd - thread context RETURN VALUE @@ -939,14 +976,13 @@ event_timed::drop(THD *thd) */ bool -event_timed::update_fields(THD *thd) +Event_timed::update_fields(THD *thd) { TABLE *table; Open_tables_state backup; int ret= 0; - bool opened; - DBUG_ENTER("event_timed::update_time_fields"); + DBUG_ENTER("Event_timed::update_time_fields"); DBUG_PRINT("enter", ("name: %*s", name.length, name.str)); @@ -980,7 +1016,7 @@ event_timed::update_fields(THD *thd) if (status_changed) { table->field[EVEX_FIELD_STATUS]->set_notnull(); - table->field[EVEX_FIELD_STATUS]->store((longlong)status); + table->field[EVEX_FIELD_STATUS]->store((longlong)status, true); status_changed= false; } @@ -1000,18 +1036,19 @@ extern LEX_STRING interval_type_to_name[]; Get SHOW CREATE EVENT as string SYNOPSIS - event_timed::get_create_event(THD *thd, String *buf) + Event_timed::get_create_event(THD *thd, String *buf) thd Thread buf String*, should be already allocated. CREATE EVENT goes inside. RETURN VALUE - 0 OK - 1 Error (for now if mysql.event has been tampered and MICROSECONDS - interval or derivative has been put there. + 0 OK + EVEX_MICROSECOND_UNSUP Error (for now if mysql.event has been + tampered and MICROSECONDS interval or + derivative has been put there. */ int -event_timed::get_create_event(THD *thd, String *buf) +Event_timed::get_create_event(THD *thd, String *buf) { int multipl= 0; char tmp_buff[128]; @@ -1023,7 +1060,7 @@ event_timed::get_create_event(THD *thd, String *buf) if (expression && event_reconstruct_interval_expression(&expr_buf, interval, expression)) - DBUG_RETURN(1); + DBUG_RETURN(EVEX_MICROSECOND_UNSUP); buf->append(STRING_WITH_LEN("CREATE EVENT ")); append_identifier(thd, buf, dbname.str, dbname.length); @@ -1041,7 +1078,7 @@ event_timed::get_create_event(THD *thd, String *buf) } else { - char dtime_buff[20*2+32];// +32 to make my_snprintf_{8bit|ucs2} happy + char dtime_buff[20*2+32];/* +32 to make my_snprintf_{8bit|ucs2} happy */ buf->append(STRING_WITH_LEN("AT '")); /* Pass the buffer and the second param tells fills the buffer and @@ -1089,14 +1126,14 @@ event_timed::get_create_event(THD *thd, String *buf) */ int -event_timed::execute(THD *thd, MEM_ROOT *mem_root) +Event_timed::execute(THD *thd, MEM_ROOT *mem_root) { Security_context *save_ctx; /* this one is local and not needed after exec */ Security_context security_ctx; int ret= 0; - DBUG_ENTER("event_timed::execute"); + DBUG_ENTER("Event_timed::execute"); DBUG_PRINT("info", (" EVEX EXECUTING event %s.%s [EXPR:%d]", dbname.str, name.str, (int) expression)); @@ -1119,12 +1156,21 @@ event_timed::execute(THD *thd, MEM_ROOT *mem_root) goto done; /* Now we are sure we have valid this->sphead so we can copy the context */ sphead->m_security_ctx= security_ctx; - thd->db= dbname.str; + /* + THD::~THD will clean this or if there is DROP DATABASE in the SP then + it will be free there. It should not point to our buffer which is allocated + on a mem_root. + */ + thd->db= my_strdup(dbname.str, MYF(0)); thd->db_length= dbname.length; if (!check_access(thd, EVENT_ACL,dbname.str, 0, 0, 0,is_schema_db(dbname.str))) { List<Item> empty_item_list; empty_item_list.empty(); + if (thd->enable_slow_log) + sphead->m_flags|= sp_head::LOG_SLOW_STATEMENTS; + sphead->m_flags|= sp_head::LOG_GENERAL_LOG; + ret= sphead->execute_procedure(thd, &empty_item_list); } else @@ -1136,7 +1182,6 @@ event_timed::execute(THD *thd, MEM_ROOT *mem_root) restore_security_context(thd, save_ctx); DBUG_PRINT("info", ("master_access=%d db_access=%d", thd->security_ctx->master_access, thd->security_ctx->db_access)); - thd->db= 0; VOID(pthread_mutex_lock(&this->LOCK_running)); running= false; @@ -1163,7 +1208,7 @@ done: /* Switches the security context Synopsis - event_timed::change_security_context() + Event_timed::change_security_context() thd - thread backup - where to store the old context @@ -1172,10 +1217,10 @@ done: 1 - Error (generates error too) */ bool -event_timed::change_security_context(THD *thd, Security_context *s_ctx, +Event_timed::change_security_context(THD *thd, Security_context *s_ctx, Security_context **backup) { - DBUG_ENTER("event_timed::change_security_context"); + DBUG_ENTER("Event_timed::change_security_context"); DBUG_PRINT("info",("%s@%s@%s",definer_user.str,definer_host.str, dbname.str)); #ifndef NO_EMBEDDED_ACCESS_CHECKS s_ctx->init(); @@ -1196,15 +1241,15 @@ event_timed::change_security_context(THD *thd, Security_context *s_ctx, /* Restores the security context Synopsis - event_timed::restore_security_context() + Event_timed::restore_security_context() thd - thread backup - switch to this context - */ +*/ void -event_timed::restore_security_context(THD *thd, Security_context *backup) +Event_timed::restore_security_context(THD *thd, Security_context *backup) { - DBUG_ENTER("event_timed::change_security_context"); + DBUG_ENTER("Event_timed::restore_security_context"); #ifndef NO_EMBEDDED_ACCESS_CHECKS if (backup) thd->security_ctx= backup; @@ -1218,29 +1263,27 @@ event_timed::restore_security_context(THD *thd, Security_context *backup) sp_head object held by the event SYNOPSIS - event_timed::compile() + Event_timed::compile() thd thread context, used for memory allocation mostly mem_root if != NULL then this memory root is used for allocs instead of thd->mem_root RETURN VALUE - 0 success - EVEX_COMPILE_ERROR error during compilation + 0 success + EVEX_COMPILE_ERROR error during compilation + EVEX_MICROSECOND_UNSUP mysql.event was tampered */ int -event_timed::compile(THD *thd, MEM_ROOT *mem_root) +Event_timed::compile(THD *thd, MEM_ROOT *mem_root) { int ret= 0; MEM_ROOT *tmp_mem_root= 0; LEX *old_lex= thd->lex, lex; char *old_db; int old_db_length; - event_timed *ett; - sp_name *spn; char *old_query; uint old_query_len; - st_sp_chistics *p; ulong old_sql_mode= thd->variables.sql_mode; char create_buf[2048]; String show_create(create_buf, sizeof(create_buf), system_charset_info); @@ -1248,7 +1291,20 @@ event_timed::compile(THD *thd, MEM_ROOT *mem_root) *old_collation_connection, *old_character_set_results; + DBUG_ENTER("Event_timed::compile"); + show_create.length(0); + + switch (get_create_event(thd, &show_create)) { + case EVEX_MICROSECOND_UNSUP: + sql_print_error("Scheduler"); + DBUG_RETURN(EVEX_MICROSECOND_UNSUP); + case 0: + break; + default: + DBUG_ASSERT(0); + } + old_character_set_client= thd->variables.character_set_client; old_character_set_results= thd->variables.character_set_results; old_collation_connection= thd->variables.collation_connection; @@ -1260,7 +1316,6 @@ event_timed::compile(THD *thd, MEM_ROOT *mem_root) thd->update_charset(); - DBUG_ENTER("event_timed::compile"); DBUG_PRINT("info",("old_sql_mode=%d new_sql_mode=%d",old_sql_mode, sql_mode)); thd->variables.sql_mode= this->sql_mode; /* Change the memory root for the execution time */ @@ -1276,11 +1331,9 @@ event_timed::compile(THD *thd, MEM_ROOT *mem_root) thd->db= dbname.str; thd->db_length= dbname.length; - get_create_event(thd, &show_create); - thd->query= show_create.c_ptr(); thd->query_length= show_create.length(); - DBUG_PRINT("event_timed::compile", ("query:%s",thd->query)); + DBUG_PRINT("Event_timed::compile", ("query:%s",thd->query)); thd->lex= &lex; lex_start(thd, (uchar*)thd->query, thd->query_length); @@ -1309,10 +1362,7 @@ event_timed::compile(THD *thd, MEM_ROOT *mem_root) sphead= lex.et->sphead; sphead->m_db= dbname; - /* - Ccopy also chistics since they will vanish otherwise we get 0x0 pointer - TODO: Handle sql_mode!! - */ + sphead->set_definer(definer.str, definer.length); sphead->set_info(0, 0, &lex.sp_chistics, sql_mode); sphead->optimize(); @@ -1355,7 +1405,7 @@ done: */ my_bool -event_timed::can_spawn_now_n_lock(THD *thd) +Event_timed::can_spawn_now_n_lock(THD *thd) { my_bool ret= FALSE; VOID(pthread_mutex_lock(&this->LOCK_running)); @@ -1374,7 +1424,7 @@ extern pthread_attr_t connection_attrib; /* Checks whether is possible and forks a thread. Passes self as argument. - + Returns EVENT_EXEC_STARTED - OK EVENT_EXEC_ALREADY_EXEC - Thread not forked, already working @@ -1382,11 +1432,11 @@ extern pthread_attr_t connection_attrib; */ int -event_timed::spawn_now(void * (*thread_func)(void*)) +Event_timed::spawn_now(void * (*thread_func)(void*)) { int ret= EVENT_EXEC_STARTED; static uint exec_num= 0; - DBUG_ENTER("event_timed::spawn_now"); + DBUG_ENTER("Event_timed::spawn_now"); DBUG_PRINT("info", ("[%s.%s]", dbname.str, name.str)); VOID(pthread_mutex_lock(&this->LOCK_running)); @@ -1420,9 +1470,9 @@ event_timed::spawn_now(void * (*thread_func)(void*)) void -event_timed::spawn_thread_finish(THD *thd) +Event_timed::spawn_thread_finish(THD *thd) { - DBUG_ENTER("event_timed::spawn_thread_finish"); + DBUG_ENTER("Event_timed::spawn_thread_finish"); VOID(pthread_mutex_lock(&this->LOCK_running)); in_spawned_thread= false; if ((flags & EVENT_EXEC_NO_MORE) || status == MYSQL_EVENT_DISABLED) @@ -1445,12 +1495,10 @@ event_timed::spawn_thread_finish(THD *thd) Returns 0 - ok 1 - not locked by this thread - */ - int -event_timed::spawn_unlock(THD *thd) +Event_timed::spawn_unlock(THD *thd) { int ret= 0; VOID(pthread_mutex_lock(&this->LOCK_running)); @@ -1471,5 +1519,5 @@ event_timed::spawn_unlock(THD *thd) } } VOID(pthread_mutex_unlock(&this->LOCK_running)); - return ret; + return ret; } diff --git a/sql/field.cc b/sql/field.cc index 72e28cbda9c..65c0d1b9397 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5266,7 +5266,7 @@ int Field_date::store(longlong nr, bool unsigned_val) } if (nr >= 19000000000000.0 && nr <= 99991231235959.0) - nr=floor(nr/1000000.0); // Timestamp to date + nr= (longlong) floor(nr/1000000.0); // Timestamp to date if (error) set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, @@ -8297,13 +8297,11 @@ void Field_bit_as_char::sql_type(String &res) const create_field::create_length_to_internal_length() DESCRIPTION - Convert create_field::length from number of characters to number of bytes, - save original value in chars_length. + Convert create_field::length from number of characters to number of bytes. */ void create_field::create_length_to_internal_length(void) { - chars_length= length; switch (sql_type) { case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: @@ -8355,7 +8353,7 @@ void create_field::init_for_tmp_table(enum_field_types sql_type_arg, { field_name= ""; sql_type= sql_type_arg; - length= length_arg;; + char_length= length= length_arg;; unireg_check= Field::NONE; interval= 0; charset= &my_charset_bin; @@ -8683,6 +8681,8 @@ bool create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, case FIELD_TYPE_DECIMAL: DBUG_ASSERT(0); /* Was obsolete */ } + /* Remember the value of length */ + char_length= length; if (!(flags & BLOB_FLAG) && ((length > max_field_charlength && fld_type != FIELD_TYPE_SET && @@ -9023,6 +9023,7 @@ create_field::create_field(Field *old_field,Field *orig_field) else interval=0; def=0; + char_length= length; if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) && old_field->ptr && orig_field && diff --git a/sql/field.h b/sql/field.h index 15c54f65ef7..3fbdc0d0aa9 100644 --- a/sql/field.h +++ b/sql/field.h @@ -173,8 +173,9 @@ public: virtual int cmp(const char *,const char *)=0; virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L) { return memcmp(a,b,pack_length()); } - int cmp_offset(uint row_offset) { return cmp(ptr,ptr+row_offset); } - int cmp_binary_offset(uint row_offset) + virtual int cmp_offset(uint row_offset) + { return cmp(ptr,ptr+row_offset); } + virtual int cmp_binary_offset(uint row_offset) { return cmp_binary(ptr, ptr+row_offset); }; virtual int key_cmp(const byte *a,const byte *b) { return cmp((char*) a,(char*) b); } @@ -1317,6 +1318,20 @@ public: }; +/* + Note: + To use Field_bit::cmp_binary() you need to copy the bits stored in + the beginning of the record (the NULL bytes) to each memory you + want to compare (where the arguments point). + + This is the reason: + - Field_bit::cmp_binary() is only implemented in the base class + (Field::cmp_binary()). + - Field::cmp_binary() currenly use pack_length() to calculate how + long the data is. + - pack_length() includes size of the bits stored in the NULL bytes + of the record. +*/ class Field_bit :public Field { public: uchar *bit_ptr; // position in record where 'uneven' bits store @@ -1342,6 +1357,8 @@ public: my_decimal *val_decimal(my_decimal *); int cmp(const char *a, const char *b) { return cmp_binary(a, b); } + int cmp_binary_offset(uint row_offset) + { return cmp_offset(row_offset); } int cmp_max(const char *a, const char *b, uint max_length); int key_cmp(const byte *a, const byte *b) { return cmp_binary((char *) a, (char *) b); } @@ -1410,9 +1427,10 @@ public: */ ulong length; /* - The value of 'length' before a call to create_length_to_internal_length + The value of `length' as set by parser: is the number of characters + for most of the types, or of bytes for BLOBs or numeric types. */ - uint32 chars_length; + uint32 char_length; uint decimals, flags, pack_length, key_length; Field::utype unireg_check; TYPELIB *interval; // Which interval to use diff --git a/sql/field_conv.cc b/sql/field_conv.cc index d46a3aa8be3..0c385efd10b 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -378,6 +378,16 @@ static void do_cut_string_complex(Copy_field *copy) +static void do_expand_binary(Copy_field *copy) +{ + CHARSET_INFO *cs= copy->from_field->charset(); + memcpy(copy->to_ptr,copy->from_ptr,copy->from_length); + cs->cset->fill(cs, copy->to_ptr+copy->from_length, + copy->to_length-copy->from_length, '\0'); +} + + + static void do_expand_string(Copy_field *copy) { CHARSET_INFO *cs= copy->from_field->charset(); @@ -582,7 +592,13 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) return (from->charset()->mbmaxlen == 1 ? do_cut_string : do_cut_string_complex); else if (to_length > from_length) - return do_expand_string; + { + if ((to->flags & BINARY_FLAG) != 0) + return do_expand_binary; + else + return do_expand_string; + } + } else if (to->real_type() != from->real_type() || to_length != from_length || diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc index 8ed16949edd..a8bc0822a85 100644 --- a/sql/ha_archive.cc +++ b/sql/ha_archive.cc @@ -177,9 +177,10 @@ handlerton archive_hton = { NULL, /* Partition flags */ NULL, /* Alter table flags */ NULL, /* Alter interface */ + NULL, /* fill_files_table */ HTON_NO_FLAGS, - NULL, /* binlog_func */ - NULL /* binlog_log_query */ + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; static handler *archive_create_handler(TABLE_SHARE *table) diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 6866b50fd19..910a703fdeb 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -153,7 +153,9 @@ handlerton berkeley_hton = { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill Files Table */ - HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME + HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; handler *berkeley_create_handler(TABLE_SHARE *table) diff --git a/sql/ha_blackhole.cc b/sql/ha_blackhole.cc index 42c785e2003..7d28344a0a4 100644 --- a/sql/ha_blackhole.cc +++ b/sql/ha_blackhole.cc @@ -61,7 +61,9 @@ handlerton blackhole_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill FILES table */ - HTON_CAN_RECREATE + HTON_CAN_RECREATE, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index f7e0c1242fe..976f3739386 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -398,7 +398,9 @@ handlerton federated_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill FILES table */ - HTON_ALTER_NOT_SUPPORTED + HTON_ALTER_NOT_SUPPORTED, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index d4790cf7d01..96f760a7a44 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -58,7 +58,9 @@ handlerton heap_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill Files Table */ - HTON_CAN_RECREATE + HTON_CAN_RECREATE, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; static handler *heap_create_handler(TABLE_SHARE *table) diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 0002ab0123f..153c456c06c 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -237,8 +237,11 @@ handlerton innobase_hton = { innobase_show_status, /* Show status */ NULL, /* Partition flags */ NULL, /* Alter table flags */ + NULL, /* alter_tablespace */ NULL, /* Fill FILES table */ - HTON_NO_FLAGS + HTON_NO_FLAGS, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 4b84d3efa7f..fba36450d81 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -90,7 +90,9 @@ handlerton myisam_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill Files Table */ - HTON_CAN_RECREATE + HTON_CAN_RECREATE, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 32b67cd23e5..ec015c5e320 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -68,7 +68,9 @@ handlerton myisammrg_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill Files Table */ - HTON_CAN_RECREATE + HTON_CAN_RECREATE, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; static handler *myisammrg_create_handler(TABLE_SHARE *table) @@ -306,7 +308,27 @@ void ha_myisammrg::info(uint flag) table->s->keys_in_use.set_prefix(table->s->keys); table->s->db_options_in_use= info.options; mean_rec_length= info.reclength; - block_size=0; + + /* + The handler::block_size is used all over the code in index scan cost + calculations. It is used to get number of disk seeks required to + retrieve a number of index tuples. + If the merge table has N underlying tables, then (assuming underlying + tables have equal size, the only "simple" approach we can use) + retrieving X index records from a merge table will require N times more + disk seeks compared to doing the same on a MyISAM table with equal + number of records. + In the edge case (file_tables > myisam_block_size) we'll get + block_size==0, and index calculation code will act as if we need one + disk seek to retrieve one index tuple. + + TODO: In 5.2 index scan cost calculation will be factored out into a + virtual function in class handler and we'll be able to remove this hack. + */ + block_size= 0; + if (file->tables) + block_size= myisam_block_size / file->tables; + update_time=0; #if SIZEOF_OFF_T > 4 ref_length=6; // Should be big enough diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 642199890e6..ff8a1221052 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -519,6 +519,7 @@ void ha_ndbcluster::invalidate_dictionary_cache(bool global) { NDBINDEX *index = (NDBINDEX *) m_index[i].index; NDBINDEX *unique_index = (NDBINDEX *) m_index[i].unique_index; + if (!index && !unique_index) continue; NDB_INDEX_TYPE idx_type= m_index[i].type; switch (idx_type) { @@ -991,8 +992,8 @@ bool ha_ndbcluster::uses_blob_value() -2 Meta data has changed; Re-read data and try again */ -static int cmp_frm(const NDBTAB *ndbtab, const void *pack_data, - uint pack_length) +int cmp_frm(const NDBTAB *ndbtab, const void *pack_data, + uint pack_length) { DBUG_ENTER("cmp_frm"); /* @@ -1076,7 +1077,7 @@ int ha_ndbcluster::get_metadata(const char *path) m_table= (void *)tab; m_table_info= NULL; // Set in external lock - DBUG_RETURN(open_indexes(ndb, table)); + DBUG_RETURN(open_indexes(ndb, table, FALSE)); } static int fix_unique_index_attr_order(NDB_INDEX_DATA &data, @@ -1249,7 +1250,7 @@ int ha_ndbcluster::add_index_handle(THD *thd, NDBDICT *dict, KEY *key_info, /* Associate index handles for each index of a table */ -int ha_ndbcluster::open_indexes(Ndb *ndb, TABLE *tab) +int ha_ndbcluster::open_indexes(Ndb *ndb, TABLE *tab, bool ignore_error) { uint i; int error= 0; @@ -1263,7 +1264,10 @@ int ha_ndbcluster::open_indexes(Ndb *ndb, TABLE *tab) for (i= 0; i < tab->s->keys; i++, key_info++, key_name++) { if ((error= add_index_handle(thd, dict, key_info, *key_name, i))) - break; + if (ignore_error) + m_index[i].index= m_index[i].unique_index= NULL; + else + break; } DBUG_RETURN(error); @@ -1680,15 +1684,16 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf, /* Read one complementing record from NDB using primary key from old_data + or hidden key */ -int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data, - uint32 old_part_id) +int ha_ndbcluster::complemented_read(const byte *old_data, byte *new_data, + uint32 old_part_id) { uint no_fields= table_share->fields, i; NdbTransaction *trans= m_active_trans; NdbOperation *op; - DBUG_ENTER("complemented_pk_read"); + DBUG_ENTER("complemented_read"); m_write_op= FALSE; if (ha_get_all_bit_in_read_set()) @@ -1702,9 +1707,17 @@ int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data, if (!(op= trans->getNdbOperation((const NDBTAB *) m_table)) || op->readTuple(lm) != 0) ERR_RETURN(trans->getNdbError()); - int res; - if ((res= set_primary_key_from_record(op, old_data))) - ERR_RETURN(trans->getNdbError()); + if (table_share->primary_key != MAX_KEY) + { + if (set_primary_key_from_record(op, old_data)) + ERR_RETURN(trans->getNdbError()); + } + else + { + // This table has no primary key, use "hidden" primary key + if (set_hidden_key(op, table->s->fields, m_ref)) + ERR_RETURN(op->getNdbError()); + } if (m_use_partition_function) op->setPartitionId(old_part_id); @@ -2214,7 +2227,7 @@ int ha_ndbcluster::full_table_scan(byte *buf) if (m_use_partition_function) { part_spec.start_part= 0; - part_spec.end_part= get_tot_partitions(m_part_info) - 1; + part_spec.end_part= m_part_info->get_tot_partitions() - 1; prune_partition_set(table, &part_spec); DBUG_PRINT("info", ("part_spec.start_part = %u, part_spec.end_part = %u", part_spec.start_part, part_spec.end_part)); @@ -2497,19 +2510,23 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) DBUG_RETURN(error); } - /* Check for update of primary key for special handling */ - if ((table_share->primary_key != MAX_KEY) && - (key_cmp(table_share->primary_key, old_data, new_data)) || + /* + * Check for update of primary key or partition change + * for special handling + */ + if (((table_share->primary_key != MAX_KEY) && + key_cmp(table_share->primary_key, old_data, new_data)) || (old_part_id != new_part_id)) { int read_res, insert_res, delete_res, undo_res; - DBUG_PRINT("info", ("primary key update, doing pk read+delete+insert")); + DBUG_PRINT("info", ("primary key update or partition change, " + "doing read+delete+insert")); // Get all old fields, since we optimize away fields not in query - read_res= complemented_pk_read(old_data, new_data, old_part_id); + read_res= complemented_read(old_data, new_data, old_part_id); if (read_res) { - DBUG_PRINT("info", ("pk read failed")); + DBUG_PRINT("info", ("read failed")); DBUG_RETURN(read_res); } // Delete old row @@ -3377,8 +3394,13 @@ int ha_ndbcluster::extra(enum ha_extra_function operation) DBUG_PRINT("info", ("HA_EXTRA_RESET")); DBUG_PRINT("info", ("Clearing condition stack")); cond_clear(); + /* + * Regular partition pruning will set the bitmap appropriately. + * Some queries like ALTER TABLE doesn't use partition pruning and + * thus the 'used_partitions' bitmap needs to be initialized + */ if (m_part_info) - bitmap_clear_all(&m_part_info->used_partitions); + bitmap_set_all(&m_part_info->used_partitions); break; case HA_EXTRA_IGNORE_DUP_KEY: /* Dup keys don't rollback everything*/ DBUG_PRINT("info", ("HA_EXTRA_IGNORE_DUP_KEY")); @@ -3739,7 +3761,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) { m_table= (void *)tab; m_table_version = tab->getObjectVersion(); - if (!(my_errno= open_indexes(ndb, table))) + if (!(my_errno= open_indexes(ndb, table, FALSE))) DBUG_RETURN(my_errno); } m_table_info= tab_info; @@ -4706,13 +4728,14 @@ int ha_ndbcluster::final_drop_index(TABLE *table_arg) int ha_ndbcluster::rename_table(const char *from, const char *to) { NDBDICT *dict; + char old_dbname[FN_HEADLEN]; char new_tabname[FN_HEADLEN]; const NDBTAB *orig_tab; int result; DBUG_ENTER("ha_ndbcluster::rename_table"); DBUG_PRINT("info", ("Renaming %s to %s", from, to)); - set_dbname(from); + set_dbname(from, old_dbname); set_tabname(from); set_tabname(to, new_tabname); @@ -4720,6 +4743,7 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) DBUG_RETURN(my_errno= HA_ERR_NO_CONNECTION); Ndb *ndb= get_ndb(); + ndb->setDatabaseName(old_dbname); dict= ndb->getDictionary(); if (!(orig_tab= dict->getTable(m_tabname))) ERR_RETURN(dict->getNdbError()); @@ -4811,7 +4835,8 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) current_thd->query, current_thd->query_length, m_dbname, new_tabname, 0, 0, - SOT_RENAME_TABLE); + SOT_RENAME_TABLE, + old_dbname, m_tabname); } if (share) free_share(&share); @@ -5191,7 +5216,7 @@ void ha_ndbcluster::set_part_info(partition_info *part_info) m_part_info= part_info; if (!(m_part_info->part_type == HASH_PARTITION && m_part_info->list_of_part_fields && - !is_sub_partitioned(m_part_info))) + !m_part_info->is_sub_partitioned())) m_use_partition_function= TRUE; } @@ -5984,8 +6009,11 @@ void ha_ndbcluster::print_error(int error, myf errflag) DBUG_PRINT("enter", ("error = %d", error)); if (error == HA_ERR_NO_PARTITION_FOUND) + { + char buf[100]; my_error(ER_NO_PARTITION_FOR_GIVEN_VALUE, MYF(0), - (int)m_part_info->part_expr->val_int()); + llstr(m_part_info->part_expr->val_int(), buf)); + } else handler::print_error(error, errflag); DBUG_VOID_RETURN; @@ -6696,6 +6724,7 @@ NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share) return share; } + /* Get a share object for key @@ -6710,17 +6739,19 @@ NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share) have_lock == TRUE, pthread_mutex_lock(&ndbcluster_mutex) already taken */ + NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, bool create_if_not_exists, bool have_lock) { - DBUG_ENTER("get_share"); - DBUG_PRINT("info", ("get_share: key %s", key)); THD *thd= current_thd; NDB_SHARE *share; + uint length= (uint) strlen(key); + DBUG_ENTER("ndbcluster_get_share"); + DBUG_PRINT("enter", ("key: '%s'", key)); + if (!have_lock) pthread_mutex_lock(&ndbcluster_mutex); - uint length= (uint) strlen(key); if (!(share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables, (byte*) key, length))) @@ -6780,10 +6811,10 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, dbug_print_open_tables(); - DBUG_PRINT("get_share", + DBUG_PRINT("info", ("0x%lx key: %s key_length: %d key: %s", share, share->key, share->key_length, key)); - DBUG_PRINT("get_share", + DBUG_PRINT("info", ("db.tablename: %s.%s use_count: %d commit_count: %d", share->db, share->table_name, share->use_count, share->commit_count)); @@ -6792,8 +6823,10 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, DBUG_RETURN(share); } + void ndbcluster_real_free_share(NDB_SHARE **share) { + DBUG_ENTER("ndbcluster_real_free_share"); DBUG_PRINT("real_free_share", ("0x%lx key: %s key_length: %d", (*share), (*share)->key, (*share)->key_length)); @@ -6831,6 +6864,7 @@ void ndbcluster_real_free_share(NDB_SHARE **share) *share= 0; dbug_print_open_tables(); + DBUG_VOID_RETURN; } /* @@ -7418,7 +7452,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) ndb_util_thread= pthread_self(); thd->thread_stack= (char*)&thd; /* remember where our stack is */ - if (thd->store_globals() && (ndb->init() != -1)) + if (thd->store_globals() || (ndb->init() != 0)) { thd->cleanup(); delete thd; @@ -9304,7 +9338,7 @@ uint ha_ndbcluster::set_up_partition_info(partition_info *part_info, { uint ng; part_elem= part_it++; - if (!is_sub_partitioned(part_info)) + if (!part_info->is_sub_partitioned()) { ng= part_elem->nodegroup_id; if (first && ng == UNDEF_NODEGROUP) diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 1eb8ac1ea70..7498d2bb624 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -691,6 +691,10 @@ static void set_tabname(const char *pathname, char *tabname); private: friend int ndbcluster_drop_database_impl(const char *path); + friend int ndb_handle_schema_change(THD *thd, + Ndb *ndb, NdbEventOperation *pOp, + NDB_SHARE *share); + int alter_table_name(const char *to); static int delete_table(ha_ndbcluster *h, Ndb *ndb, const char *path, @@ -708,7 +712,7 @@ private: int create_indexes(Ndb *ndb, TABLE *tab); void clear_index(int i); void clear_indexes(); - int open_indexes(Ndb *ndb, TABLE *tab); + int open_indexes(Ndb *ndb, TABLE *tab, bool ignore_error); void renumber_indexes(Ndb *ndb, TABLE *tab); int drop_indexes(Ndb *ndb, TABLE *tab); int add_index_handle(THD *thd, NdbDictionary::Dictionary *dict, @@ -727,8 +731,8 @@ private: char* get_tablespace_name(THD *thd); int set_range_data(void *tab, partition_info* part_info); int set_list_data(void *tab, partition_info* part_info); - int complemented_pk_read(const byte *old_data, byte *new_data, - uint32 old_part_id); + int complemented_read(const byte *old_data, byte *new_data, + uint32 old_part_id); int pk_read(const byte *key, uint key_len, byte *buf, uint32 part_id); int ordered_index_scan(const key_range *start_key, const key_range *end_key, diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index 28756c54c7f..f88c118b46e 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -184,8 +184,8 @@ static void dbug_print_table(const char *info, TABLE *table) Run a query through mysql_parse Used to: - - purging the cluster_replication.binlog_index - - creating the cluster_replication.apply_status table + - purging the binlog_index + - creating the apply_status table */ static void run_query(THD *thd, char *buf, char *end, my_bool print_error, my_bool disable_binlog) @@ -230,6 +230,70 @@ static void run_query(THD *thd, char *buf, char *end, } } +int +ndbcluster_binlog_open_table(THD *thd, NDB_SHARE *share, + TABLE_SHARE *table_share, TABLE *table) +{ + int error; + MEM_ROOT *mem_root= &share->mem_root; + DBUG_ENTER("ndbcluster_binlog_open_table"); + + init_tmp_table_share(table_share, share->db, 0, share->table_name, + share->key); + if ((error= open_table_def(thd, table_share, 0))) + { + sql_print_error("Unable to get table share for %s, error=%d", + share->key, error); + DBUG_PRINT("error", ("open_table_def failed %d", error)); + free_table_share(table_share); + my_free((gptr) table_share, MYF(0)); + my_free((gptr) table, MYF(0)); + DBUG_RETURN(error); + } + if ((error= open_table_from_share(thd, table_share, "", 0, + (uint) READ_ALL, 0, table, FALSE))) + { + sql_print_error("Unable to open table for %s, error=%d(%d)", + share->key, error, my_errno); + DBUG_PRINT("error", ("open_table_from_share failed %d", error)); + free_table_share(table_share); + my_free((gptr) table_share, MYF(0)); + my_free((gptr) table, MYF(0)); + DBUG_RETURN(error); + } + assign_new_table_id(table_share); + if (!table->record[1] || table->record[1] == table->record[0]) + { + table->record[1]= alloc_root(&table->mem_root, + table->s->rec_buff_length); + } + table->in_use= injector_thd; + + table->s->db.str= share->db; + table->s->db.length= strlen(share->db); + table->s->table_name.str= share->table_name; + table->s->table_name.length= strlen(share->table_name); + + share->table_share= table_share; + share->table= table; +#ifndef DBUG_OFF + dbug_print_table("table", table); +#endif + /* + ! do not touch the contents of the table + it may be in use by the injector thread + */ + share->ndb_value[0]= (NdbValue*) + alloc_root(mem_root, sizeof(NdbValue) * + (table->s->fields + 2 /*extra for hidden key and part key*/)); + share->ndb_value[1]= (NdbValue*) + alloc_root(mem_root, sizeof(NdbValue) * + (table->s->fields + 2 /*extra for hidden key and part key*/)); + + DBUG_RETURN(0); +} + + /* Initialize the binlog part of the NDB_SHARE */ @@ -238,6 +302,7 @@ void ndbcluster_binlog_init_share(NDB_SHARE *share, TABLE *_table) THD *thd= current_thd; MEM_ROOT *mem_root= &share->mem_root; int do_event_op= ndb_binlog_running; + DBUG_ENTER("ndbcluster_binlog_init_share"); share->op= 0; share->table= 0; @@ -276,74 +341,23 @@ void ndbcluster_binlog_init_share(NDB_SHARE *share, TABLE *_table) { share->flags|= NSF_NO_BINLOG; } - return; + DBUG_VOID_RETURN; } while (1) { + int error; TABLE_SHARE *table_share= (TABLE_SHARE *) my_malloc(sizeof(*table_share), MYF(MY_WME)); TABLE *table= (TABLE*) my_malloc(sizeof(*table), MYF(MY_WME)); - int error; - - init_tmp_table_share(table_share, share->db, 0, share->table_name, - share->key); - if ((error= open_table_def(thd, table_share, 0))) - { - sql_print_error("Unable to get table share for %s, error=%d", - share->key, error); - DBUG_PRINT("error", ("open_table_def failed %d", error)); - my_free((gptr) table_share, MYF(0)); - table_share= 0; - my_free((gptr) table, MYF(0)); - table= 0; + if ((error= ndbcluster_binlog_open_table(thd, share, table_share, table))) break; - } - if ((error= open_table_from_share(thd, table_share, "", 0, - (uint) READ_ALL, 0, table, FALSE))) - { - sql_print_error("Unable to open table for %s, error=%d(%d)", - share->key, error, my_errno); - DBUG_PRINT("error", ("open_table_from_share failed %d", error)); - my_free((gptr) table_share, MYF(0)); - table_share= 0; - my_free((gptr) table, MYF(0)); - table= 0; - break; - } - assign_new_table_id(table); - if (!table->record[1] || table->record[1] == table->record[0]) - { - table->record[1]= alloc_root(&table->mem_root, - table->s->rec_buff_length); - } - table->in_use= injector_thd; - - table->s->db.str= share->db; - table->s->db.length= strlen(share->db); - table->s->table_name.str= share->table_name; - table->s->table_name.length= strlen(share->table_name); - - share->table_share= table_share; - share->table= table; -#ifndef DBUG_OFF - dbug_print_table("table", table); -#endif - /* - ! do not touch the contents of the table - it may be in use by the injector thread - */ - share->ndb_value[0]= (NdbValue*) - alloc_root(mem_root, sizeof(NdbValue) * table->s->fields - + 1 /*extra for hidden key*/); - share->ndb_value[1]= (NdbValue*) - alloc_root(mem_root, sizeof(NdbValue) * table->s->fields - +1 /*extra for hidden key*/); if (table->s->primary_key == MAX_KEY) share->flags|= NSF_HIDDEN_PK; if (table->s->blob_fields != 0) share->flags|= NSF_BLOB_FLAG; break; } + DBUG_VOID_RETURN; } /***************************************************************** @@ -592,7 +606,7 @@ void ndbcluster_binlog_init_handlerton() /* - check the availability af the cluster_replication.apply_status share + check the availability af the apply_status share - return share, but do not increase refcount - return 0 if there is no share */ @@ -610,7 +624,7 @@ static NDB_SHARE *ndbcluster_check_apply_status_share() } /* - check the availability af the cluster_replication.schema share + check the availability af the schema share - return share, but do not increase refcount - return 0 if there is no share */ @@ -628,7 +642,7 @@ static NDB_SHARE *ndbcluster_check_schema_share() } /* - Create the cluster_replication.apply_status table + Create the apply_status table */ static int ndbcluster_create_apply_status_table(THD *thd) { @@ -677,7 +691,7 @@ static int ndbcluster_create_apply_status_table(THD *thd) /* - Create the cluster_replication.schema table + Create the schema table */ static int ndbcluster_create_schema_table(THD *thd) { @@ -871,7 +885,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, const char *db, const char *table_name, uint32 ndb_table_id, uint32 ndb_table_version, - enum SCHEMA_OP_TYPE type) + enum SCHEMA_OP_TYPE type, + const char *old_db, const char *old_table_name) { DBUG_ENTER("ndbcluster_log_schema_op"); Thd_ndb *thd_ndb= get_thd_ndb(thd); @@ -905,10 +920,19 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, query= tmp_buf2; query_length= (uint) (strxmov(tmp_buf2, "drop table `", table_name, "`", NullS) - tmp_buf2); - // fall through - case SOT_CREATE_TABLE: - // fall through + if (!share) + get_a_share= 1; + break; case SOT_RENAME_TABLE: + /* redo the rename table query as is may contain several tables */ + query= tmp_buf2; + query_length= (uint) (strxmov(tmp_buf2, "rename table `", + old_db, ".", old_table_name, "` to `", + db, ".", table_name, "`", NullS) - tmp_buf2); + if (!share) + get_a_share= 1; + break; + case SOT_CREATE_TABLE: // fall through case SOT_ALTER_TABLE: if (!share) @@ -969,8 +993,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, } Ndb *ndb= thd_ndb->ndb; - char old_db[FN_REFLEN]; - strcpy(old_db, ndb->getDatabaseName()); + char save_db[FN_REFLEN]; + strcpy(save_db, ndb->getDatabaseName()); char tmp_buf[SCHEMA_QUERY_SIZE]; NDBDICT *dict= ndb->getDictionary(); @@ -1077,7 +1101,7 @@ end: if (trans) ndb->closeTransaction(trans); - ndb->setDatabaseName(old_db); + ndb->setDatabaseName(save_db); /* Wait for other mysqld's to acknowledge the table operation @@ -1155,8 +1179,8 @@ ndbcluster_update_slock(THD *thd, const NdbError *ndb_error= 0; uint32 node_id= g_ndb_cluster_connection->node_id(); Ndb *ndb= check_ndb_in_thd(thd); - char old_db[128]; - strcpy(old_db, ndb->getDatabaseName()); + char save_db[FN_HEADLEN]; + strcpy(save_db, ndb->getDatabaseName()); char tmp_buf[SCHEMA_QUERY_SIZE]; NDBDICT *dict= ndb->getDictionary(); @@ -1278,31 +1302,98 @@ end: db, table_name); if (trans) ndb->closeTransaction(trans); - ndb->setDatabaseName(old_db); + ndb->setDatabaseName(save_db); DBUG_RETURN(0); } /* Handle _non_ data events from the storage nodes */ -static int +int ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, NDB_SHARE *share) { + DBUG_ENTER("ndb_handle_schema_change"); int remote_drop_table= 0, do_close_cached_tables= 0; + const char *dbname= share->table->s->db.str; + const char *tabname= share->table->s->table_name.str; + bool online_alter_table= (pOp->getEventType() == NDBEVENT::TE_ALTER && + pOp->tableFrmChanged()); if (pOp->getEventType() != NDBEVENT::TE_CLUSTER_FAILURE && - pOp->getReqNodeId() != g_ndb_cluster_connection->node_id()) + (uint) pOp->getReqNodeId() != g_ndb_cluster_connection->node_id()) { + TABLE_SHARE *table_share= share->table->s; + TABLE* table= share->table; + + /* + Invalidate table and all it's indexes + */ ndb->setDatabaseName(share->table->s->db.str); - ha_ndbcluster::invalidate_dictionary_cache(share->table->s, - ndb, - share->table->s->db.str, - share->table->s->table_name.str, - TRUE); + Thd_ndb *thd_ndb= get_thd_ndb(thd); + DBUG_ASSERT(thd_ndb != NULL); + Ndb* old_ndb= thd_ndb->ndb; + thd_ndb->ndb= ndb; + ha_ndbcluster table_handler(table_share); + table_handler.set_dbname(share->key); + table_handler.set_tabname(share->key); + table_handler.open_indexes(ndb, table, TRUE); + table_handler.invalidate_dictionary_cache(TRUE); + thd_ndb->ndb= old_ndb; + + if (online_alter_table) + { + char key[FN_REFLEN]; + const void *data= 0, *pack_data= 0; + uint length, pack_length; + int error; + NDBDICT *dict= ndb->getDictionary(); + const NDBTAB *altered_table= pOp->getTable(); + + DBUG_PRINT("info", ("Detected frm change of table %s.%s", + dbname, tabname)); + build_table_filename(key, FN_LEN-1, dbname, tabname, NullS); + /* + If the frm of the altered table is different than the one on + disk then overwrite it with the new table definition + */ + if (readfrm(key, &data, &length) == 0 && + packfrm(data, length, &pack_data, &pack_length) == 0 && + cmp_frm(altered_table, pack_data, pack_length)) + { + DBUG_DUMP("frm", (char*)altered_table->getFrmData(), + altered_table->getFrmLength()); + pthread_mutex_lock(&LOCK_open); + const NDBTAB *old= dict->getTable(tabname); + if (!old && + old->getObjectVersion() != altered_table->getObjectVersion()) + dict->putTable(altered_table); + + if ((error= unpackfrm(&data, &length, altered_table->getFrmData())) || + (error= writefrm(key, data, length))) + { + sql_print_information("NDB: Failed write frm for %s.%s, error %d", + dbname, tabname, error); + } + close_cached_tables((THD*) 0, 0, (TABLE_LIST*) 0, TRUE); + if ((error= ndbcluster_binlog_open_table(thd, share, + table_share, table))) + sql_print_information("NDB: Failed to re-open table %s.%s", + dbname, tabname); + pthread_mutex_unlock(&LOCK_open); + } + } remote_drop_table= 1; } + // If only frm was changed continue replicating + if (online_alter_table) + { + /* Signal ha_ndbcluster::alter_table that drop is done */ + (void) pthread_cond_signal(&injector_cond); + DBUG_RETURN(0); + } + (void) pthread_mutex_lock(&share->mutex); DBUG_ASSERT(share->op == pOp || share->op_old == pOp); if (share->op_old == pOp) @@ -1481,11 +1572,16 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, // skip break; case NDBEVENT::TE_ALTER: - /* do the rename of the table in the share */ - share->table->s->db.str= share->db; - share->table->s->db.length= strlen(share->db); - share->table->s->table_name.str= share->table_name; - share->table->s->table_name.length= strlen(share->table_name); + if (pOp->tableNameChanged()) + { + DBUG_PRINT("info", ("Detected name change of table %s.%s", + share->db, share->table_name)); + /* do the rename of the table in the share */ + share->table->s->db.str= share->db; + share->table->s->db.length= strlen(share->db); + share->table->s->table_name.str= share->table_name; + share->table->s->table_name.length= strlen(share->table_name); + } ndb_handle_schema_change(thd, ndb, pOp, share); break; case NDBEVENT::TE_CLUSTER_FAILURE: @@ -1569,13 +1665,13 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, /********************************************************************* Internal helper functions for handeling of the cluster replication tables - - cluster_replication.binlog_index - - cluster_replication.apply_status + - binlog_index + - apply_status *********************************************************************/ /* struct to hold the data to be inserted into the - cluster_replication.binlog_index table + binlog_index table */ struct Binlog_index_row { ulonglong gci; @@ -1588,7 +1684,7 @@ struct Binlog_index_row { }; /* - Open the cluster_replication.binlog_index table + Open the binlog_index table */ static int open_binlog_index(THD *thd, TABLE_LIST *tables, TABLE **binlog_index) @@ -1619,7 +1715,7 @@ static int open_binlog_index(THD *thd, TABLE_LIST *tables, } /* - Insert one row in the cluster_replication.binlog_index + Insert one row in the binlog_index declared friend in handler.h to be able to call write_row directly so that this insert is not replicated @@ -1641,7 +1737,8 @@ int ndb_add_binlog_index(THD *thd, void *_row) { if (need_reopen) { - close_tables_for_reopen(thd, &binlog_tables); + TABLE_LIST *p_binlog_tables= &binlog_tables; + close_tables_for_reopen(thd, &p_binlog_tables); binlog_index= 0; continue; } @@ -1766,6 +1863,7 @@ int ndbcluster_create_binlog_setup(Ndb *ndb, const char *key, /* Handle any trailing share */ NDB_SHARE *share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables, (byte*) key, key_len); + if (share && share_may_exist) { if (share->flags & NSF_NO_BINLOG || @@ -2091,7 +2189,6 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, op= ndb->createEventOperation(event_name); // reset to catch errors ndb->setDatabaseName(""); - ndb->setDatabaseSchemaName(""); } if (!op) { @@ -2372,17 +2469,22 @@ ndb_binlog_thread_handle_non_data_event(Ndb *ndb, NdbEventOperation *pOp, share->key, share, pOp, share->op, share->op_old)); break; case NDBEVENT::TE_ALTER: - /* ToDo: remove printout */ - if (ndb_extra_logging) - sql_print_information("NDB Binlog: rename table %s%s/%s -> %s.", - share_prefix, share->table->s->db.str, - share->table->s->table_name.str, - share->key); - /* do the rename of the table in the share */ - share->table->s->db.str= share->db; - share->table->s->db.length= strlen(share->db); - share->table->s->table_name.str= share->table_name; - share->table->s->table_name.length= strlen(share->table_name); + if (pOp->tableNameChanged()) + { + DBUG_PRINT("info", ("Detected name change of table %s.%s", + share->db, share->table_name)); + /* ToDo: remove printout */ + if (ndb_extra_logging) + sql_print_information("NDB Binlog: rename table %s%s/%s -> %s.", + share_prefix, share->table->s->db.str, + share->table->s->table_name.str, + share->key); + /* do the rename of the table in the share */ + share->table->s->db.str= share->db; + share->table->s->db.length= strlen(share->db); + share->table->s->table_name.str= share->table_name; + share->table->s->table_name.length= strlen(share->table_name); + } goto drop_alter_common; case NDBEVENT::TE_DROP: if (apply_status_share == share) @@ -2659,8 +2761,8 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) goto err; } - // empty database and schema - if (!(ndb= new Ndb(g_ndb_cluster_connection, "", "")) || + // empty database + if (!(ndb= new Ndb(g_ndb_cluster_connection, "")) || ndb->init()) { sql_print_error("NDB Binlog: Getting Ndb object failed"); @@ -2682,7 +2784,7 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) ndb_binlog_thread_running= 1; if (opt_bin_log) { - if (binlog_row_based) + if (global_system_variables.binlog_format == BINLOG_FORMAT_ROW) { ndb_binlog_running= TRUE; } @@ -2924,7 +3026,6 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) ndb_binlog_thread_handle_non_data_event(ndb, pOp, row); // reset to catch errors ndb->setDatabaseName(""); - ndb->setDatabaseSchemaName(""); } pOp= ndb->nextEvent(); diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h index d222a7d848b..91ef53edd6b 100644 --- a/sql/ha_ndbcluster_binlog.h +++ b/sql/ha_ndbcluster_binlog.h @@ -95,7 +95,9 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, const char *db, const char *table_name, uint32 ndb_table_id, uint32 ndb_table_version, - enum SCHEMA_OP_TYPE type); + enum SCHEMA_OP_TYPE type, + const char *old_db= 0, + const char *old_table_name= 0); int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, NDB_SHARE *share); void ndb_rep_event_name(String *event_name, @@ -123,6 +125,8 @@ ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print, prototypes for ndb handler utility function also needed by the ndb binlog code */ +int cmp_frm(const NDBTAB *ndbtab, const void *pack_data, + uint pack_length); int ndbcluster_find_all_files(THD *thd); #endif /* HAVE_NDB_BINLOG */ diff --git a/sql/ha_ndbcluster_tables.h b/sql/ha_ndbcluster_tables.h index d726fd63e1d..12124cd8820 100644 --- a/sql/ha_ndbcluster_tables.h +++ b/sql/ha_ndbcluster_tables.h @@ -15,7 +15,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define NDB_REP_DB "cluster_replication" +#define NDB_REP_DB "cluster" #define NDB_REP_TABLE "binlog_index" #define NDB_APPLY_TABLE "apply_status" #define NDB_SCHEMA_TABLE "schema" diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 5d4d1570044..e7a324481db 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -102,7 +102,9 @@ handlerton partition_hton = { alter_table_flags, /* Partition flags */ NULL, /* Alter Tablespace */ NULL, /* Fill FILES table */ - HTON_NOT_USER_SELECTABLE | HTON_HIDDEN + HTON_NOT_USER_SELECTABLE | HTON_HIDDEN, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; /* @@ -186,7 +188,7 @@ ha_partition::ha_partition(TABLE_SHARE *share) ha_partition::ha_partition(partition_info *part_info) :handler(&partition_hton, NULL), m_part_info(part_info), m_create_handler(TRUE), - m_is_sub_partitioned(is_sub_partitioned(m_part_info)) + m_is_sub_partitioned(m_part_info->is_sub_partitioned()) { DBUG_ENTER("ha_partition::ha_partition(part_info)"); @@ -331,7 +333,7 @@ int ha_partition::ha_initialise() if (m_create_handler) { - m_tot_parts= get_tot_partitions(m_part_info); + m_tot_parts= m_part_info->get_tot_partitions(); DBUG_ASSERT(m_tot_parts > 0); if (new_handlers_from_part_info()) DBUG_RETURN(1); @@ -1290,7 +1292,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, DBUG_ENTER("ha_partition::change_partitions"); m_reorged_parts= 0; - if (!is_sub_partitioned(m_part_info)) + if (!m_part_info->is_sub_partitioned()) no_subparts= 1; /* @@ -1453,7 +1455,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, if (part_elem->part_state == PART_CHANGED || (part_elem->part_state == PART_TO_BE_ADDED && temp_partitions)) name_variant= TEMP_PART_NAME; - if (is_sub_partitioned(m_part_info)) + if (m_part_info->is_sub_partitioned()) { List_iterator<partition_element> sub_it(part_elem->subpartitions); uint j= 0, part; @@ -2609,7 +2611,7 @@ void ha_partition::unlock_row() ADDITIONAL INFO: Most handlers set timestamp when calling write row if any such fields - exists. Since we are calling an underlying handler we assume the´ + exists. Since we are calling an underlying handler we assume the´ underlying handler will assume this responsibility. Underlying handlers will also call update_auto_increment to calculate diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 35435844064..40306ba7da8 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -135,7 +135,7 @@ public: virtual void set_part_info(partition_info *part_info) { m_part_info= part_info; - m_is_sub_partitioned= is_sub_partitioned(part_info); + m_is_sub_partitioned= part_info->is_sub_partitioned(); } /* ------------------------------------------------------------------------- diff --git a/sql/handler.cc b/sql/handler.cc index 68ca3855158..3c79a1af8bd 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -64,7 +64,11 @@ const handlerton default_hton = NULL, NULL, NULL, create_default, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - HTON_NO_FLAGS + NULL, /* alter_tablespace */ + NULL, /* fill_files_table */ + HTON_NO_FLAGS, /* flags */ + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES; @@ -3147,7 +3151,7 @@ namespace { bool check_table_binlog_row_based(THD *thd, TABLE *table) { return - binlog_row_based && + thd->current_stmt_binlog_row_based && thd && (thd->options & OPTION_BIN_LOG) && (table->s->tmp_table == NO_TMP_TABLE) && binlog_filter->db_ok(table->s->db.str); diff --git a/sql/handler.h b/sql/handler.h index fa4450544e9..d71841fe6b0 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -98,13 +98,6 @@ #define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30) #define HA_NO_COPY_ON_ALTER (1 << 31) -/* Flags for partition handlers */ -#define HA_CAN_PARTITION (1 << 0) /* Partition support */ -#define HA_CAN_UPDATE_PARTITION_KEY (1 << 1) -#define HA_CAN_PARTITION_UNIQUE (1 << 2) -#define HA_USE_AUTO_PARTITION (1 << 3) - - /* bits in index_flags(index_number) for what you can do with index */ #define HA_READ_NEXT 1 /* TODO really use this flag */ #define HA_READ_PREV 2 /* supports ::index_prev */ @@ -307,6 +300,7 @@ struct xid_t { long bqual_length; char data[XIDDATASIZE]; // not \0-terminated ! + xid_t() {} /* Remove gcc warning */ bool eq(struct xid_t *xid) { return eq(xid->gtrid_length, xid->bqual_length, xid->data); } bool eq(long g, long b, const char *d) @@ -578,10 +572,9 @@ typedef struct struct st_table_list *tables, class Item *cond); uint32 flags; /* global handler flags */ - /* - Handlerton functions are not set in the different storage - engines static initialization. They are initialized at handler init. - Thus, leave them last in the struct. + /* + Those handlerton functions below are properly initialized at handler + init. */ int (*binlog_func)(THD *thd, enum_binlog_func fn, void *arg); void (*binlog_log_query)(THD *thd, enum_binlog_command binlog_command, @@ -622,33 +615,6 @@ enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED, enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 }; -typedef struct { - uint32 start_part; - uint32 end_part; -} part_id_range; - - -/** - * An enum and a struct to handle partitioning and subpartitioning. - */ -enum partition_type { - NOT_A_PARTITION= 0, - RANGE_PARTITION, - HASH_PARTITION, - LIST_PARTITION -}; - -enum partition_state { - PART_NORMAL= 0, - PART_IS_DROPPED= 1, - PART_TO_BE_DROPPED= 2, - PART_TO_BE_ADDED= 3, - PART_TO_BE_REORGED= 4, - PART_REORGED_DROPPED= 5, - PART_CHANGED= 6, - PART_IS_CHANGED= 7, - PART_IS_ADDED= 8 -}; typedef struct { ulonglong data_file_length; @@ -666,400 +632,12 @@ typedef struct { #define UNDEF_NODEGROUP 65535 class Item; -class partition_element :public Sql_alloc { -public: - List<partition_element> subpartitions; - List<longlong> list_val_list; - ulonglong part_max_rows; - ulonglong part_min_rows; - char *partition_name; - char *tablespace_name; - longlong range_value; - char* part_comment; - char* data_file_name; - char* index_file_name; - handlerton *engine_type; - enum partition_state part_state; - uint16 nodegroup_id; - - partition_element() - : part_max_rows(0), part_min_rows(0), partition_name(NULL), - tablespace_name(NULL), range_value(0), part_comment(NULL), - data_file_name(NULL), index_file_name(NULL), - engine_type(NULL),part_state(PART_NORMAL), - nodegroup_id(UNDEF_NODEGROUP) - { - subpartitions.empty(); - list_val_list.empty(); - } - ~partition_element() {} -}; - -typedef struct { - longlong list_value; - uint32 partition_id; -} LIST_PART_ENTRY; - class partition_info; -typedef int (*get_part_id_func)(partition_info *part_info, - uint32 *part_id, - longlong *func_value); -typedef uint32 (*get_subpart_id_func)(partition_info *part_info); - - struct st_partition_iter; #define NOT_A_PARTITION_ID ((uint32)-1) -/* - A "Get next" function for partition iterator. - SYNOPSIS - partition_iter_func() - part_iter Partition iterator, you call only "iter.get_next(&iter)" - - RETURN - NOT_A_PARTITION_ID if there are no more partitions. - [sub]partition_id of the next partition -*/ -typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter); - - -/* - Partition set iterator. Used to enumerate a set of [sub]partitions - obtained in partition interval analysis (see get_partitions_in_range_iter). - - For the user, the only meaningful field is get_next, which may be used as - follows: - part_iterator.get_next(&part_iterator); - - Initialization is done by any of the following calls: - - get_partitions_in_range_iter-type function call - - init_single_partition_iterator() - - init_all_partitions_iterator() - Cleanup is not needed. -*/ - -typedef struct st_partition_iter -{ - partition_iter_func get_next; - - struct st_part_num_range - { - uint32 start; - uint32 end; - }; - - struct st_field_value_range - { - longlong start; - longlong end; - }; - - union - { - struct st_part_num_range part_nums; - struct st_field_value_range field_vals; - }; - partition_info *part_info; -} PARTITION_ITERATOR; - - -/* - Get an iterator for set of partitions that match given field-space interval - - SYNOPSIS - get_partitions_in_range_iter() - part_info Partitioning info - is_subpart - min_val Left edge, field value in opt_range_key format. - max_val Right edge, field value in opt_range_key format. - flags Some combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE, - NO_MAX_RANGE. - part_iter Iterator structure to be initialized - - DESCRIPTION - Functions with this signature are used to perform "Partitioning Interval - Analysis". This analysis is applicable for any type of [sub]partitioning - by some function of a single fieldX. The idea is as follows: - Given an interval "const1 <=? fieldX <=? const2", find a set of partitions - that may contain records with value of fieldX within the given interval. - - The min_val, max_val and flags parameters specify the interval. - The set of partitions is returned by initializing an iterator in *part_iter - - NOTES - There are currently two functions of this type: - - get_part_iter_for_interval_via_walking - - get_part_iter_for_interval_via_mapping - - RETURN - 0 - No matching partitions, iterator not initialized - 1 - Some partitions would match, iterator intialized for traversing them - -1 - All partitions would match, iterator not initialized -*/ - -typedef int (*get_partitions_in_range_iter)(partition_info *part_info, - bool is_subpart, - char *min_val, char *max_val, - uint flags, - PARTITION_ITERATOR *part_iter); - - -class partition_info : public Sql_alloc -{ -public: - /* - * Here comes a set of definitions needed for partitioned table handlers. - */ - List<partition_element> partitions; - List<partition_element> temp_partitions; - - List<char> part_field_list; - List<char> subpart_field_list; - - /* - If there is no subpartitioning, use only this func to get partition ids. - If there is subpartitioning, use the this func to get partition id when - you have both partition and subpartition fields. - */ - get_part_id_func get_partition_id; - - /* Get partition id when we don't have subpartition fields */ - get_part_id_func get_part_partition_id; - - /* - Get subpartition id when we have don't have partition fields by we do - have subpartition ids. - Mikael said that for given constant tuple - {subpart_field1, ..., subpart_fieldN} the subpartition id will be the - same in all subpartitions - */ - get_subpart_id_func get_subpartition_id; - - /* NULL-terminated array of fields used in partitioned expression */ - Field **part_field_array; - /* NULL-terminated array of fields used in subpartitioned expression */ - Field **subpart_field_array; - - /* - Array of all fields used in partition and subpartition expression, - without duplicates, NULL-terminated. - */ - Field **full_part_field_array; - - Item *part_expr; - Item *subpart_expr; - - Item *item_free_list; - - /* - A bitmap of partitions used by the current query. - Usage pattern: - * The handler->extra(HA_EXTRA_RESET) call at query start/end sets all - partitions to be unused. - * Before index/rnd_init(), partition pruning code sets the bits for used - partitions. - */ - MY_BITMAP used_partitions; - - union { - longlong *range_int_array; - LIST_PART_ENTRY *list_array; - }; - - /******************************************** - * INTERVAL ANALYSIS - ********************************************/ - /* - Partitioning interval analysis function for partitioning, or NULL if - interval analysis is not supported for this kind of partitioning. - */ - get_partitions_in_range_iter get_part_iter_for_interval; - /* - Partitioning interval analysis function for subpartitioning, or NULL if - interval analysis is not supported for this kind of partitioning. - */ - get_partitions_in_range_iter get_subpart_iter_for_interval; - - /* - Valid iff - get_part_iter_for_interval=get_part_iter_for_interval_via_walking: - controls how we'll process "field < C" and "field > C" intervals. - If the partitioning function F is strictly increasing, then for any x, y - "x < y" => "F(x) < F(y)" (*), i.e. when we get interval "field < C" - we can perform partition pruning on the equivalent "F(field) < F(C)". - - If the partitioning function not strictly increasing (it is simply - increasing), then instead of (*) we get "x < y" => "F(x) <= F(y)" - i.e. for interval "field < C" we can perform partition pruning for - "F(field) <= F(C)". - */ - bool range_analysis_include_bounds; - /******************************************** - * INTERVAL ANALYSIS ENDS - ********************************************/ - - char* part_info_string; - - char *part_func_string; - char *subpart_func_string; - - uchar *part_state; - - partition_element *curr_part_elem; - partition_element *current_partition; - /* - These key_map's are used for Partitioning to enable quick decisions - on whether we can derive more information about which partition to - scan just by looking at what index is used. - */ - key_map all_fields_in_PF, all_fields_in_PPF, all_fields_in_SPF; - key_map some_fields_in_PF; - - handlerton *default_engine_type; - Item_result part_result_type; - partition_type part_type; - partition_type subpart_type; - - uint part_info_len; - uint part_state_len; - uint part_func_len; - uint subpart_func_len; - - uint no_parts; - uint no_subparts; - uint count_curr_subparts; - - uint part_error_code; - - uint no_list_values; - - uint no_part_fields; - uint no_subpart_fields; - uint no_full_part_fields; - - /* - This variable is used to calculate the partition id when using - LINEAR KEY/HASH. This functionality is kept in the MySQL Server - but mainly of use to handlers supporting partitioning. - */ - uint16 linear_hash_mask; - - bool use_default_partitions; - bool use_default_no_partitions; - bool use_default_subpartitions; - bool use_default_no_subpartitions; - bool default_partitions_setup; - bool defined_max_value; - bool list_of_part_fields; - bool list_of_subpart_fields; - bool linear_hash_ind; - bool fixed; - bool from_openfrm; - - partition_info() - : get_partition_id(NULL), get_part_partition_id(NULL), - get_subpartition_id(NULL), - part_field_array(NULL), subpart_field_array(NULL), - full_part_field_array(NULL), - part_expr(NULL), subpart_expr(NULL), item_free_list(NULL), - list_array(NULL), - part_info_string(NULL), - part_func_string(NULL), subpart_func_string(NULL), - part_state(NULL), - curr_part_elem(NULL), current_partition(NULL), - default_engine_type(NULL), - part_result_type(INT_RESULT), - part_type(NOT_A_PARTITION), subpart_type(NOT_A_PARTITION), - part_info_len(0), part_state_len(0), - part_func_len(0), subpart_func_len(0), - no_parts(0), no_subparts(0), - count_curr_subparts(0), part_error_code(0), - no_list_values(0), no_part_fields(0), no_subpart_fields(0), - no_full_part_fields(0), linear_hash_mask(0), - use_default_partitions(TRUE), - use_default_no_partitions(TRUE), - use_default_subpartitions(TRUE), - use_default_no_subpartitions(TRUE), - default_partitions_setup(FALSE), - defined_max_value(FALSE), - list_of_part_fields(FALSE), list_of_subpart_fields(FALSE), - linear_hash_ind(FALSE), - fixed(FALSE), - from_openfrm(FALSE) - { - all_fields_in_PF.clear_all(); - all_fields_in_PPF.clear_all(); - all_fields_in_SPF.clear_all(); - some_fields_in_PF.clear_all(); - partitions.empty(); - temp_partitions.empty(); - part_field_list.empty(); - subpart_field_list.empty(); - } - ~partition_info() {} -}; - - -#ifdef WITH_PARTITION_STORAGE_ENGINE -uint32 get_next_partition_id_range(struct st_partition_iter* part_iter); - -/* Initialize the iterator to return a single partition with given part_id */ - -static inline void init_single_partition_iterator(uint32 part_id, - PARTITION_ITERATOR *part_iter) -{ - part_iter->part_nums.start= part_id; - part_iter->part_nums.end= part_id+1; - part_iter->get_next= get_next_partition_id_range; -} - -/* Initialize the iterator to enumerate all partitions */ -static inline -void init_all_partitions_iterator(partition_info *part_info, - PARTITION_ITERATOR *part_iter) -{ - part_iter->part_nums.start= 0; - part_iter->part_nums.end= part_info->no_parts; - part_iter->get_next= get_next_partition_id_range; -} - -/* - Answers the question if subpartitioning is used for a certain table - SYNOPSIS - is_sub_partitioned() - part_info A reference to the partition_info struct - RETURN VALUE - Returns true if subpartitioning used and false otherwise - DESCRIPTION - A routine to check for subpartitioning for improved readability of code -*/ -static inline -bool is_sub_partitioned(partition_info *part_info) -{ return (part_info->subpart_type == NOT_A_PARTITION ? FALSE : TRUE); } - - -/* - Returns the total number of partitions on the leaf level. - SYNOPSIS - get_tot_partitions() - part_info A reference to the partition_info struct - RETURN VALUE - Returns the number of partitions - DESCRIPTION - A routine to check for number of partitions for improved readability - of code -*/ -static inline -uint get_tot_partitions(partition_info *part_info) -{ - return part_info->no_parts * - (is_sub_partitioned(part_info) ? part_info->no_subparts : 1); -} - - -#endif typedef struct st_ha_create_information { @@ -1096,6 +674,7 @@ typedef class Item COND; typedef struct st_ha_check_opt { + st_ha_check_opt() {} /* Remove gcc warning */ ulong sort_buffer_size; uint flags; /* isam layer flags (e.g. for myisamchk) */ uint sql_flags; /* sql layer flags - for something myisamchk cannot do */ @@ -1104,54 +683,6 @@ typedef struct st_ha_check_opt } HA_CHECK_OPT; -#ifdef WITH_PARTITION_STORAGE_ENGINE -bool is_partition_in_list(char *part_name, List<char> list_part_names); -char *are_partitions_in_table(partition_info *new_part_info, - partition_info *old_part_info); -bool check_reorganise_list(partition_info *new_part_info, - partition_info *old_part_info, - List<char> list_part_names); -bool set_up_defaults_for_partitioning(partition_info *part_info, - handler *file, - ulonglong max_rows, - uint start_no); -handler *get_ha_partition(partition_info *part_info); -int get_parts_for_update(const byte *old_data, byte *new_data, - const byte *rec0, partition_info *part_info, - uint32 *old_part_id, uint32 *new_part_id, - longlong *func_value); -int get_part_for_delete(const byte *buf, const byte *rec0, - partition_info *part_info, uint32 *part_id); -bool check_partition_info(partition_info *part_info,handlerton **eng_type, - handler *file, ulonglong max_rows); -bool fix_partition_func(THD *thd, const char *name, TABLE *table, - bool create_table_ind); -char *generate_partition_syntax(partition_info *part_info, - uint *buf_length, bool use_sql_alloc, - bool write_all); -bool partition_key_modified(TABLE *table, List<Item> &fields); -void prune_partition_set(const TABLE *table, part_id_range *part_spec); -void get_partition_set(const TABLE *table, byte *buf, const uint index, - const key_range *key_spec, - part_id_range *part_spec); -void get_full_part_id_from_key(const TABLE *table, byte *buf, - KEY *key_info, - const key_range *key_spec, - part_id_range *part_spec); -bool mysql_unpack_partition(THD *thd, const uchar *part_buf, - uint part_info_len, - uchar *part_state, uint part_state_len, - TABLE *table, bool is_create_table_ind, - handlerton *default_db_type); -void make_used_partitions_str(partition_info *part_info, String *parts_str); -uint32 get_list_array_idx_for_endpoint(partition_info *part_info, - bool left_endpoint, - bool include_endpoint); -uint32 get_partition_id_range_for_endpoint(partition_info *part_info, - bool left_endpoint, - bool include_endpoint); -#endif - /* This is a buffer area that the handler can use to store rows. @@ -1169,11 +700,15 @@ typedef struct st_handler_buffer typedef struct system_status_var SSV; +/* + The handler class is the interface for dynamically loadable + storage engines. Do not add ifdefs and take care when adding or + changing virtual functions to avoid vtable confusion + */ class handler :public Sql_alloc { -#ifdef WITH_PARTITION_STORAGE_ENGINE - friend class ha_partition; -#endif + friend class ha_partition; + protected: struct st_table_share *table_share; /* The table definition */ struct st_table *table; /* The current open table */ @@ -1751,7 +1286,7 @@ public: virtual const char *table_type() const =0; virtual const char **bas_ext() const =0; virtual ulong table_flags(void) const =0; -#ifdef WITH_PARTITION_STORAGE_ENGINE + virtual int get_default_no_partitions(ulonglong max_rows) { return 1;} virtual void set_auto_partitions(partition_info *part_info) { return; } virtual bool get_no_parts(const char *name, @@ -1761,7 +1296,7 @@ public: return 0; } virtual void set_part_info(partition_info *part_info) {return;} -#endif + virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0; virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys) diff --git a/sql/item.cc b/sql/item.cc index 9f09a8fa02c..bbe7f3d2f9e 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -375,9 +375,6 @@ void Item::print_item_w_name(String *str) void Item::cleanup() { DBUG_ENTER("Item::cleanup"); - DBUG_PRINT("info", ("Item: 0x%lx, name %s, original name %s", - this, name ? name : "(null)", - orig_name ? orig_name : "null")); fixed=0; marker= 0; if (orig_name) @@ -5151,9 +5148,9 @@ bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const if (item_ref->ref_type() == VIEW_REF) { Item *item_ref_ref= *(item_ref->ref); - DBUG_ASSERT((*ref)->type() == FIELD_ITEM && - (item_ref_ref->type() == FIELD_ITEM)); - return (*ref == item_ref_ref); + DBUG_ASSERT((*ref)->real_item()->type() == FIELD_ITEM && + (item_ref_ref->real_item()->type() == FIELD_ITEM)); + return ((*ref)->real_item() == item_ref_ref->real_item()); } } return FALSE; diff --git a/sql/item.h b/sql/item.h index ae6aaeb82f0..b9ce418858c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -164,7 +164,8 @@ struct Hybrid_type_traits virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const; virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; static const Hybrid_type_traits *instance(); - Hybrid_type_traits() {}; + Hybrid_type_traits() {} + virtual ~Hybrid_type_traits() {} }; @@ -339,6 +340,7 @@ private: bool save_resolve_in_select_list; public: + Name_resolution_context_state() {} /* Remove gcc warning */ TABLE_LIST *save_next_local; public: @@ -1055,6 +1057,7 @@ bool agg_item_charsets(DTCollation &c, const char *name, class Item_num: public Item { public: + Item_num() {} /* Remove gcc warning */ virtual Item_num *neg()= 0; Item *safe_charset_converter(CHARSET_INFO *tocs); }; @@ -1626,7 +1629,6 @@ public: str_value.length(), collation.collation); } Item *safe_charset_converter(CHARSET_INFO *tocs); - String *const_string() { return &str_value; } inline void append(char *str, uint length) { str_value.append(str, length); } void print(String *str); // to prevent drop fixed flag (no need parent cleanup call) @@ -1928,9 +1930,10 @@ class Item_int_with_ref :public Item_int { Item *ref; public: - Item_int_with_ref(longlong i, Item *ref_arg) :Item_int(i), ref(ref_arg) + Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) : + Item_int(i), ref(ref_arg) { - unsigned_flag= ref_arg->unsigned_flag; + unsigned_flag= unsigned_arg; } int save_in_field(Field *field, bool no_conversions) { diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 2014f646356..592b7e9dc6c 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -216,7 +216,8 @@ static bool convert_constant_item(THD *thd, Field *field, Item **item) field->table->in_use->variables.sql_mode|= MODE_INVALID_DATES; if (!(*item)->save_in_field(field, 1) && !((*item)->null_value)) { - Item *tmp=new Item_int_with_ref(field->val_int(), *item); + Item *tmp=new Item_int_with_ref(field->val_int(), *item, + test(field->flags & UNSIGNED_FLAG)); field->table->in_use->variables.sql_mode= orig_sql_mode; if (tmp) thd->change_item_tree(item, tmp); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 15aebd2492c..89aafa5721e 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -128,6 +128,8 @@ public: class Comp_creator { public: + Comp_creator() {} /* Remove gcc warning */ + virtual ~Comp_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const = 0; virtual const char* symbol(bool invert) const = 0; virtual bool eqne_op() const = 0; @@ -137,6 +139,8 @@ public: class Eq_creator :public Comp_creator { public: + Eq_creator() {} /* Remove gcc warning */ + virtual ~Eq_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const; virtual const char* symbol(bool invert) const { return invert? "<>" : "="; } virtual bool eqne_op() const { return 1; } @@ -146,6 +150,8 @@ public: class Ne_creator :public Comp_creator { public: + Ne_creator() {} /* Remove gcc warning */ + virtual ~Ne_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const; virtual const char* symbol(bool invert) const { return invert? "=" : "<>"; } virtual bool eqne_op() const { return 1; } @@ -155,6 +161,8 @@ public: class Gt_creator :public Comp_creator { public: + Gt_creator() {} /* Remove gcc warning */ + virtual ~Gt_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const; virtual const char* symbol(bool invert) const { return invert? "<=" : ">"; } virtual bool eqne_op() const { return 0; } @@ -164,6 +172,8 @@ public: class Lt_creator :public Comp_creator { public: + Lt_creator() {} /* Remove gcc warning */ + virtual ~Lt_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const; virtual const char* symbol(bool invert) const { return invert? ">=" : "<"; } virtual bool eqne_op() const { return 0; } @@ -173,6 +183,8 @@ public: class Ge_creator :public Comp_creator { public: + Ge_creator() {} /* Remove gcc warning */ + virtual ~Ge_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const; virtual const char* symbol(bool invert) const { return invert? "<" : ">="; } virtual bool eqne_op() const { return 0; } @@ -182,6 +194,8 @@ public: class Le_creator :public Comp_creator { public: + Le_creator() {} /* Remove gcc warning */ + virtual ~Le_creator() {} /* Remove gcc warning */ virtual Item_bool_func2* create(Item *a, Item *b) const; virtual const char* symbol(bool invert) const { return invert? ">" : "<="; } virtual bool eqne_op() const { return 0; } @@ -739,6 +753,7 @@ class cmp_item_int :public cmp_item { longlong value; public: + cmp_item_int() {} /* Remove gcc warning */ void store_value(Item *item) { value= item->val_int(); @@ -759,6 +774,7 @@ class cmp_item_real :public cmp_item { double value; public: + cmp_item_real() {} /* Remove gcc warning */ void store_value(Item *item) { value= item->val_real(); @@ -780,6 +796,7 @@ class cmp_item_decimal :public cmp_item { my_decimal value; public: + cmp_item_decimal() {} /* Remove gcc warning */ void store_value(Item *item); int cmp(Item *arg); int compare(cmp_item *c); diff --git a/sql/item_func.cc b/sql/item_func.cc index 22200732861..d2e0911557f 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2657,6 +2657,7 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func, u_d->name.str, ER(ER_UNKNOWN_ERROR)); DBUG_RETURN(TRUE); } + thd->set_current_stmt_binlog_row_based_if_mixed(); DBUG_RETURN(FALSE); } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a3e47154bc3..eb89eb7708c 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -3002,6 +3002,7 @@ String *Item_func_uuid::val_str(String *str) char *s; THD *thd= current_thd; + thd->set_current_stmt_binlog_row_based_if_mixed(); pthread_mutex_lock(&LOCK_uuid_generator); if (! uuid_time) /* first UUID() call. initializing data */ { diff --git a/sql/item_sum.h b/sql/item_sum.h index a8242d76287..a38530a502c 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1116,6 +1116,13 @@ public: enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;} const char *func_name() const { return "group_concat"; } virtual Item_result result_type () const { return STRING_RESULT; } + enum_field_types field_type() const + { + if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB) + return FIELD_TYPE_BLOB; + else + return MYSQL_TYPE_VARCHAR; + } void clear(); bool add(); void reset_field() { DBUG_ASSERT(0); } // not used diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 2effe3a615c..c4f7dec70d0 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1656,9 +1656,15 @@ longlong Item_func_sec_to_time::val_int() void Item_func_date_format::fix_length_and_dec() { + /* + Must use this_item() in case it's a local SP variable + (for ->max_length and ->str_value) + */ + Item *arg1= args[1]->this_item(); + decimals=0; collation.set(&my_charset_bin); - if (args[1]->type() == STRING_ITEM) + if (arg1->type() == STRING_ITEM) { // Optimize the normal case fixed_length=1; @@ -1666,13 +1672,13 @@ void Item_func_date_format::fix_length_and_dec() The result is a binary string (no reason to use collation->mbmaxlen This is becasue make_date_time() only returns binary strings */ - max_length= format_length(((Item_string*) args[1])->const_string()); + max_length= format_length(&arg1->str_value); } else { fixed_length=0; /* The result is a binary string (no reason to use collation->mbmaxlen */ - max_length=min(args[1]->max_length,MAX_BLOB_WIDTH) * 10; + max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10; set_if_smaller(max_length,MAX_BLOB_WIDTH); } maybe_null=1; // If wrong date @@ -1682,6 +1688,7 @@ void Item_func_date_format::fix_length_and_dec() bool Item_func_date_format::eq(const Item *item, bool binary_cmp) const { Item_func_date_format *item_func; + if (item->type() != FUNC_ITEM) return 0; if (func_name() != ((Item_func*) item)->func_name()) diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index d86b6acfc56..8ad7e2f9661 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -206,7 +206,11 @@ public: return str; } enum Item_result result_type () const { return STRING_RESULT; } - void fix_length_and_dec() { max_length= MAX_BLOB_WIDTH; } + void fix_length_and_dec() + { + max_length= MAX_BLOB_WIDTH; + collation.collation= pxml->charset(); + } const char *func_name() const { return "nodeset"; } }; @@ -252,6 +256,18 @@ public: }; +/* Returns self */ +class Item_nodeset_func_selfbyname: public Item_nodeset_func_axisbyname +{ +public: + Item_nodeset_func_selfbyname(Item *a, const char *n_arg, uint l_arg, + String *pxml): + Item_nodeset_func_axisbyname(a, n_arg, l_arg, pxml) {} + const char *func_name() const { return "xpath_selfbyname"; } + String *val_nodeset(String *nodeset); +}; + + /* Returns children */ class Item_nodeset_func_childbyname: public Item_nodeset_func_axisbyname { @@ -572,6 +588,20 @@ String * Item_nodeset_func_union::val_nodeset(String *nodeset) } +String *Item_nodeset_func_selfbyname::val_nodeset(String *nodeset) +{ + prepare(nodeset); + for (MY_XPATH_FLT *flt= fltbeg; flt < fltend; flt++) + { + uint pos= 0; + MY_XML_NODE *self= &nodebeg[flt->num]; + if (validname(self)) + ((XPathFilter*)nodeset)->append_element(flt->num,pos++); + } + return nodeset; +} + + String *Item_nodeset_func_childbyname::val_nodeset(String *nodeset) { prepare(nodeset); @@ -945,6 +975,9 @@ static Item* nametestfunc(MY_XPATH *xpath, case MY_XPATH_AXIS_ATTRIBUTE: res= new Item_nodeset_func_attributebyname(arg, beg, len, xpath->pxml); break; + case MY_XPATH_AXIS_SELF: + res= new Item_nodeset_func_selfbyname(arg, beg, len, xpath->pxml); + break; default: res= new Item_nodeset_func_childbyname(arg, beg, len, xpath->pxml); } @@ -1272,7 +1305,7 @@ my_xident_body(int c) return (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= '0' && (c) <= '9') || - ((c)=='-')); + ((c)=='-') || ((c) == '_')); } @@ -1976,8 +2009,17 @@ static int my_xpath_parse_AndExpr(MY_XPATH *xpath) */ static int my_xpath_parse_ne(MY_XPATH *xpath) { - return my_xpath_parse_term(xpath, MY_XPATH_LEX_EXCL) && - my_xpath_parse_term(xpath, MY_XPATH_LEX_EQ); + MY_XPATH_LEX prevtok= xpath->prevtok; + if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_EXCL)) + return 0; + if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_EQ)) + { + /* Unget the exclamation mark */ + xpath->lasttok= xpath->prevtok; + xpath->prevtok= prevtok; + return 0; + } + return 1; } static int my_xpath_parse_EqualityOperator(MY_XPATH *xpath) { @@ -2335,6 +2377,7 @@ void Item_xml_str_func::fix_length_and_dec() xpath.cs= collation.collation; xpath.debug= 0; xpath.pxml= &pxml; + pxml.set_charset(collation.collation); rc= my_xpath_parse(&xpath, xp->ptr(), xp->ptr() + xp->length()); diff --git a/sql/log.cc b/sql/log.cc index 323b6df86d9..ff14b986aa4 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -102,7 +102,9 @@ handlerton binlog_hton = { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill FILES table */ - HTON_NOT_USER_SELECTABLE | HTON_HIDDEN + HTON_NOT_USER_SELECTABLE | HTON_HIDDEN, + NULL, /* binlog_func */ + NULL /* binlog_log_query */ }; @@ -2630,7 +2632,7 @@ THD::binlog_set_pending_rows_event(Rows_log_event* ev) int MYSQL_LOG::flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event) { DBUG_ENTER("MYSQL_LOG::flush_and_set_pending_rows_event(event)"); - DBUG_ASSERT(binlog_row_based && mysql_bin_log.is_open()); + DBUG_ASSERT(thd->current_stmt_binlog_row_based && mysql_bin_log.is_open()); DBUG_PRINT("enter", ("event=%p", event)); int error= 0; @@ -2847,7 +2849,7 @@ bool MYSQL_LOG::write(Log_event *event_info) */ if (thd) { - if (!binlog_row_based) + if (!thd->current_stmt_binlog_row_based) { if (thd->last_insert_id_used) { @@ -3517,7 +3519,7 @@ bool MYSQL_LOG::write_table_map(THD *thd, IO_CACHE *file, TABLE* table, table, table->s->table_name, table->s->table_map_id)); /* Pre-conditions */ - DBUG_ASSERT(binlog_row_based && is_open()); + DBUG_ASSERT(thd->current_stmt_binlog_row_based && is_open()); DBUG_ASSERT(table->s->table_map_id != ULONG_MAX); #ifndef DBUG_OFF diff --git a/sql/log.h b/sql/log.h index 98a86072fca..8a83e7b66d0 100644 --- a/sql/log.h +++ b/sql/log.h @@ -507,4 +507,24 @@ public: void init_general_log(uint general_log_printer); }; + +enum enum_binlog_format { + BINLOG_FORMAT_STMT= 0, // statement-based +#ifdef HAVE_ROW_BASED_REPLICATION + BINLOG_FORMAT_ROW= 1, // row_based + /* + statement-based except for cases where only row-based can work (UUID() + etc): + */ + BINLOG_FORMAT_MIXED= 2, +#endif +/* + This value is last, after the end of binlog_format_typelib: it has no + corresponding cell in this typelib. We use this value to be able to know if + the user has explicitely specified a binlog format at startup or not. +*/ + BINLOG_FORMAT_UNSPEC= 3 +}; +extern TYPELIB binlog_format_typelib; + #endif /* LOG_H */ diff --git a/sql/log_event.cc b/sql/log_event.cc index cd16745df90..e589f46e0e0 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -28,7 +28,6 @@ #endif /* MYSQL_CLIENT */ #include <base64.h> #include <my_bitmap.h> -#include <my_vle.h> #define log_cs &my_charset_latin1 @@ -5128,7 +5127,8 @@ Rows_log_event::Rows_log_event(const char *buf, uint event_len, byte const *const var_start= (const byte *)buf + common_header_len + post_header_len; byte const *const ptr_width= var_start; - byte const *const ptr_after_width= my_vle_decode(&m_width, ptr_width); + uchar *ptr_after_width= (uchar*) ptr_width; + m_width = net_field_length(&ptr_after_width); const uint byte_count= (m_width + 7) / 8; const byte* const ptr_rows_data= var_start + byte_count + 1; @@ -5281,6 +5281,7 @@ int Rows_log_event::exec_event(st_relay_log_info *rli) tested replicate-* rules). */ TABLE_LIST table_list; + TABLE_LIST *tables= &table_list; bool need_reopen; uint count= 1; bzero(&table_list, sizeof(table_list)); @@ -5330,13 +5331,12 @@ int Rows_log_event::exec_event(st_relay_log_info *rli) */ thd->binlog_flush_pending_rows_event(false); - close_tables_for_reopen(thd, &table_list); + close_tables_for_reopen(thd, &tables); /* open the table again, same as in Table_map_event::exec_event */ table_list.db= const_cast<char*>(db); table_list.alias= table_list.table_name= const_cast<char*>(table_name); table_list.updating= 1; - TABLE_LIST *tables= &table_list; if ((error= open_tables(thd, &tables, &count, 0)) == 0) { /* reset some variables for the table list*/ @@ -5598,13 +5598,14 @@ bool Rows_log_event::write_data_body(IO_CACHE*file) Note that this should be the number of *bits*, not the number of bytes. */ - byte sbuf[my_vle_sizeof(m_width)]; + char sbuf[sizeof(m_width)]; my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf; - char *const sbuf_end= (char *const)my_vle_encode(sbuf, sizeof(sbuf), m_width); - DBUG_ASSERT(static_cast<my_size_t>(sbuf_end - (char *const)sbuf) <= sizeof(sbuf)); + char *const sbuf_end= net_store_length((char*) sbuf, (uint) m_width); + DBUG_ASSERT(static_cast<my_size_t>(sbuf_end - sbuf) <= sizeof(sbuf)); - return (my_b_safe_write(file, sbuf, sbuf_end - (char *const)sbuf) || + return (my_b_safe_write(file, reinterpret_cast<byte*>(sbuf), + sbuf_end - sbuf) || my_b_safe_write(file, reinterpret_cast<byte*>(m_cols.bitmap), no_bytes_in_map(&m_cols)) || my_b_safe_write(file, m_rows_buf, data_size)); @@ -5731,7 +5732,8 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len, /* Length of table name + counter + terminating null */ byte const* const ptr_colcnt= ptr_tbllen + m_tbllen + 2; - byte const* const ptr_after_colcnt= my_vle_decode(&m_colcnt, ptr_colcnt); + uchar *ptr_after_colcnt= (uchar*) ptr_colcnt; + m_colcnt= net_field_length(&ptr_after_colcnt); DBUG_PRINT("info",("m_dblen=%d off=%d m_tbllen=%d off=%d m_colcnt=%d off=%d", m_dblen, ptr_dblen-(const byte*)vpart, @@ -5854,13 +5856,17 @@ int Table_map_log_event::exec_event(st_relay_log_info *rli) (!rpl_filter->is_on() || rpl_filter->tables_ok("", &table_list))) { /* + TODO: Mats will soon change this test below so that a SBR slave always + accepts RBR events from the master (and binlogs them RBR). + */ + /* Check if the slave is set to use SBR. If so, the slave should stop immediately since it is not possible to daisy-chain from RBR to SBR. Once RBR is used, the rest of the chain has to use RBR. */ if (mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG) && - !binlog_row_based) + !thd->current_stmt_binlog_row_based) { slave_print_msg(ERROR_LEVEL, rli, ER_BINLOG_ROW_RBR_TO_SBR, "It is not possible to use statement-based binlogging " @@ -6043,15 +6049,16 @@ bool Table_map_log_event::write_data_body(IO_CACHE *file) byte const dbuf[]= { m_dblen }; byte const tbuf[]= { m_tbllen }; - byte cbuf[my_vle_sizeof(m_colcnt)]; - byte *const cbuf_end= my_vle_encode(cbuf, sizeof(cbuf), m_colcnt); + char cbuf[sizeof(m_colcnt)]; + char *const cbuf_end= net_store_length((char*) cbuf, (uint) m_colcnt); DBUG_ASSERT(static_cast<my_size_t>(cbuf_end - cbuf) <= sizeof(cbuf)); return (my_b_safe_write(file, dbuf, sizeof(dbuf)) || my_b_safe_write(file, (const byte*)m_dbnam, m_dblen+1) || my_b_safe_write(file, tbuf, sizeof(tbuf)) || my_b_safe_write(file, (const byte*)m_tblnam, m_tbllen+1) || - my_b_safe_write(file, cbuf, cbuf_end - cbuf) || + my_b_safe_write(file, reinterpret_cast<byte*>(cbuf), + cbuf_end - (char*) cbuf) || my_b_safe_write(file, reinterpret_cast<byte*>(m_coltype), m_colcnt)); } #endif @@ -6358,18 +6365,27 @@ void Write_rows_log_event::print(FILE *file, PRINT_EVENT_INFO* print_event_info) **************************************************************************/ #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) -static int record_compare(TABLE *table, char const *a, char const *b) +/* + Compares table->record[0] and table->record[1] + + Returns TRUE if different. +*/ +static bool record_compare(TABLE *table) { - for (my_size_t i= 0 ; i < table->s->fields ; ++i) + if (table->s->blob_fields + table->s->varchar_fields == 0) + return cmp_record(table,record[1]); + /* Compare null bits */ + if (memcmp(table->null_flags, + table->null_flags+table->s->rec_buff_length, + table->s->null_bytes)) + return TRUE; // Diff in NULL value + /* Compare updated fields */ + for (Field **ptr=table->field ; *ptr ; ptr++) { - uint const off= table->field[i]->offset(); - uint const res= table->field[i]->cmp_binary(a + off, - b + off); - if (res != 0) { - return res; - } + if ((*ptr)->cmp_binary_offset(table->s->rec_buff_length)) + return TRUE; } - return 0; + return FALSE; } @@ -6377,15 +6393,12 @@ static int record_compare(TABLE *table, char const *a, char const *b) Find the row given by 'key', if the table has keys, or else use a table scan to find (and fetch) the row. If the engine allows random access of the records, a combination of position() and rnd_pos() will be used. - - The 'record_buf' will be used as buffer for records while locating the - correct row. */ -static int find_and_fetch_row(TABLE *table, byte *key, byte *record_buf) +static int find_and_fetch_row(TABLE *table, byte *key) { DBUG_ENTER("find_and_fetch_row(TABLE *table, byte *key, byte *record)"); DBUG_PRINT("enter", ("table=%p, key=%p, record=%p", - table, key, record_buf)); + table, key, table->record[1])); DBUG_ASSERT(table->in_use != NULL); @@ -6403,7 +6416,7 @@ static int find_and_fetch_row(TABLE *table, byte *key, byte *record_buf) DBUG_RETURN(table->file->rnd_pos(table->record[0], table->file->ref)); } - DBUG_ASSERT(record_buf); + DBUG_ASSERT(table->record[1]); /* We need to retrieve all fields */ table->file->ha_set_all_bits_in_read_set(); @@ -6411,7 +6424,7 @@ static int find_and_fetch_row(TABLE *table, byte *key, byte *record_buf) if (table->s->keys > 0) { int error; - if ((error= table->file->index_read_idx(record_buf, 0, key, + if ((error= table->file->index_read_idx(table->record[1], 0, key, table->key_info->key_length, HA_READ_KEY_EXACT))) { @@ -6436,10 +6449,10 @@ static int find_and_fetch_row(TABLE *table, byte *key, byte *record_buf) if (table->key_info->flags & HA_NOSAME) DBUG_RETURN(0); - while (record_compare(table, (const char*)table->record[0], (const char*)record_buf) != 0) + while (record_compare(table)) { int error; - if ((error= table->file->index_next(record_buf))) + if ((error= table->file->index_next(table->record[1]))) { table->file->print_error(error, MYF(0)); DBUG_RETURN(error); @@ -6453,7 +6466,7 @@ static int find_and_fetch_row(TABLE *table, byte *key, byte *record_buf) int error= 0; do { - error= table->file->rnd_next(record_buf); + error= table->file->rnd_next(table->record[1]); switch (error) { case 0: @@ -6470,9 +6483,7 @@ static int find_and_fetch_row(TABLE *table, byte *key, byte *record_buf) DBUG_RETURN(error); } } - while (restart_count < 2 && - record_compare(table, (const char*)table->record[0], - (const char*)record_buf) != 0); + while (restart_count < 2 && record_compare(table)); DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == 0); DBUG_RETURN(error); @@ -6492,7 +6503,7 @@ Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, TABLE *tbl_arg, bool is_transactional) : Rows_log_event(thd_arg, tbl_arg, tid, cols, is_transactional) #ifdef HAVE_REPLICATION - ,m_memory(NULL), m_key(NULL), m_search_record(NULL) + ,m_memory(NULL), m_key(NULL), m_after_image(NULL) #endif { } @@ -6509,7 +6520,7 @@ Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint event_len, : Rows_log_event(buf, event_len, DELETE_ROWS_EVENT, description_event) #else : Rows_log_event(buf, event_len, DELETE_ROWS_EVENT, description_event), - m_memory(NULL), m_key(NULL), m_search_record(NULL) + m_memory(NULL), m_key(NULL), m_after_image(NULL) #endif { } @@ -6524,7 +6535,7 @@ int Delete_rows_log_event::do_before_row_operations(TABLE *table) table->s->primary_key < MAX_KEY) { /* - We don't need to allocate any memory for m_search_record and + We don't need to allocate any memory for m_after_image and m_key since they are not used. */ return 0; @@ -6536,14 +6547,14 @@ int Delete_rows_log_event::do_before_row_operations(TABLE *table) { m_memory= my_multi_malloc(MYF(MY_WME), - &m_search_record, table->s->reclength, + &m_after_image, table->s->reclength, &m_key, table->key_info->key_length, NULL); } else { - m_search_record= (byte*)my_malloc(table->s->reclength, MYF(MY_WME)); - m_memory= (gptr)m_search_record; + m_after_image= (byte*)my_malloc(table->s->reclength, MYF(MY_WME)); + m_memory= (gptr)m_after_image; m_key= NULL; } if (!m_memory) @@ -6570,7 +6581,7 @@ int Delete_rows_log_event::do_after_row_operations(TABLE *table, int error) table->file->ha_index_or_rnd_end(); my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR)); // Free for multi_malloc m_memory= NULL; - m_search_record= NULL; + m_after_image= NULL; m_key= NULL; return error; @@ -6608,7 +6619,7 @@ int Delete_rows_log_event::do_exec_row(TABLE *table) { DBUG_ASSERT(table != NULL); - int error= find_and_fetch_row(table, m_key, m_search_record); + int error= find_and_fetch_row(table, m_key); if (error) return error; @@ -6680,30 +6691,20 @@ int Update_rows_log_event::do_before_row_operations(TABLE *table) { DBUG_ASSERT(m_memory == NULL); - if ((table->file->table_flags() & HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS) && - table->s->primary_key < MAX_KEY) - { - /* - We don't need to allocate any memory for m_search_record and - m_key since they are not used. - */ - return 0; - } - int error= 0; if (table->s->keys > 0) { m_memory= my_multi_malloc(MYF(MY_WME), - &m_search_record, table->s->reclength, + &m_after_image, table->s->reclength, &m_key, table->key_info->key_length, NULL); } else { - m_search_record= (byte*)my_malloc(table->s->reclength, MYF(MY_WME)); - m_memory= (gptr)m_search_record; + m_after_image= (byte*)my_malloc(table->s->reclength, MYF(MY_WME)); + m_memory= (gptr)m_after_image; m_key= NULL; } if (!m_memory) @@ -6731,7 +6732,7 @@ int Update_rows_log_event::do_after_row_operations(TABLE *table, int error) table->file->ha_index_or_rnd_end(); my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR)); m_memory= NULL; - m_search_record= NULL; + m_after_image= NULL; m_key= NULL; return error; @@ -6751,8 +6752,8 @@ char const *Update_rows_log_event::do_prepare_row(THD *thd, TABLE *table, /* record[0] is the before image for the update */ ptr= unpack_row(table, table->record[0], ptr, &m_cols); DBUG_ASSERT(ptr != NULL); - /* record[1] is the after image for the update */ - ptr= unpack_row(table, table->record[1], ptr, &m_cols); + /* m_after_image is the after image for the update */ + ptr= unpack_row(table, m_after_image, ptr, &m_cols); /* If we will access rows using the random access method, m_key will @@ -6772,11 +6773,20 @@ int Update_rows_log_event::do_exec_row(TABLE *table) { DBUG_ASSERT(table != NULL); - int error= find_and_fetch_row(table, m_key, m_search_record); + int error= find_and_fetch_row(table, m_key); if (error) return error; /* + This is only a precaution to make sure that the call to + ha_update_row is using record[1]. + + If this is not needed/required, then we could use m_after_image in + that call instead. + */ + bmove_align(table->record[1], m_after_image,(size_t) table->s->reclength); + + /* Now we should have the right row to update. The record that has been fetched is guaranteed to be in record[0], so we use that. */ diff --git a/sql/log_event.h b/sql/log_event.h index a7c532d4c24..dd68e969ff1 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -28,14 +28,6 @@ #include <my_bitmap.h> -#if !defined(MYSQL_CLIENT) -#ifdef HAVE_ROW_BASED_REPLICATION -extern my_bool binlog_row_based; -#else -extern const my_bool binlog_row_based; -#endif -#endif - #define LOG_READ_EOF -1 #define LOG_READ_BOGUS -2 #define LOG_READ_IO -3 @@ -131,6 +123,7 @@ struct old_sql_ex ****************************************************************************/ struct sql_ex_info { + sql_ex_info() {} /* Remove gcc warning */ char* field_term; char* enclosed; char* line_term; @@ -2012,7 +2005,7 @@ private: #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) gptr m_memory; - byte *m_search_record; + byte *m_after_image; virtual int do_before_row_operations(TABLE *table); virtual int do_after_row_operations(TABLE *table, int error); @@ -2076,7 +2069,7 @@ private: #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) gptr m_memory; byte *m_key; - byte *m_search_record; + byte *m_after_image; virtual int do_before_row_operations(TABLE *table); virtual int do_after_row_operations(TABLE *table, int error); @@ -2146,7 +2139,7 @@ private: #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) gptr m_memory; byte *m_key; - byte *m_search_record; + byte *m_after_image; virtual int do_before_row_operations(TABLE *table); virtual int do_after_row_operations(TABLE *table, int error); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index fc777c47818..b3c3e4d9211 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -92,6 +92,15 @@ char* query_table_status(THD *thd,const char *db,const char *table_name); #define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1)) #define all_bits_set(A,B) ((A) & (B) != (B)) +#define WARN_DEPRECATED(Thd,Ver,Old,New) \ + do { \ + DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) >= 0); \ + push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \ + ER_WARN_DEPRECATED, ER(ER_WARN_DEPRECATED), \ + (Old), (Ver), (New)); \ + } while(0) + + extern CHARSET_INFO *system_charset_info, *files_charset_info ; extern CHARSET_INFO *national_charset_info, *table_alias_charset; @@ -434,6 +443,7 @@ typedef struct st_sql_list { byte *first; byte **next; + st_sql_list() {} /* Remove gcc warning */ inline void empty() { elements=0; @@ -503,6 +513,8 @@ typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key, #include "protocol.h" #include "sql_plugin.h" #include "sql_udf.h" +#include "sql_partition.h" + class user_var_entry; class Security_context; enum enum_var_type @@ -657,7 +669,7 @@ bool table_cache_init(void); void table_cache_free(void); bool table_def_init(void); void table_def_free(void); -void assign_new_table_id(TABLE *table); +void assign_new_table_id(TABLE_SHARE *share); uint cached_open_tables(void); uint cached_table_definitions(void); void kill_mysql(void); @@ -1036,9 +1048,9 @@ void free_io_cache(TABLE *entry); void intern_close_table(TABLE *entry); bool close_thread_table(THD *thd, TABLE **table_ptr); void close_temporary_tables(THD *thd); -void close_tables_for_reopen(THD *thd, TABLE_LIST *tables); +void close_tables_for_reopen(THD *thd, TABLE_LIST **tables); TABLE_LIST *find_table_in_list(TABLE_LIST *table, - uint offset_to_list, + st_table_list *TABLE_LIST::*link, const char *db_name, const char *table_name); TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list); @@ -1128,7 +1140,7 @@ inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table, const char *db_name, const char *table_name) { - return find_table_in_list(table, offsetof(TABLE_LIST, next_global), + return find_table_in_list(table, &TABLE_LIST::next_global, db_name, table_name); } @@ -1136,7 +1148,7 @@ inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table, const char *db_name, const char *table_name) { - return find_table_in_list(table, offsetof(TABLE_LIST, next_local), + return find_table_in_list(table, &TABLE_LIST::next_local, db_name, table_name); } @@ -1286,12 +1298,8 @@ extern ulong what_to_log,flush_time; extern ulong query_buff_size, thread_stack; extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit; extern ulong max_binlog_size, max_relay_log_size; -extern const char *opt_binlog_format; #ifdef HAVE_ROW_BASED_REPLICATION -extern my_bool binlog_row_based; extern ulong opt_binlog_rows_event_max_size; -#else -extern const my_bool binlog_row_based; #endif extern ulong rpl_recovery_rank, thread_cache_size; extern ulong back_log; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e1c8ed966ee..4f8944593bc 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -465,31 +465,14 @@ my_bool opt_noacl; my_bool sp_automatic_privileges= 1; #ifdef HAVE_ROW_BASED_REPLICATION -/* - This variable below serves as an optimization for (opt_binlog_format == - BF_ROW) as we need to do this test for every row. Stmt-based is default. -*/ -my_bool binlog_row_based= FALSE; ulong opt_binlog_rows_event_max_size; -const char *binlog_format_names[]= {"STATEMENT", "ROW", NullS}; -/* - Note that BF_UNSPECIFIED is last, after the end of binlog_format_names: it - has no corresponding cell in this array. We use this value to be able to - know if the user has explicitely specified a binlog format (then we require - also --log-bin) or not (then we fall back to statement-based). -*/ -enum binlog_format { BF_STMT= 0, BF_ROW= 1, BF_UNSPECIFIED= 2 }; +const char *binlog_format_names[]= {"STATEMENT", "ROW", "MIXED", NullS}; #else -const my_bool binlog_row_based= FALSE; const char *binlog_format_names[]= {"STATEMENT", NullS}; -enum binlog_format { BF_STMT= 0, BF_UNSPECIFIED= 2 }; #endif - TYPELIB binlog_format_typelib= { array_elements(binlog_format_names)-1,"", binlog_format_names, NULL }; -const char *opt_binlog_format= 0; -enum binlog_format opt_binlog_format_id= BF_UNSPECIFIED; #ifdef HAVE_INITGROUPS static bool calling_initgroups= FALSE; /* Used in SIGSEGV handler. */ @@ -3070,6 +3053,8 @@ static int init_server_components() #ifdef HAVE_REPLICATION init_slave_list(); #endif + init_events(); + /* Setup logs */ /* enable old-fashioned error log */ @@ -3187,42 +3172,25 @@ with --log-bin instead."); unireg_abort(1); } - if (!opt_bin_log && (opt_binlog_format_id != BF_UNSPECIFIED)) + if (!opt_bin_log && (global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC)) { sql_print_warning("You need to use --log-bin to make " "--binlog-format work."); unireg_abort(1); } - if (opt_binlog_format_id == BF_UNSPECIFIED) + if (global_system_variables.binlog_format == BINLOG_FORMAT_UNSPEC) { #ifdef HAVE_NDB_BINLOG if (opt_bin_log && have_ndbcluster == SHOW_OPTION_YES) - opt_binlog_format_id= BF_ROW; + global_system_variables.binlog_format= BINLOG_FORMAT_ROW; else #endif - opt_binlog_format_id= BF_STMT; - } -#ifdef HAVE_ROW_BASED_REPLICATION - if (opt_binlog_format_id == BF_ROW) - { - binlog_row_based= TRUE; - /* - Row-based binlogging turns on InnoDB unsafe locking, because the locks - are not needed when using row-based binlogging. In fact - innodb-locks-unsafe-for-binlog is unsafe only for stmt-based, it's - safe for row-based. - */ -#ifdef HAVE_INNOBASE_DB - innobase_locks_unsafe_for_binlog= TRUE; -#endif - /* Trust stored function creators because they can do no harm */ - trust_function_creators= 1; + global_system_variables.binlog_format= BINLOG_FORMAT_STMT; } -#endif + /* Check that we have not let the format to unspecified at this point */ - DBUG_ASSERT((uint)opt_binlog_format_id <= + DBUG_ASSERT((uint)global_system_variables.binlog_format <= array_elements(binlog_format_names)-1); - opt_binlog_format= binlog_format_names[opt_binlog_format_id]; #ifdef HAVE_REPLICATION if (opt_log_slave_updates && replicate_same_server_id) @@ -3698,8 +3666,6 @@ we force server id to 2, but this MySQL server will not act as a slave."); } } - init_events(); - create_shutdown_thread(); create_maintenance_thread(); @@ -4864,8 +4830,6 @@ struct my_option my_long_options[] = (gptr*) &abort_slave_event_count, (gptr*) &abort_slave_event_count, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif /* HAVE_REPLICATION */ - {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax. This mode will also set transaction isolation level 'serializable'.", 0, 0, 0, - GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"allow-suspicious-udfs", OPT_ALLOW_SUSPICIOUS_UDFS, "Allows use of UDFs consisting of only one symbol xxx() " "without corresponding xxx_init() or xxx_deinit(). That also means " @@ -4873,6 +4837,8 @@ struct my_option my_long_options[] = "from libc.so", (gptr*) &opt_allow_suspicious_udfs, (gptr*) &opt_allow_suspicious_udfs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax. This mode will also set transaction isolation level 'serializable'.", 0, 0, 0, + GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"auto-increment-increment", OPT_AUTO_INCREMENT, "Auto-increment columns are incremented by this", (gptr*) &global_system_variables.auto_increment_increment, @@ -4929,23 +4895,23 @@ Disable with --skip-bdb (will save memory).", {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", (gptr*) &my_bind_addr_str, (gptr*) &my_bind_addr_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"binlog-format", OPT_BINLOG_FORMAT, + {"binlog_format", OPT_BINLOG_FORMAT, #ifdef HAVE_ROW_BASED_REPLICATION "Tell the master the form of binary logging to use: either 'row' for " - "row-based binary logging (which automatically turns on " - "innodb_locks_unsafe_for_binlog as it is safe in this case), or " - "'statement' for statement-based logging. " + "row-based binary logging, or 'statement' for statement-based binary " + "logging, or 'mixed'. 'mixed' is statement-based binary logging except " + "for those statements where only row-based is correct: those which " + "involve user-defined functions (i.e. UDFs) or the UUID() function; for " + "those, row-based binary logging is automatically used. " #ifdef HAVE_NDB_BINLOG - "If ndbcluster is enabled, the default will be set to 'row'." + "If ndbcluster is enabled, the default is 'row'." #endif - , #else - "Tell the master the form of binary logging to use: this release build " + "Tell the master the form of binary logging to use: this build " "supports only statement-based binary logging, so only 'statement' is " - "a legal value; MySQL-Max release builds support row-based binary logging " - "in addition.", + "a legal value." #endif - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + , 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"binlog-do-db", OPT_BINLOG_DO_DB, "Tells the master it should log updates for the specified database, and exclude all others not explicitly mentioned.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -5148,9 +5114,7 @@ Disable with --skip-innodb-doublewrite.", (gptr*) &innobase_use_doublewrite, (gptr*) &innobase_unix_file_flush_method, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"innodb_locks_unsafe_for_binlog", OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG, - "Force InnoDB not to use next-key locking, to use only row-level locking." - " This is unsafe if you are using statement-based binary logging, and safe" - " if you are using row-based binary logging.", + "Force InnoDB to not use next-key locking, to use only row-level locking.", (gptr*) &innobase_locks_unsafe_for_binlog, (gptr*) &innobase_locks_unsafe_for_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"innodb_log_arch_dir", OPT_INNODB_LOG_ARCH_DIR, @@ -5175,16 +5139,16 @@ Disable with --skip-innodb-doublewrite.", (gptr*) &innobase_use_doublewrite, "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file", (gptr*) &innobase_create_status_file, (gptr*) &innobase_create_status_file, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"innodb_table_locks", OPT_INNODB_TABLE_LOCKS, - "Enable InnoDB locking in LOCK TABLES", - (gptr*) &global_system_variables.innodb_table_locks, - (gptr*) &global_system_variables.innodb_table_locks, - 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0}, {"innodb_support_xa", OPT_INNODB_SUPPORT_XA, "Enable InnoDB support for the XA two-phase commit", (gptr*) &global_system_variables.innodb_support_xa, (gptr*) &global_system_variables.innodb_support_xa, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0}, + {"innodb_table_locks", OPT_INNODB_TABLE_LOCKS, + "Enable InnoDB locking in LOCK TABLES", + (gptr*) &global_system_variables.innodb_table_locks, + (gptr*) &global_system_variables.innodb_table_locks, + 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0}, #endif /* End WITH_INNOBASE_STORAGE_ENGINE */ {"isam", OPT_ISAM, "Obsolete. ISAM storage engine is no longer supported.", (gptr*) &opt_isam, (gptr*) &opt_isam, 0, GET_BOOL, NO_ARG, 0, 0, 0, @@ -5231,8 +5195,9 @@ Disable with --skip-innodb-doublewrite.", (gptr*) &innobase_use_doublewrite, "a stored function (or trigger) is allowed only to users having the SUPER privilege " "and only if this stored function (trigger) may not break binary logging." #ifdef HAVE_ROW_BASED_REPLICATION - " If using --binlog-format=row, the security issues do not exist and the " - "binary logging cannot break so this option is automatically set to 1." + "Note that if ALL connections to this server ALWAYS use row-based binary " + "logging, the security issues do not exist and the binary logging cannot " + "break, so you can safely set this to 1." #endif ,(gptr*) &trust_function_creators, (gptr*) &trust_function_creators, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -5535,12 +5500,6 @@ thread is in the relay logs.", {"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB, "Updates to a database with a different name than the original. Example: replicate-rewrite-db=master_db_name->slave_db_name.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE, - "Tells the slave thread to restrict replication to the tables that match the specified wildcard pattern. To specify more than one table, use the directive multiple times, once for each table. This will work for cross-database updates. Example: replicate-wild-do-table=foo%.bar% will replicate only updates to tables in all databases that start with foo and whose table names start with bar.", - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE, - "Tells the slave thread to not replicate to the tables that match the given wildcard pattern. To specify more than one table to ignore, use the directive multiple times, once for each table. This will work for cross-database updates. Example: replicate-wild-ignore-table=foo%.bar% will not do updates to tables in databases that start with foo and whose table names start with bar.", - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #ifdef HAVE_REPLICATION {"replicate-same-server-id", OPT_REPLICATE_SAME_SERVER_ID, "In replication, if set to 1, do not skip events having our server id. \ @@ -5550,6 +5509,12 @@ Can't be set to 1 if --log-slave-updates is used.", (gptr*) &replicate_same_server_id, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE, + "Tells the slave thread to restrict replication to the tables that match the specified wildcard pattern. To specify more than one table, use the directive multiple times, once for each table. This will work for cross-database updates. Example: replicate-wild-do-table=foo%.bar% will replicate only updates to tables in all databases that start with foo and whose table names start with bar.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE, + "Tells the slave thread to not replicate to the tables that match the given wildcard pattern. To specify more than one table to ignore, use the directive multiple times, once for each table. This will work for cross-database updates. Example: replicate-wild-ignore-table=foo%.bar% will not do updates to tables in databases that start with foo and whose table names start with bar.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, // In replication, we may need to tell the other servers how to connect {"report-host", OPT_REPORT_HOST, "Hostname or IP of the slave to be reported to to the master during slave registration. Will appear in the output of SHOW SLAVE HOSTS. Leave unset if you do not want the slave to register itself with the master. Note that it is not sufficient for the master to simply read the IP of the slave off the socket once the slave connects. Due to NAT and other routing issues, that IP may not be valid for connecting to the slave from the master or other hosts.", @@ -5791,6 +5756,11 @@ log and this option does nothing anymore.", "What size queue (in rows) should be allocated for handling INSERT DELAYED. If the queue becomes full, any client that does INSERT DELAYED will wait until there is room in the queue again.", (gptr*) &delayed_queue_size, (gptr*) &delayed_queue_size, 0, GET_ULONG, REQUIRED_ARG, DELAYED_QUEUE_SIZE, 1, ~0L, 0, 1, 0}, + {"div_precision_increment", OPT_DIV_PRECINCREMENT, + "Precision of the result of '/' operator will be increased on that value.", + (gptr*) &global_system_variables.div_precincrement, + (gptr*) &max_system_variables.div_precincrement, 0, GET_ULONG, + REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0}, {"expire_logs_days", OPT_EXPIRE_LOGS_DAYS, "If non-zero, binary logs will be purged after expire_logs_days " "days; possible purges happen at startup and at binary log rotation.", @@ -5846,6 +5816,10 @@ log and this option does nothing anymore.", (gptr*) &innobase_buffer_pool_size, (gptr*) &innobase_buffer_pool_size, 0, GET_LL, REQUIRED_ARG, 8*1024*1024L, 1024*1024L, LONGLONG_MAX, 0, 1024*1024L, 0}, + {"innodb_commit_concurrency", OPT_INNODB_THREAD_CONCURRENCY, + "Helps in performance tuning in heavily concurrent environments.", + (gptr*) &srv_commit_concurrency, (gptr*) &srv_commit_concurrency, + 0, GET_LONG, REQUIRED_ARG, 0, 0, 1000, 0, 1, 0}, {"innodb_concurrency_tickets", OPT_INNODB_CONCURRENCY_TICKETS, "Number of times a thread is allowed to enter InnoDB within the same \ SQL query after it has once got the ticket", @@ -5895,10 +5869,6 @@ log and this option does nothing anymore.", "Helps in performance tuning in heavily concurrent environments.", (gptr*) &srv_thread_concurrency, (gptr*) &srv_thread_concurrency, 0, GET_LONG, REQUIRED_ARG, 20, 1, 1000, 0, 1, 0}, - {"innodb_commit_concurrency", OPT_INNODB_THREAD_CONCURRENCY, - "Helps in performance tuning in heavily concurrent environments.", - (gptr*) &srv_commit_concurrency, (gptr*) &srv_commit_concurrency, - 0, GET_LONG, REQUIRED_ARG, 0, 0, 1000, 0, 1, 0}, {"innodb_thread_sleep_delay", OPT_INNODB_THREAD_SLEEP_DELAY, "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0" " disable a sleep", @@ -6019,6 +5989,11 @@ The minimum value for this variable is 4096.", (gptr*) &global_system_variables.max_sort_length, (gptr*) &max_system_variables.max_sort_length, 0, GET_ULONG, REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0}, + {"max_sp_recursion_depth", OPT_MAX_SP_RECURSION_DEPTH, + "Maximum stored procedure recursion depth. (discussed with docs).", + (gptr*) &global_system_variables.max_sp_recursion_depth, + (gptr*) &max_system_variables.max_sp_recursion_depth, 0, GET_ULONG, + OPT_ARG, 0, 0, 255, 0, 1, 0 }, {"max_tmp_tables", OPT_MAX_TMP_TABLES, "Maximum number of temporary tables a client can keep open at a time.", (gptr*) &global_system_variables.max_tmp_tables, @@ -6183,21 +6158,11 @@ The minimum value for this variable is 4096.", (gptr*) &max_system_variables.read_rnd_buff_size, 0, GET_ULONG, REQUIRED_ARG, 256*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ~0L, MALLOC_OVERHEAD, IO_SIZE, 0}, - {"div_precision_increment", OPT_DIV_PRECINCREMENT, - "Precision of the result of '/' operator will be increased on that value.", - (gptr*) &global_system_variables.div_precincrement, - (gptr*) &max_system_variables.div_precincrement, 0, GET_ULONG, - REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0}, {"record_buffer", OPT_RECORD_BUFFER, "Alias for read_buffer_size", (gptr*) &global_system_variables.read_buff_size, (gptr*) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG, 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ~0L, MALLOC_OVERHEAD, IO_SIZE, 0}, - {"max_sp_recursion_depth", OPT_MAX_SP_RECURSION_DEPTH, - "Maximum stored procedure recursion depth. (discussed with docs).", - (gptr*) &global_system_variables.max_sp_recursion_depth, - (gptr*) &max_system_variables.max_sp_recursion_depth, 0, GET_ULONG, - OPT_ARG, 0, 0, 255, 0, 1, 0 }, #ifdef HAVE_REPLICATION {"relay_log_purge", OPT_RELAY_LOG_PURGE, "0 = do not purge relay logs. 1 = purge them as soon as they are no more needed.", @@ -7070,6 +7035,7 @@ static void mysql_init_variables(void) max_system_variables.max_join_size= (ulonglong) HA_POS_ERROR; global_system_variables.old_passwords= 0; global_system_variables.old_alter_table= 0; + global_system_variables.binlog_format= BINLOG_FORMAT_UNSPEC; /* Default behavior for 4.1 and 5.0 is to treat NULL values as unequal when collecting index statistics for MyISAM tables. @@ -7314,18 +7280,19 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), #ifdef HAVE_ROW_BASED_REPLICATION fprintf(stderr, "Unknown binary log format: '%s' " - "(should be '%s' or '%s')\n", + "(should be one of '%s', '%s', '%s')\n", argument, - binlog_format_names[BF_STMT], - binlog_format_names[BF_ROW]); + binlog_format_names[BINLOG_FORMAT_STMT], + binlog_format_names[BINLOG_FORMAT_ROW], + binlog_format_names[BINLOG_FORMAT_MIXED]); #else fprintf(stderr, "Unknown binary log format: '%s' (only legal value is '%s')\n", - argument, binlog_format_names[BF_STMT]); + argument, binlog_format_names[BINLOG_FORMAT_STMT]); #endif exit(1); } - opt_binlog_format_id= (enum binlog_format)(id-1); + global_system_variables.binlog_format= id-1; break; } case (int)OPT_BINLOG_DO_DB: diff --git a/sql/net_serv.cc b/sql/net_serv.cc index ef56f0d77e2..c80bb8bad9a 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -208,23 +208,44 @@ my_bool net_realloc(NET *net, ulong length) RETURN VALUES 0 No data to read 1 Data or EOF to read + -1 Don't know if data is ready or not */ -static my_bool net_data_is_ready(my_socket sd) +static int net_data_is_ready(my_socket sd) { +#ifdef HAVE_POLL + struct pollfd ufds; + int res; + + ufds.fd= sd; + ufds.events= POLLIN | POLLPRI; + if (!(res= poll(&ufds, 1, 0))) + return 0; + if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI))) + return 0; + return 1; +#else fd_set sfds; struct timeval tv; int res; +#ifndef __WIN__ + /* Windows uses an _array_ of 64 fd's as default, so it's safe */ + if (sd >= FD_SETSIZE) + return -1; +#define NET_DATA_IS_READY_CAN_RETURN_MINUS_ONE +#endif + FD_ZERO(&sfds); FD_SET(sd, &sfds); tv.tv_sec= tv.tv_usec= 0; if ((res= select(sd+1, &sfds, NULL, NULL, &tv)) < 0) - return FALSE; + return 0; else return test(res ? FD_ISSET(sd, &sfds) : 0); +#endif } @@ -251,10 +272,10 @@ static my_bool net_data_is_ready(my_socket sd) void net_clear(NET *net) { - int count; + int count, ready; DBUG_ENTER("net_clear"); #if !defined(EMBEDDED_LIBRARY) - while(net_data_is_ready(net->vio->sd)) + while((ready= net_data_is_ready(net->vio->sd)) > 0) { /* The socket is ready */ if ((count= vio_read(net->vio, (char*) (net->buff), @@ -274,6 +295,22 @@ void net_clear(NET *net) break; } } +#ifdef NET_DATA_IS_READY_CAN_RETURN_MINUS_ONE + /* 'net_data_is_ready' returned "don't know" */ + if (ready == -1) + { + /* Read unblocking to clear net */ + my_bool old_mode; + if (!vio_blocking(net->vio, FALSE, &old_mode)) + { + while ((count= vio_read(net->vio, (char*) (net->buff), + (uint32) net->max_packet)) > 0) + DBUG_PRINT("info",("skipped %d bytes from file: %s", + count, vio_description(net->vio))); + vio_blocking(net->vio, TRUE, &old_mode); + } + } +#endif #endif net->pkt_nr=net->compress_pkt_nr=0; /* Ready for new command */ net->write_pos=net->buff; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 1146ea2428d..e42be40be81 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1601,6 +1601,8 @@ public: { return (void*) alloc_root(mem_root, (uint) size); } static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); } static void operator delete(void *ptr, MEM_ROOT *mem_root) { /* Never called */ } + virtual ~TABLE_READ_PLAN() {} /* Remove gcc warning */ + }; class TRP_ROR_INTERSECT; @@ -1624,6 +1626,7 @@ public: TRP_RANGE(SEL_ARG *key_arg, uint idx_arg) : key(key_arg), key_idx(idx_arg) {} + virtual ~TRP_RANGE() {} /* Remove gcc warning */ QUICK_SELECT_I *make_quick(PARAM *param, bool retrieve_full_rows, MEM_ROOT *parent_alloc) @@ -1645,6 +1648,8 @@ public: class TRP_ROR_INTERSECT : public TABLE_READ_PLAN { public: + TRP_ROR_INTERSECT() {} /* Remove gcc warning */ + virtual ~TRP_ROR_INTERSECT() {} /* Remove gcc warning */ QUICK_SELECT_I *make_quick(PARAM *param, bool retrieve_full_rows, MEM_ROOT *parent_alloc); @@ -1666,6 +1671,8 @@ public: class TRP_ROR_UNION : public TABLE_READ_PLAN { public: + TRP_ROR_UNION() {} /* Remove gcc warning */ + virtual ~TRP_ROR_UNION() {} /* Remove gcc warning */ QUICK_SELECT_I *make_quick(PARAM *param, bool retrieve_full_rows, MEM_ROOT *parent_alloc); TABLE_READ_PLAN **first_ror; /* array of ptrs to plans for merged scans */ @@ -1682,6 +1689,8 @@ public: class TRP_INDEX_MERGE : public TABLE_READ_PLAN { public: + TRP_INDEX_MERGE() {} /* Remove gcc warning */ + virtual ~TRP_INDEX_MERGE() {} /* Remove gcc warning */ QUICK_SELECT_I *make_quick(PARAM *param, bool retrieve_full_rows, MEM_ROOT *parent_alloc); TRP_RANGE **range_scans; /* array of ptrs to plans of merged scans */ @@ -1731,6 +1740,7 @@ public: if (key_infix_len) memcpy(this->key_infix, key_infix_arg, key_infix_len); } + virtual ~TRP_GROUP_MIN_MAX() {} /* Remove gcc warning */ QUICK_SELECT_I *make_quick(PARAM *param, bool retrieve_full_rows, MEM_ROOT *parent_alloc); @@ -2979,7 +2989,7 @@ static bool create_partition_index_description(PART_PRUNE_PARAM *ppar) ppar->last_subpart_partno= used_subpart_fields?(int)(used_part_fields + used_subpart_fields - 1): -1; - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { ppar->mark_full_partition_used= mark_full_partition_used_with_parts; ppar->get_top_partition_id_func= part_info->get_part_partition_id; @@ -3108,7 +3118,7 @@ static void dbug_print_segment_range(SEL_ARG *arg, KEY_PART *part) fputs(" < ", DBUG_FILE); else fputs(" <= ", DBUG_FILE); - store_key_image_to_rec(part->field, (char*)(arg->min_value), part->length); + store_key_image_to_rec(part->field, (char*)(arg->max_value), part->length); dbug_print_field(part->field); } fputs("\n", DBUG_FILE); diff --git a/sql/parse_file.h b/sql/parse_file.h index afa88da2ead..0d5a215fe1a 100644 --- a/sql/parse_file.h +++ b/sql/parse_file.h @@ -49,6 +49,8 @@ struct File_option class Unknown_key_hook { public: + Unknown_key_hook() {} /* Remove gcc warning */ + virtual ~Unknown_key_hook() {} /* Remove gcc warning */ virtual bool process_unknown_string(char *&unknown_key, gptr base, MEM_ROOT *mem_root, char *end)= 0; }; @@ -59,6 +61,7 @@ public: class File_parser_dummy_hook: public Unknown_key_hook { public: + File_parser_dummy_hook() {} /* Remove gcc warning */ virtual bool process_unknown_string(char *&unknown_key, gptr base, MEM_ROOT *mem_root, char *end); }; diff --git a/sql/partition_element.h b/sql/partition_element.h new file mode 100644 index 00000000000..8a11c332897 --- /dev/null +++ b/sql/partition_element.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2000,200666666 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + 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; either version 2 of the License, or + (at your option) any later version. + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** + * An enum and a struct to handle partitioning and subpartitioning. + */ +enum partition_type { + NOT_A_PARTITION= 0, + RANGE_PARTITION, + HASH_PARTITION, + LIST_PARTITION +}; + +enum partition_state { + PART_NORMAL= 0, + PART_IS_DROPPED= 1, + PART_TO_BE_DROPPED= 2, + PART_TO_BE_ADDED= 3, + PART_TO_BE_REORGED= 4, + PART_REORGED_DROPPED= 5, + PART_CHANGED= 6, + PART_IS_CHANGED= 7, + PART_IS_ADDED= 8 +}; + +class partition_element :public Sql_alloc { +public: + List<partition_element> subpartitions; + List<longlong> list_val_list; + ulonglong part_max_rows; + ulonglong part_min_rows; + char *partition_name; + char *tablespace_name; + longlong range_value; + char* part_comment; + char* data_file_name; + char* index_file_name; + handlerton *engine_type; + enum partition_state part_state; + uint16 nodegroup_id; + + partition_element() + : part_max_rows(0), part_min_rows(0), partition_name(NULL), + tablespace_name(NULL), range_value(0), part_comment(NULL), + data_file_name(NULL), index_file_name(NULL), + engine_type(NULL),part_state(PART_NORMAL), + nodegroup_id(UNDEF_NODEGROUP) + { + subpartitions.empty(); + list_val_list.empty(); + } + ~partition_element() {} +}; diff --git a/sql/partition_info.cc b/sql/partition_info.cc new file mode 100644 index 00000000000..66e0d366116 --- /dev/null +++ b/sql/partition_info.cc @@ -0,0 +1,349 @@ +/* Copyright (C) 2006 MySQL AB + + 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; either version 2 of the License, or + (at your option) any later version. + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Some general useful functions */ + +#ifdef USE_PRAGMA_IMPLEMENTATION +#pragma implementation +#endif + +#include "mysql_priv.h" +#include "ha_partition.h" + +#ifdef WITH_PARTITION_STORAGE_ENGINE + + +/* + Create a memory area where default partition names are stored and fill it + up with the names. + + SYNOPSIS + create_default_partition_names() + part_no Partition number for subparts + no_parts Number of partitions + start_no Starting partition number + subpart Is it subpartitions + + RETURN VALUE + A pointer to the memory area of the default partition names + + DESCRIPTION + A support routine for the partition code where default values are + generated. + The external routine needing this code is check_partition_info +*/ + +#define MAX_PART_NAME_SIZE 16 + +char *partition_info::create_default_partition_names(uint part_no, uint no_parts, + uint start_no, bool is_subpart) +{ + char *ptr= sql_calloc(no_parts*MAX_PART_NAME_SIZE); + char *move_ptr= ptr; + uint i= 0; + DBUG_ENTER("create_default_partition_names"); + + if (likely(ptr != 0)) + { + do + { + if (is_subpart) + my_sprintf(move_ptr, (move_ptr,"p%usp%u", part_no, (start_no + i))); + else + my_sprintf(move_ptr, (move_ptr,"p%u", (start_no + i))); + move_ptr+=MAX_PART_NAME_SIZE; + } while (++i < no_parts); + } + else + { + mem_alloc_error(no_parts*MAX_PART_NAME_SIZE); + } + DBUG_RETURN(ptr); +} + + +/* + Set up all the default partitions not set-up by the user in the SQL + statement. Also perform a number of checks that the user hasn't tried + to use default values where no defaults exists. + + SYNOPSIS + set_up_default_partitions() + part_info The reference to all partition information + file A reference to a handler of the table + max_rows Maximum number of rows stored in the table + start_no Starting partition number + + RETURN VALUE + TRUE Error, attempted default values not possible + FALSE Ok, default partitions set-up + + DESCRIPTION + The routine uses the underlying handler of the partitioning to define + the default number of partitions. For some handlers this requires + knowledge of the maximum number of rows to be stored in the table. + This routine only accepts HASH and KEY partitioning and thus there is + no subpartitioning if this routine is successful. + The external routine needing this code is check_partition_info +*/ + +bool partition_info::set_up_default_partitions(handler *file, ulonglong max_rows, + uint start_no) +{ + uint i; + char *default_name; + bool result= TRUE; + DBUG_ENTER("partition_info::set_up_default_partitions"); + + if (part_type != HASH_PARTITION) + { + const char *error_string; + if (part_type == RANGE_PARTITION) + error_string= partition_keywords[PKW_RANGE].str; + else + error_string= partition_keywords[PKW_LIST].str; + my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), error_string); + goto end; + } + if (no_parts == 0) + no_parts= file->get_default_no_partitions(max_rows); + if (unlikely(no_parts > MAX_PARTITIONS)) + { + my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); + goto end; + } + if (unlikely((!(default_name= create_default_partition_names(0, no_parts, + start_no, + FALSE))))) + goto end; + i= 0; + do + { + partition_element *part_elem= new partition_element(); + if (likely(part_elem != 0 && + (!partitions.push_back(part_elem)))) + { + part_elem->engine_type= default_engine_type; + part_elem->partition_name= default_name; + default_name+=MAX_PART_NAME_SIZE; + } + else + { + mem_alloc_error(sizeof(partition_element)); + goto end; + } + } while (++i < no_parts); + result= FALSE; +end: + DBUG_RETURN(result); +} + + +/* + Set up all the default subpartitions not set-up by the user in the SQL + statement. Also perform a number of checks that the default partitioning + becomes an allowed partitioning scheme. + + SYNOPSIS + set_up_default_subpartitions() + part_info The reference to all partition information + file A reference to a handler of the table + max_rows Maximum number of rows stored in the table + + RETURN VALUE + TRUE Error, attempted default values not possible + FALSE Ok, default partitions set-up + + DESCRIPTION + The routine uses the underlying handler of the partitioning to define + the default number of partitions. For some handlers this requires + knowledge of the maximum number of rows to be stored in the table. + This routine is only called for RANGE or LIST partitioning and those + need to be specified so only subpartitions are specified. + The external routine needing this code is check_partition_info +*/ + +bool partition_info::set_up_default_subpartitions(handler *file, + ulonglong max_rows) +{ + uint i, j; + char *default_name, *name_ptr; + bool result= TRUE; + partition_element *part_elem; + List_iterator<partition_element> part_it(partitions); + DBUG_ENTER("partition_info::set_up_default_subpartitions"); + + if (no_subparts == 0) + no_subparts= file->get_default_no_partitions(max_rows); + if (unlikely((no_parts * no_subparts) > MAX_PARTITIONS)) + { + my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); + goto end; + } + i= 0; + do + { + part_elem= part_it++; + j= 0; + name_ptr= create_default_partition_names(i, no_subparts, (uint)0, TRUE); + if (unlikely(!name_ptr)) + goto end; + do + { + partition_element *subpart_elem= new partition_element(); + if (likely(subpart_elem != 0 && + (!part_elem->subpartitions.push_back(subpart_elem)))) + { + subpart_elem->engine_type= default_engine_type; + subpart_elem->partition_name= name_ptr; + name_ptr+= MAX_PART_NAME_SIZE; + } + else + { + mem_alloc_error(sizeof(partition_element)); + goto end; + } + } while (++j < no_subparts); + } while (++i < no_parts); + result= FALSE; +end: + DBUG_RETURN(result); +} + + +/* + Support routine for check_partition_info + + SYNOPSIS + set_up_defaults_for_partitioning() + part_info The reference to all partition information + file A reference to a handler of the table + max_rows Maximum number of rows stored in the table + start_no Starting partition number + + RETURN VALUE + TRUE Error, attempted default values not possible + FALSE Ok, default partitions set-up + + DESCRIPTION + Set up defaults for partition or subpartition (cannot set-up for both, + this will return an error. +*/ + +bool partition_info::set_up_defaults_for_partitioning(handler *file, + ulonglong max_rows, + uint start_no) +{ + DBUG_ENTER("partition_info::set_up_defaults_for_partitioning"); + + if (!default_partitions_setup) + { + default_partitions_setup= TRUE; + if (use_default_partitions) + DBUG_RETURN(set_up_default_partitions(file, max_rows, start_no)); + if (is_sub_partitioned() && + use_default_subpartitions) + DBUG_RETURN(set_up_default_subpartitions(file, max_rows)); + } + DBUG_RETURN(FALSE); +} + + +/* + A support function to check if a partition element's name is unique + + SYNOPSIS + has_unique_name() + partition_element element to check + + RETURN VALUES + TRUE Has unique name + FALSE Doesn't +*/ + +bool partition_info::has_unique_name(partition_element *element) +{ + DBUG_ENTER("partition_info::has_unique_name"); + + const char *name_to_check= element->partition_name; + List_iterator<partition_element> parts_it(partitions); + + partition_element *el; + while ((el= (parts_it++))) + { + if (!(my_strcasecmp(system_charset_info, el->partition_name, + name_to_check)) && el != element) + DBUG_RETURN(FALSE); + + if (!el->subpartitions.is_empty()) + { + partition_element *sub_el; + List_iterator<partition_element> subparts_it(el->subpartitions); + while ((sub_el= (subparts_it++))) + { + if (!(my_strcasecmp(system_charset_info, sub_el->partition_name, + name_to_check)) && sub_el != element) + DBUG_RETURN(FALSE); + } + } + } + DBUG_RETURN(TRUE); +} + + +/* + A support function to check partition names for duplication in a + partitioned table + + SYNOPSIS + has_unique_names() + + RETURN VALUES + TRUE Has unique part and subpart names + FALSE Doesn't + + DESCRIPTION + Checks that the list of names in the partitions doesn't contain any + duplicated names. +*/ + +char *partition_info::has_unique_names() +{ + DBUG_ENTER("partition_info::has_unique_names"); + + List_iterator<partition_element> parts_it(partitions); + + partition_element *el; + while ((el= (parts_it++))) + { + if (! has_unique_name(el)) + DBUG_RETURN(el->partition_name); + + if (!el->subpartitions.is_empty()) + { + List_iterator<partition_element> subparts_it(el->subpartitions); + partition_element *subel; + while ((subel= (subparts_it++))) + { + if (! has_unique_name(subel)) + DBUG_RETURN(subel->partition_name); + } + } + } + DBUG_RETURN(NULL); +} + +#endif /* WITH_PARTITION_STORAGE_ENGINE */ diff --git a/sql/partition_info.h b/sql/partition_info.h new file mode 100644 index 00000000000..c8cb4ae407a --- /dev/null +++ b/sql/partition_info.h @@ -0,0 +1,271 @@ +/* Copyright (C) 2000,2006 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + 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; either version 2 of the License, or + (at your option) any later version. + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifdef USE_PRAGMA_INTERFACE +#pragma interface /* gcc class implementation */ +#endif + +#include "partition_element.h" + +class partition_info; + +/* Some function typedefs */ +typedef int (*get_part_id_func)(partition_info *part_info, + uint32 *part_id, + longlong *func_value); +typedef uint32 (*get_subpart_id_func)(partition_info *part_info); + + + +class partition_info : public Sql_alloc +{ +public: + /* + * Here comes a set of definitions needed for partitioned table handlers. + */ + List<partition_element> partitions; + List<partition_element> temp_partitions; + + List<char> part_field_list; + List<char> subpart_field_list; + + /* + If there is no subpartitioning, use only this func to get partition ids. + If there is subpartitioning, use the this func to get partition id when + you have both partition and subpartition fields. + */ + get_part_id_func get_partition_id; + + /* Get partition id when we don't have subpartition fields */ + get_part_id_func get_part_partition_id; + + /* + Get subpartition id when we have don't have partition fields by we do + have subpartition ids. + Mikael said that for given constant tuple + {subpart_field1, ..., subpart_fieldN} the subpartition id will be the + same in all subpartitions + */ + get_subpart_id_func get_subpartition_id; + + /* NULL-terminated array of fields used in partitioned expression */ + Field **part_field_array; + /* NULL-terminated array of fields used in subpartitioned expression */ + Field **subpart_field_array; + + /* + Array of all fields used in partition and subpartition expression, + without duplicates, NULL-terminated. + */ + Field **full_part_field_array; + + Item *part_expr; + Item *subpart_expr; + + Item *item_free_list; + + /* + A bitmap of partitions used by the current query. + Usage pattern: + * The handler->extra(HA_EXTRA_RESET) call at query start/end sets all + partitions to be unused. + * Before index/rnd_init(), partition pruning code sets the bits for used + partitions. + */ + MY_BITMAP used_partitions; + + union { + longlong *range_int_array; + LIST_PART_ENTRY *list_array; + }; + + /******************************************** + * INTERVAL ANALYSIS + ********************************************/ + /* + Partitioning interval analysis function for partitioning, or NULL if + interval analysis is not supported for this kind of partitioning. + */ + get_partitions_in_range_iter get_part_iter_for_interval; + /* + Partitioning interval analysis function for subpartitioning, or NULL if + interval analysis is not supported for this kind of partitioning. + */ + get_partitions_in_range_iter get_subpart_iter_for_interval; + + /* + Valid iff + get_part_iter_for_interval=get_part_iter_for_interval_via_walking: + controls how we'll process "field < C" and "field > C" intervals. + If the partitioning function F is strictly increasing, then for any x, y + "x < y" => "F(x) < F(y)" (*), i.e. when we get interval "field < C" + we can perform partition pruning on the equivalent "F(field) < F(C)". + + If the partitioning function not strictly increasing (it is simply + increasing), then instead of (*) we get "x < y" => "F(x) <= F(y)" + i.e. for interval "field < C" we can perform partition pruning for + "F(field) <= F(C)". + */ + bool range_analysis_include_bounds; + /******************************************** + * INTERVAL ANALYSIS ENDS + ********************************************/ + + char* part_info_string; + + char *part_func_string; + char *subpart_func_string; + + uchar *part_state; + + partition_element *curr_part_elem; + partition_element *current_partition; + /* + These key_map's are used for Partitioning to enable quick decisions + on whether we can derive more information about which partition to + scan just by looking at what index is used. + */ + key_map all_fields_in_PF, all_fields_in_PPF, all_fields_in_SPF; + key_map some_fields_in_PF; + + handlerton *default_engine_type; + Item_result part_result_type; + partition_type part_type; + partition_type subpart_type; + + uint part_info_len; + uint part_state_len; + uint part_func_len; + uint subpart_func_len; + + uint no_parts; + uint no_subparts; + uint count_curr_subparts; + + uint part_error_code; + + uint no_list_values; + + uint no_part_fields; + uint no_subpart_fields; + uint no_full_part_fields; + + /* + This variable is used to calculate the partition id when using + LINEAR KEY/HASH. This functionality is kept in the MySQL Server + but mainly of use to handlers supporting partitioning. + */ + uint16 linear_hash_mask; + + bool use_default_partitions; + bool use_default_no_partitions; + bool use_default_subpartitions; + bool use_default_no_subpartitions; + bool default_partitions_setup; + bool defined_max_value; + bool list_of_part_fields; + bool list_of_subpart_fields; + bool linear_hash_ind; + bool fixed; + bool from_openfrm; + + partition_info() + : get_partition_id(NULL), get_part_partition_id(NULL), + get_subpartition_id(NULL), + part_field_array(NULL), subpart_field_array(NULL), + full_part_field_array(NULL), + part_expr(NULL), subpart_expr(NULL), item_free_list(NULL), + list_array(NULL), + part_info_string(NULL), + part_func_string(NULL), subpart_func_string(NULL), + part_state(NULL), + curr_part_elem(NULL), current_partition(NULL), + default_engine_type(NULL), + part_result_type(INT_RESULT), + part_type(NOT_A_PARTITION), subpart_type(NOT_A_PARTITION), + part_info_len(0), part_state_len(0), + part_func_len(0), subpart_func_len(0), + no_parts(0), no_subparts(0), + count_curr_subparts(0), part_error_code(0), + no_list_values(0), no_part_fields(0), no_subpart_fields(0), + no_full_part_fields(0), linear_hash_mask(0), + use_default_partitions(TRUE), + use_default_no_partitions(TRUE), + use_default_subpartitions(TRUE), + use_default_no_subpartitions(TRUE), + default_partitions_setup(FALSE), + defined_max_value(FALSE), + list_of_part_fields(FALSE), list_of_subpart_fields(FALSE), + linear_hash_ind(FALSE), + fixed(FALSE), + from_openfrm(FALSE) + { + all_fields_in_PF.clear_all(); + all_fields_in_PPF.clear_all(); + all_fields_in_SPF.clear_all(); + some_fields_in_PF.clear_all(); + partitions.empty(); + temp_partitions.empty(); + part_field_list.empty(); + subpart_field_list.empty(); + } + ~partition_info() {} + + /* Answers the question if subpartitioning is used for a certain table */ + bool is_sub_partitioned() + { + return (subpart_type == NOT_A_PARTITION ? FALSE : TRUE); + } + + /* Returns the total number of partitions on the leaf level */ + uint get_tot_partitions() + { + return no_parts * (is_sub_partitioned() ? no_subparts : 1); + } + + bool set_up_defaults_for_partitioning(handler *file, ulonglong max_rows, + uint start_no); + char *has_unique_names(); +private: + bool set_up_default_partitions(handler *file, ulonglong max_rows, + uint start_no); + bool set_up_default_subpartitions(handler *file, ulonglong max_rows); + char *create_default_partition_names(uint part_no, uint no_parts, + uint start_no, bool is_subpart); + bool has_unique_name(partition_element *element); +}; + +uint32 get_next_partition_id_range(struct st_partition_iter* part_iter); + +/* Initialize the iterator to return a single partition with given part_id */ + +static inline void init_single_partition_iterator(uint32 part_id, + PARTITION_ITERATOR *part_iter) +{ + part_iter->part_nums.start= part_id; + part_iter->part_nums.end= part_id+1; + part_iter->get_next= get_next_partition_id_range; +} + +/* Initialize the iterator to enumerate all partitions */ +static inline +void init_all_partitions_iterator(partition_info *part_info, + PARTITION_ITERATOR *part_iter) +{ + part_iter->part_nums.start= 0; + part_iter->part_nums.end= part_info->no_parts; + part_iter->get_next= get_next_partition_id_range; +} diff --git a/sql/set_var.cc b/sql/set_var.cc index 12f3a61aa4e..bf3fdd8c8d7 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -141,6 +141,7 @@ static int check_log_update(THD *thd, set_var *var); static bool set_log_update(THD *thd, set_var *var); static int check_pseudo_thread_id(THD *thd, set_var *var); static bool set_log_bin(THD *thd, set_var *var); +void fix_binlog_format_after_update(THD *thd, enum_var_type type); static void fix_low_priority_updates(THD *thd, enum_var_type type); static int check_tx_isolation(THD *thd, set_var *var); static void fix_tx_isolation(THD *thd, enum_var_type type); @@ -185,6 +186,8 @@ sys_var_bool_ptr sys_automatic_sp_privileges("automatic_sp_privileges", sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size", &binlog_cache_size); +sys_var_thd_binlog_format sys_binlog_format("binlog_format", + &SV::binlog_format); sys_var_thd_ulong sys_bulk_insert_buff_size("bulk_insert_buffer_size", &SV::bulk_insert_buff_size); sys_var_character_set_server sys_character_set_server("character_set_server"); @@ -653,11 +656,11 @@ static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff) var->value= buff; if (!use_slave_mask || bitmap_is_clear_all(&slave_error_mask)) { - var->value= "OFF"; + var->value= const_cast<char *>("OFF"); } else if (bitmap_is_set_all(&slave_error_mask)) { - var->value= "ALL"; + var->value= const_cast<char *>("ALL"); } else { @@ -706,7 +709,7 @@ SHOW_VAR init_vars[]= { {"bdb_shared_data", (char*) &berkeley_shared_data, SHOW_BOOL}, {"bdb_tmpdir", (char*) &berkeley_tmpdir, SHOW_CHAR_PTR}, {sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size, SHOW_SYS}, - {"binlog_format", (char*) &opt_binlog_format, SHOW_CHAR_PTR}, + {sys_binlog_format.name, (char*) &sys_binlog_format, SHOW_SYS}, {sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS}, {sys_character_set_client.name,(char*) &sys_character_set_client, SHOW_SYS}, {sys_character_set_connection.name,(char*) &sys_character_set_connection,SHOW_SYS}, @@ -1243,6 +1246,54 @@ extern void fix_delay_key_write(THD *thd, enum_var_type type) } } + +bool sys_var_thd_binlog_format::is_readonly() const +{ + /* + Under certain circumstances, the variable is read-only (unchangeable): + */ + THD *thd= current_thd; + /* + If RBR and open temporary tables, their CREATE TABLE may not be in the + binlog, so we can't toggle to SBR in this connection. + The test below will also prevent SET GLOBAL, well it was not easy to test + if global or not here. + And this test will also prevent switching from RBR to RBR (a no-op which + should not happen too often). + */ + if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) && + thd->temporary_tables) + { + my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0)); + return 1; + } + /* + if in a stored function, it's too late to change mode + */ + if (thd->spcont && thd->prelocked_mode) + { + DBUG_ASSERT(thd->variables.binlog_format != BINLOG_FORMAT_ROW); + my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0)); + return 1; + } +#ifdef HAVE_NDB_BINLOG + /* + Cluster does not support changing the binlog format on the fly yet. + */ + if (opt_bin_log && (have_ndbcluster == SHOW_OPTION_YES)) + { + my_error(ER_NDB_CANT_SWITCH_BINLOG_FORMAT, MYF(0)); + return 1; + } +#endif + return sys_var_thd_enum::is_readonly(); +} + +void fix_binlog_format_after_update(THD *thd, enum_var_type type) +{ + thd->reset_current_stmt_binlog_row_based(); +} + static void fix_max_binlog_size(THD *thd, enum_var_type type) { DBUG_ENTER("fix_max_binlog_size"); @@ -2724,7 +2775,7 @@ static bool set_log_update(THD *thd, set_var *var) See sql/mysqld.cc/, comments in function init_server_components() for an explaination of the different warnings we send below */ - + if (opt_sql_bin_update) { ((sys_var_thd_bit*) var->var)->bit_flag|= (OPTION_BIN_LOG | @@ -3205,10 +3256,7 @@ bool sys_var_thd_storage_engine::update(THD *thd, set_var *var) void sys_var_thd_table_type::warn_deprecated(THD *thd) { - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_SYNTAX, - ER(ER_WARN_DEPRECATED_SYNTAX), "table_type", - "storage_engine"); + WARN_DEPRECATED(thd, "5.2", "table_type", "'storage_engine'"); } void sys_var_thd_table_type::set_default(THD *thd, enum_var_type type) @@ -3465,10 +3513,8 @@ bool process_key_caches(int (* func) (const char *name, KEY_CACHE *)) void sys_var_trust_routine_creators::warn_deprecated(THD *thd) { - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_SYNTAX, - ER(ER_WARN_DEPRECATED_SYNTAX), "log_bin_trust_routine_creators", - "log_bin_trust_function_creators"); + WARN_DEPRECATED(thd, "5.2", "log_bin_trust_routine_creators", + "'log_bin_trust_function_creators'"); } void sys_var_trust_routine_creators::set_default(THD *thd, enum_var_type type) diff --git a/sql/set_var.h b/sql/set_var.h index 0961f6d4325..f62d6ce8d2a 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -826,6 +826,18 @@ public: bool update(THD *thd, set_var *var); }; +extern void fix_binlog_format_after_update(THD *thd, enum_var_type type); + +class sys_var_thd_binlog_format :public sys_var_thd_enum +{ +public: + sys_var_thd_binlog_format(const char *name_arg, ulong SV::*offset_arg) + :sys_var_thd_enum(name_arg, offset_arg, + &binlog_format_typelib, + fix_binlog_format_after_update) + {}; + bool is_readonly() const; +}; /**************************************************************************** Classes for parsing of the SET command diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 35ff2e4222b..d163da30e95 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5018,7 +5018,7 @@ ER_UNKNOWN_STORAGE_ENGINE 42000 ger "Unbekannte Speicher-Engine '%s'" por "Motor de tabela desconhecido '%s'" spa "Desconocido motor de tabla '%s'" -ER_WARN_DEPRECATED_SYNTAX +ER_UNUSED_1 eng "'%s' is deprecated; use '%s' instead" ger "'%s' ist veraltet. Bitte benutzen Sie '%s'" por "'%s' é desatualizado. Use '%s' em seu lugar" @@ -5660,8 +5660,8 @@ ER_PARTITION_NOT_DEFINED_ERROR eng "For the partitioned engine it is necessary to define all %-.64s" swe "För partitioneringsmotorn så är det nödvändigt att definiera alla %-.64s" ER_TOO_MANY_PARTITIONS_ERROR - eng "Too many partitions were defined" - swe "För många partitioner definierades" + eng "Too many partitions (including subpartitions) were defined" + swe "För många partitioner (inkluderande subpartitioner) definierades" ER_SUBPARTITION_ERROR eng "It is only possible to mix RANGE/LIST partitioning with HASH/KEY partitioning for subpartitioning" swe "Det är endast möjligt att blanda RANGE/LIST partitionering med HASH/KEY partitionering för subpartitionering" @@ -5781,7 +5781,7 @@ ER_EVENT_NEITHER_M_EXPR_NOR_M_AT eng "No datetime expression provided" ER_COL_COUNT_DOESNT_MATCH_CORRUPTED eng "Column count of mysql.%s is wrong. Expected %d, found %d. Table probably corrupted" -ER_EVENT_CANNOT_LOAD_FROM_TABLE +ER_CANNOT_LOAD_FROM_TABLE eng "Cannot load from mysql.%s. Table probably corrupted. See error log." ER_EVENT_CANNOT_DELETE eng "Failed to delete the event from mysql.event" @@ -5810,6 +5810,14 @@ ER_ILLEGAL_HA_CREATE_OPTION eng "Table storage engine '%-.64s' does not support the create option '%.64s'" ER_CANT_CHANGE_TX_ISOLATION 25001 eng "Transaction isolation level can't be changed while a transaction is in progress" -ER_WARN_DEPRECATED_STATEMENT - eng "The '%s' statement is deprecated and will be removed in MySQL %s. Please use client programs (e.g. %s) instead." +ER_WARN_DEPRECATED + eng "The syntax '%s' is deprecated and will be removed in MySQL %s. Please use %s instead." +ER_SP_NO_AGGREGATE 42000 + eng "AGGREGATE is not supported for stored functions" +ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR + eng "Cannot switch out of the row-based binary log format when the session has open temporary tables" +ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT + eng "Cannot change the binary logging format inside a stored function or trigger" +ER_NDB_CANT_SWITCH_BINLOG_FORMAT + eng "The NDB cluster engine does not support changing the binlog format on the fly yet" diff --git a/sql/sp.cc b/sql/sp.cc index 4838f839b4e..481d81edfe4 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1013,6 +1013,7 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error) { TABLE_LIST *routine; bool result= 0; + bool sp_object_found; DBUG_ENTER("sp_exists_routine"); for (routine= routines; routine; routine= routine->next_global) { @@ -1025,10 +1026,12 @@ sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error) lex_name.str= thd->strmake(routine->table_name, lex_name.length); name= new sp_name(lex_db, lex_name); name->init_qname(thd); - if (sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name, - &thd->sp_proc_cache, FALSE) != NULL || - sp_find_routine(thd, TYPE_ENUM_FUNCTION, name, - &thd->sp_func_cache, FALSE) != NULL) + sp_object_found= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name, + &thd->sp_proc_cache, FALSE) != NULL || + sp_find_routine(thd, TYPE_ENUM_FUNCTION, name, + &thd->sp_func_cache, FALSE) != NULL; + mysql_reset_errors(thd, TRUE); + if (sp_object_found) { if (any) DBUG_RETURN(1); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 1f29468a61f..d7490a5ac8e 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1301,7 +1301,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, each substatement be binlogged its way. */ need_binlog_call= mysql_bin_log.is_open() && - (thd->options & OPTION_BIN_LOG) && !binlog_row_based; + (thd->options & OPTION_BIN_LOG) && !thd->current_stmt_binlog_row_based; if (need_binlog_call) { reset_dynamic(&thd->user_var_events); @@ -1412,6 +1412,8 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) uint params = m_pcont->context_pvars(); sp_rcontext *save_spcont, *octx; sp_rcontext *nctx = NULL; + bool save_enable_slow_log= false; + bool save_log_general= false; DBUG_ENTER("sp_head::execute_procedure"); DBUG_PRINT("info", ("procedure %s", m_name.str)); @@ -1510,12 +1512,28 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) DBUG_PRINT("info",(" %.*s: eval args done", m_name.length, m_name.str)); } - + if (!(m_flags & LOG_SLOW_STATEMENTS) && thd->enable_slow_log) + { + DBUG_PRINT("info", ("Disabling slow log for the execution")); + save_enable_slow_log= true; + thd->enable_slow_log= FALSE; + } + if (!(m_flags & LOG_GENERAL_LOG) && !(thd->options & OPTION_LOG_OFF)) + { + DBUG_PRINT("info", ("Disabling general log for the execution")); + save_log_general= true; + /* disable this bit */ + thd->options |= OPTION_LOG_OFF; + } thd->spcont= nctx; - + if (!err_status) err_status= execute(thd); + if (save_log_general) + thd->options &= ~OPTION_LOG_OFF; + if (save_enable_slow_log) + thd->enable_slow_log= true; /* In the case when we weren't able to employ reuse mechanism for OUT/INOUT paranmeters, we should reallocate memory. This @@ -1621,6 +1639,8 @@ sp_head::reset_lex(THD *thd) sublex->trg_table_fields.empty(); sublex->sp_lex_in_use= FALSE; + sublex->in_comment= oldlex->in_comment; + /* Reset type info. */ sublex->charset= NULL; @@ -2292,10 +2312,15 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) (the order of query cache and subst_spvars calls is irrelevant because queries with SP vars can't be cached) */ + if (unlikely((thd->options & OPTION_LOG_OFF)==0)) + general_log_print(thd, COM_QUERY, "%s", thd->query); + if (query_cache_send_result_to_client(thd, thd->query, thd->query_length) <= 0) { res= m_lex_keeper.reset_lex_and_exec_core(thd, nextp, FALSE, this); + if (!res && unlikely(thd->enable_slow_log)) + log_slow_statement(thd); query_cache_end_of_result(thd); } else diff --git a/sql/sp_head.h b/sql/sp_head.h index a637c466041..472e5343991 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -124,7 +124,9 @@ public: IS_INVOKED= 32, // Is set if this sp_head is being used HAS_SET_AUTOCOMMIT_STMT= 64,// Is set if a procedure with 'set autocommit' /* Is set if a procedure with COMMIT (implicit or explicit) | ROLLBACK */ - HAS_COMMIT_OR_ROLLBACK= 128 + HAS_COMMIT_OR_ROLLBACK= 128, + LOG_SLOW_STATEMENTS= 256, // Used by events + LOG_GENERAL_LOG= 512 // Used by events }; /* TYPE_ENUM_FUNCTION, TYPE_ENUM_PROCEDURE or TYPE_ENUM_TRIGGER */ diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index c3c05228eef..e7393902e72 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -268,6 +268,7 @@ class Select_fetch_into_spvars: public select_result_interceptor List<struct sp_pvar> *spvar_list; uint field_count; public: + Select_fetch_into_spvars() {} /* Remove gcc warning */ uint get_field_count() { return field_count; } void set_spvar_list(List<struct sp_pvar> *vars) { spvar_list= vars; } diff --git a/sql/spatial.h b/sql/spatial.h index 527dc750bdc..a6f74a1ada0 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -165,6 +165,8 @@ struct Geometry_buffer; class Geometry { public: + Geometry() {} /* Remove gcc warning */ + virtual ~Geometry() {} /* Remove gcc warning */ static void *operator new(size_t size, void *buffer) { return buffer; @@ -302,6 +304,8 @@ protected: class Gis_point: public Geometry { public: + Gis_point() {} /* Remove gcc warning */ + virtual ~Gis_point() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); @@ -349,6 +353,8 @@ public: class Gis_line_string: public Geometry { public: + Gis_line_string() {} /* Remove gcc warning */ + virtual ~Gis_line_string() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); @@ -375,6 +381,8 @@ public: class Gis_polygon: public Geometry { public: + Gis_polygon() {} /* Remove gcc warning */ + virtual ~Gis_polygon() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); @@ -401,6 +409,8 @@ public: class Gis_multi_point: public Geometry { public: + Gis_multi_point() {} /* Remove gcc warning */ + virtual ~Gis_multi_point() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); @@ -423,6 +433,8 @@ public: class Gis_multi_line_string: public Geometry { public: + Gis_multi_line_string() {} /* Remove gcc warning */ + virtual ~Gis_multi_line_string() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); @@ -447,6 +459,8 @@ public: class Gis_multi_polygon: public Geometry { public: + Gis_multi_polygon() {} /* Remove gcc warning */ + virtual ~Gis_multi_polygon() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); @@ -471,6 +485,8 @@ public: class Gis_geometry_collection: public Geometry { public: + Gis_geometry_collection() {} /* Remove gcc warning */ + virtual ~Gis_geometry_collection() {} /* Remove gcc warning */ uint32 get_data_size() const; bool init_from_wkt(Gis_read_stream *trs, String *wkb); uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index bebee7df8b2..3c2d1328a57 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -263,7 +263,9 @@ my_bool acl_init(bool dont_read_acl_tables) acl_cache= new hash_filo(ACL_CACHE_SIZE, 0, 0, (hash_get_key) acl_entry_get_key, - (hash_free_key) free, system_charset_info); + (hash_free_key) free, + /* Use the case sensitive "binary" charset */ + &my_charset_bin); if (dont_read_acl_tables) { DBUG_RETURN(0); /* purecov: tested */ @@ -471,10 +473,10 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) /* - if it is pre 5.1.4 privilege table then map CREATE privilege on + if it is pre 5.1.6 privilege table then map CREATE privilege on CREATE|ALTER|DROP|EXECUTE EVENT */ - if (table->s->fields <= 37 && (user.access & CREATE_ACL)) + if (table->s->fields <= 37 && (user.access & SUPER_ACL)) user.access|= EVENT_ACL; /* diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 2d6576bff8b..26d81eccce6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -313,6 +313,22 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key, conflicts */ (void) pthread_mutex_lock(&share->mutex); + + /* + We assign a new table id under the protection of the LOCK_open and + the share's own mutex. We do this insted of creating a new mutex + and using it for the sole purpose of serializing accesses to a + static variable, we assign the table id here. We assign it to the + share before inserting it into the table_def_cache to be really + sure that it cannot be read from the cache without having a table + id assigned. + + CAVEAT. This means that the table cannot be used for + binlogging/replication purposes, unless get_table_share() has been + called directly or indirectly. + */ + assign_new_table_id(share); + if (my_hash_insert(&table_def_cache, (byte*) share)) { #ifdef NOT_YET @@ -917,6 +933,15 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, DESCRIPTION Marks all tables in the list which were used by current substatement (they are marked by its query_id) as free for reuse. + + NOTE + The reason we reset query_id is that it's not enough to just test + if table->query_id != thd->query_id to know if a table is in use. + + For example + SELECT f1_that_uses_t1() FROM t1; + In f1_that_uses_t1() we will see one instance of t1 where query_id is + set to query_id of original query. */ static void mark_used_tables_as_free_for_reuse(THD *thd, TABLE *table) @@ -1189,7 +1214,7 @@ void close_temporary_tables(THD *thd) close_temporary(table, 1, 1); } if (query && found_user_tables && mysql_bin_log.is_open() && - !binlog_row_based) // CREATE TEMP TABLE not binlogged if row-based + !thd->current_stmt_binlog_row_based) // CREATE TEMP TABLE not binlogged if row-based { /* The -1 is to remove last ',' */ thd->clear_error(); @@ -1230,11 +1255,11 @@ void close_temporary_tables(THD *thd) */ TABLE_LIST *find_table_in_list(TABLE_LIST *table, - uint offset, + st_table_list *TABLE_LIST::*link, const char *db_name, const char *table_name) { - for (; table; table= *(TABLE_LIST **) ((char*) table + offset)) + for (; table; table= table->*link ) { if ((table->table == 0 || table->table->s->tmp_table == NO_TMP_TABLE) && strcmp(table->db, db_name) == 0 && @@ -2383,43 +2408,55 @@ void abort_locked_tables(THD *thd,const char *db, const char *table_name) /* - Function to assign a new table map id to a table. + Function to assign a new table map id to a table share. PARAMETERS - table - Pointer to table structure + share - Pointer to table share structure + + DESCRIPTION + + We are intentionally not checking that share->mutex is locked + since this function should only be called when opening a table + share and before it is entered into the table_def_cache (meaning + that it cannot be fetched by another thread, even accidentally). PRE-CONDITION(S) - table is non-NULL + share is non-NULL The LOCK_open mutex is locked POST-CONDITION(S) - table->s->table_map_id is given a value that with a high certainty - is not used by any other table. + share->table_map_id is given a value that with a high certainty is + not used by any other table (the only case where a table id can be + reused is on wrap-around, which means more than 4 billion table + shares open at the same time). - table->s->table_map_id is not ULONG_MAX. + share->table_map_id is not ULONG_MAX. */ -void assign_new_table_id(TABLE *table) +void assign_new_table_id(TABLE_SHARE *share) { static ulong last_table_id= ULONG_MAX; - DBUG_ENTER("assign_new_table_id(TABLE*)"); + DBUG_ENTER("assign_new_table_id"); /* Preconditions */ - DBUG_ASSERT(table != NULL); + DBUG_ASSERT(share != NULL); safe_mutex_assert_owner(&LOCK_open); ulong tid= ++last_table_id; /* get next id */ - /* There is one reserved number that cannot be used. */ + /* + There is one reserved number that cannot be used. Remember to + change this when 6-byte global table id's are introduced. + */ if (unlikely(tid == ULONG_MAX)) tid= ++last_table_id; - table->s->table_map_id= tid; + share->table_map_id= tid; DBUG_PRINT("info", ("table_id=%lu", tid)); /* Post conditions */ - DBUG_ASSERT(table->s->table_map_id != ULONG_MAX); + DBUG_ASSERT(share->table_map_id != ULONG_MAX); DBUG_VOID_RETURN; } @@ -2573,20 +2610,6 @@ retry: break; } - /* - We assign a new table id under the protection of the LOCK_open - mutex. We assign a new table id here instead of inside openfrm() - since that function can be used without acquiring any lock (e.g., - inside ha_create_table()). Insted of creatint a new mutex and - using it for the sole purpose of serializing accesses to a static - variable, we assign the table id here. - - CAVEAT. This means that the table cannot be used for - binlogging/replication purposes, unless open_table() has been called - directly or indirectly. - */ - assign_new_table_id(entry); - if (Table_triggers_list::check_n_load(thd, share->db.str, share->table_name.str, entry, 0)) { @@ -2692,22 +2715,11 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags) statement for which table list for prelocking is already built, let us cache routines and try to build such table list. - NOTE: We can't delay prelocking until we will met some sub-statement - which really uses tables, since this will imply that we have to restore - its table list to be able execute it in some other context. - And current views implementation assumes that view tables are added to - global table list only once during PS preparing/first SP execution. - Also locking at earlier stage is probably faster altough may decrease - concurrency a bit. - NOTE: We will mark statement as requiring prelocking only if we will have non empty table list. But this does not guarantee that in prelocked mode we will have some locked tables, because queries which use only derived/information schema tables and views possible. Thus "counter" may be still zero for prelocked statement... - - NOTE: The above notes may be out of date. Please wait for psergey to - document new prelocked behavior. */ if (!thd->prelocked_mode && !thd->lex->requires_prelocking() && @@ -2793,48 +2805,23 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags) if (refresh) // Refresh in progress { - /* close all 'old' tables used by this thread */ - pthread_mutex_lock(&LOCK_open); - // if query_id is not reset, we will get an error - // re-opening a temp table - thd->version=refresh_version; - TABLE **prev_table= &thd->open_tables; - bool found=0; - for (TABLE_LIST *tmp= *start; tmp; tmp= tmp->next_global) - { - /* Close normal (not temporary) changed tables */ - if (tmp->table && ! tmp->table->s->tmp_table != NO_TMP_TABLE) - { - if (tmp->table->s->version != refresh_version || - ! tmp->table->db_stat) - { - VOID(hash_delete(&open_cache,(byte*) tmp->table)); - tmp->table=0; - found=1; - } - else - { - *prev_table= tmp->table; // Relink open list - prev_table= &tmp->table->next; - } - } - } - *prev_table=0; - pthread_mutex_unlock(&LOCK_open); - if (found) - VOID(pthread_cond_broadcast(&COND_refresh)); // Signal to refresh /* - Let us prepare for recalculation of set of prelocked tables. - First we pretend that we have finished calculation which we - were doing currently. Then we restore list of tables to be - opened and set of used routines to the state in which they were - before first open_tables() call for this statement (i.e. before - we have calculated current set of tables for prelocking). + We have met name-locked or old version of table. Now we have + to close all tables which are not up to date. We also have to + throw away set of prelocked tables (and thus close tables from + this set that were open by now) since it possible that one of + tables which determined its content was changed. + + Instead of implementing complex/non-robust logic mentioned + above we simply close and then reopen all tables. + + In order to prepare for recalculation of set of prelocked tables + we pretend that we have finished calculation which we were doing + currently. */ if (query_tables_last_own) thd->lex->mark_as_requiring_prelocking(query_tables_last_own); - thd->lex->chop_off_not_own_tables(); - sp_remove_not_own_routines(thd->lex); + close_tables_for_reopen(thd, start); goto restart; } result= -1; // Fatal error @@ -3045,7 +3032,7 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables) break; if (!need_reopen) DBUG_RETURN(-1); - close_tables_for_reopen(thd, tables); + close_tables_for_reopen(thd, &tables); } DBUG_RETURN(0); } @@ -3082,7 +3069,7 @@ bool open_and_lock_tables(THD *thd, TABLE_LIST *tables) break; if (!need_reopen) DBUG_RETURN(-1); - close_tables_for_reopen(thd, tables); + close_tables_for_reopen(thd, &tables); } if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) || (thd->fill_derived_tables() && @@ -3310,18 +3297,24 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen) SYNOPSIS close_tables_for_reopen() - thd Thread context - tables List of tables which we were trying to open and lock + thd in Thread context + tables in/out List of tables which we were trying to open and lock */ -void close_tables_for_reopen(THD *thd, TABLE_LIST *tables) +void close_tables_for_reopen(THD *thd, TABLE_LIST **tables) { + /* + If table list consists only from tables from prelocking set, table list + for new attempt should be empty, so we have to update list's root pointer. + */ + if (thd->lex->first_not_own_table() == *tables) + *tables= 0; thd->lex->chop_off_not_own_tables(); sp_remove_not_own_routines(thd->lex); - for (TABLE_LIST *tmp= tables; tmp; tmp= tmp->next_global) - if (tmp->table && !tmp->table->s->tmp_table) - tmp->table= 0; + for (TABLE_LIST *tmp= *tables; tmp; tmp= tmp->next_global) + tmp->table= 0; + mark_used_tables_as_free_for_reuse(thd, thd->temporary_tables); close_thread_tables(thd); } @@ -4437,7 +4430,6 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, { Field_iterator_table_ref it_1, it_2; Natural_join_column *nj_col_1, *nj_col_2; - const char *field_name_1; Query_arena *arena, backup; bool add_columns= TRUE; bool result= TRUE; @@ -4470,6 +4462,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, { bool is_created_1; bool found= FALSE; + const char *field_name_1; if (!(nj_col_1= it_1.get_or_create_column_ref(&is_created_1))) goto err; field_name_1= nj_col_1->name(); @@ -4670,7 +4663,6 @@ store_natural_using_join_columns(THD *thd, TABLE_LIST *natural_using_join, { Field_iterator_table_ref it_1, it_2; Natural_join_column *nj_col_1, *nj_col_2; - bool is_created; Query_arena *arena, backup; bool result= TRUE; List<Natural_join_column> *non_join_columns; diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc index cc0e9714d85..0939ad66cd0 100644 --- a/sql/sql_binlog.cc +++ b/sql/sql_binlog.cc @@ -58,7 +58,7 @@ void mysql_client_binlog_statement(THD* thd) const char *error= 0; char *buf= (char *) my_malloc(event_len, MYF(MY_WME)); - Log_event *ev; + Log_event *ev = 0; int res; /* diff --git a/sql/sql_cache.h b/sql/sql_cache.h index b7531696150..29d314d3c44 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -69,6 +69,7 @@ class Query_cache; struct Query_cache_block_table { + Query_cache_block_table() {} /* Remove gcc warning */ TABLE_COUNTER_TYPE n; // numbr in table (from 0) Query_cache_block_table *next, *prev; Query_cache_table *parent; @@ -78,6 +79,7 @@ struct Query_cache_block_table struct Query_cache_block { + Query_cache_block() {} /* Remove gcc warning */ enum block_type {FREE, QUERY, RESULT, RES_CONT, RES_BEG, RES_INCOMPLETE, TABLE, INCOMPLETE}; @@ -143,6 +145,7 @@ struct Query_cache_query struct Query_cache_table { + Query_cache_table() {} /* Remove gcc warning */ char *tbl; uint32 key_len; uint8 table_type; @@ -171,6 +174,7 @@ struct Query_cache_table struct Query_cache_result { + Query_cache_result() {} /* Remove gcc warning */ Query_cache_block *query; inline gptr data() @@ -197,6 +201,7 @@ extern "C" void query_cache_invalidate_by_MyISAM_filename(const char* filename); struct Query_cache_memory_bin { + Query_cache_memory_bin() {} /* Remove gcc warning */ #ifndef DBUG_OFF ulong size; #endif @@ -215,8 +220,7 @@ struct Query_cache_memory_bin struct Query_cache_memory_bin_step { -public: - Query_cache_memory_bin_step() {} + Query_cache_memory_bin_step() {} /* Remove gcc warning */ ulong size; ulong increment; uint idx; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e68bcb9e281..d391584a3be 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -329,6 +329,7 @@ void THD::init(void) bzero((char*) warn_count, sizeof(warn_count)); total_warn_count= 0; update_charset(); + reset_current_stmt_binlog_row_based(); bzero((char *) &status_var, sizeof(status_var)); } @@ -988,10 +989,9 @@ bool select_send::send_data(List<Item> &items) thd->sent_row_count++; if (!thd->vio_ok()) DBUG_RETURN(0); - if (thd->net.report_error) - protocol->remove_last_row(); - else + if (!thd->net.report_error) DBUG_RETURN(protocol->write()); + protocol->remove_last_row(); DBUG_RETURN(1); } @@ -2026,12 +2026,12 @@ void THD::reset_sub_statement_state(Sub_statement_state *backup, INSERT INTO t1 VALUES (1), (foo()), (2); */ - if (binlog_row_based) + if (current_stmt_binlog_row_based) binlog_flush_pending_rows_event(false); #endif /* HAVE_ROW_BASED_REPLICATION */ if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) && - !binlog_row_based) + !current_stmt_binlog_row_based) options&= ~OPTION_BIN_LOG; /* Disable result sets */ client_capabilities &= ~CLIENT_MULTI_RESULTS; @@ -2394,7 +2394,7 @@ int THD::binlog_write_row(TABLE* table, bool is_trans, MY_BITMAP const* cols, my_size_t colcnt, byte const *record) { - DBUG_ASSERT(binlog_row_based && mysql_bin_log.is_open()); + DBUG_ASSERT(current_stmt_binlog_row_based && mysql_bin_log.is_open()); /* Pack records into format for transfer. We are allocating more @@ -2441,7 +2441,7 @@ int THD::binlog_update_row(TABLE* table, bool is_trans, const byte *before_record, const byte *after_record) { - DBUG_ASSERT(binlog_row_based && mysql_bin_log.is_open()); + DBUG_ASSERT(current_stmt_binlog_row_based && mysql_bin_log.is_open()); bool error= 0; my_size_t const before_maxlen = max_row_length(table, before_record); @@ -2489,7 +2489,7 @@ int THD::binlog_delete_row(TABLE* table, bool is_trans, MY_BITMAP const* cols, my_size_t colcnt, byte const *record) { - DBUG_ASSERT(binlog_row_based && mysql_bin_log.is_open()); + DBUG_ASSERT(current_stmt_binlog_row_based && mysql_bin_log.is_open()); /* Pack records into format for transfer. We are allocating more @@ -2520,7 +2520,7 @@ int THD::binlog_delete_row(TABLE* table, bool is_trans, int THD::binlog_flush_pending_rows_event(bool stmt_end) { DBUG_ENTER("THD::binlog_flush_pending_rows_event"); - if (!binlog_row_based || !mysql_bin_log.is_open()) + if (!current_stmt_binlog_row_based || !mysql_bin_log.is_open()) DBUG_RETURN(0); /* @@ -2561,8 +2561,8 @@ void THD::binlog_delete_pending_rows_event() /* Member function that will log query, either row-based or - statement-based depending on the value of the 'binlog_row_based' - variable and the value of the 'qtype' flag. + statement-based depending on the value of the 'current_stmt_binlog_row_based' + the value of the 'qtype' flag. This function should be called after the all calls to ha_*_row() functions have been issued, but before tables are unlocked and @@ -2586,11 +2586,11 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, moving back and forth between using RBR for replication of system tables and not using it. - Make sure to change in check_table_binlog_row_based() according + Make sure to change in check_table_current_stmt_binlog_row_based according to how you treat this. */ case THD::ROW_QUERY_TYPE: - if (binlog_row_based) + if (current_stmt_binlog_row_based) DBUG_RETURN(binlog_flush_pending_rows_event(true)); /* Otherwise, we fall through */ case THD::STMT_QUERY_TYPE: diff --git a/sql/sql_class.h b/sql/sql_class.h index 00440449be8..267faba49f8 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -248,13 +248,15 @@ struct system_variables #endif /* HAVE_REPLICATION */ my_bool innodb_table_locks; my_bool innodb_support_xa; - ulong ndb_autoincrement_prefetch_sz; my_bool ndb_force_send; my_bool ndb_use_exact_count; my_bool ndb_use_transactions; my_bool ndb_index_stat_enable; + ulong ndb_autoincrement_prefetch_sz; ulong ndb_index_stat_cache_entries; ulong ndb_index_stat_update_freq; + ulong binlog_format; // binlog format for this thd (see enum_binlog_format) + my_bool old_alter_table; my_bool old_passwords; @@ -629,6 +631,7 @@ void xid_cache_delete(XID_STATE *xid_state); class Security_context { public: + Security_context() {} /* Remove gcc warning */ /* host - host of the client user - user of the client, set to NULL until the user has been read from @@ -1123,6 +1126,8 @@ public: char scramble[SCRAMBLE_LENGTH+1]; bool slave_thread, one_shot_set; + /* tells if current statement should binlog row-based(1) or stmt-based(0) */ + bool current_stmt_binlog_row_based; bool locked, some_tables_deleted; bool last_cuted_field; bool no_errors, password, is_fatal_error; @@ -1377,6 +1382,15 @@ public: void restore_sub_statement_state(Sub_statement_state *backup); void set_n_backup_active_arena(Query_arena *set, Query_arena *backup); void restore_active_arena(Query_arena *set, Query_arena *backup); + inline void set_current_stmt_binlog_row_based_if_mixed() + { + if (variables.binlog_format == BINLOG_FORMAT_MIXED) + current_stmt_binlog_row_based= 1; + } + inline void reset_current_stmt_binlog_row_based() + { + current_stmt_binlog_row_based= test(variables.binlog_format == BINLOG_FORMAT_ROW); + } }; @@ -1467,6 +1481,7 @@ public: class select_result_interceptor: public select_result { public: + select_result_interceptor() {} /* Remove gcc warning */ uint field_count(List<Item> &fields) const { return 0; } bool send_fields(List<Item> &fields, uint flag) { return FALSE; } }; @@ -1757,6 +1772,7 @@ class Table_ident :public Sql_alloc class user_var_entry { public: + user_var_entry() {} /* Remove gcc warning */ LEX_STRING name; char *value; ulong length; diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 885643cf899..3d035359b6f 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1226,17 +1226,21 @@ err: bool mysql_change_db(THD *thd, const char *name, bool no_access_check) { int length, db_length; - char *dbname=my_strdup((char*) name,MYF(MY_WME)); + char *dbname= thd->slave_thread ? (char *) name : + my_strdup((char *) name, MYF(MY_WME)); char path[FN_REFLEN]; HA_CREATE_INFO create; bool system_db= 0; #ifndef NO_EMBEDDED_ACCESS_CHECKS ulong db_access; Security_context *sctx= thd->security_ctx; + LINT_INIT(db_access); #endif DBUG_ENTER("mysql_change_db"); DBUG_PRINT("enter",("name: '%s'",name)); + LINT_INIT(db_length); + /* dbname can only be NULL if malloc failed */ if (!dbname || !(db_length= strlen(dbname))) { @@ -1246,7 +1250,8 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check) system_db= 1; goto end; } - x_free(dbname); /* purecov: inspected */ + if (!(thd->slave_thread)) + x_free(dbname); /* purecov: inspected */ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ @@ -1254,7 +1259,8 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check) if (check_db_name(dbname)) { my_error(ER_WRONG_DB_NAME, MYF(0), dbname); - x_free(dbname); + if (!(thd->slave_thread)) + my_free(dbname, MYF(0)); DBUG_RETURN(1); } DBUG_PRINT("info",("Use database: %s", dbname)); @@ -1284,7 +1290,8 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check) dbname); general_log_print(thd, COM_INIT_DB, ER(ER_DBACCESS_DENIED_ERROR), sctx->priv_user, sctx->priv_host, dbname); - my_free(dbname,MYF(0)); + if (!(thd->slave_thread)) + my_free(dbname,MYF(0)); DBUG_RETURN(1); } } @@ -1295,7 +1302,8 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check) if (my_access(path,F_OK)) { my_error(ER_BAD_DB_ERROR, MYF(0), dbname); - my_free(dbname,MYF(0)); + if (!(thd->slave_thread)) + my_free(dbname,MYF(0)); DBUG_RETURN(1); } end: @@ -1304,7 +1312,7 @@ end: if (dbname && dbname[0] == 0) { if (!(thd->slave_thread)) - x_free(dbname); + my_free(dbname, MYF(0)); thd->db= NULL; thd->db_length= 0; } diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index c9cb1ccd5c2..34947e35b17 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -962,7 +962,7 @@ end: { /* TRUNCATE must always be statement-based binlogged (not row-based) so - we don't test binlog_row_based. + we don't test current_stmt_binlog_row_based. */ thd->clear_error(); thd->binlog_query(THD::STMT_QUERY_TYPE, diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 6655491ca57..bd7be110b88 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2411,7 +2411,7 @@ void select_insert::send_error(uint errcode,const char *err) thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, table->file->has_transactions(), FALSE); } - if (!binlog_row_based && !table->s->tmp_table) + if (!thd->current_stmt_binlog_row_based && !table->s->tmp_table) thd->options|=OPTION_STATUS_NO_TRANS_UPDATE; } if (info.copied || info.deleted || info.updated) @@ -2556,7 +2556,7 @@ select_create::binlog_show_create_table() on rollback, we clear the OPTION_STATUS_NO_TRANS_UPDATE bit of thd->options. */ - DBUG_ASSERT(binlog_row_based && !create_table_written); + DBUG_ASSERT(thd->current_stmt_binlog_row_based && !create_table_written); thd->options&= ~OPTION_STATUS_NO_TRANS_UPDATE; char buf[2048]; @@ -2582,7 +2582,7 @@ void select_create::store_values(List<Item> &values) Before writing the first row, we write the CREATE TABLE statement to the binlog. */ - if (binlog_row_based && !create_table_written) + if (thd->current_stmt_binlog_row_based && !create_table_written) { binlog_show_create_table(); create_table_written= TRUE; @@ -2611,7 +2611,7 @@ bool select_create::send_eof() If no rows where written to the binary log, we write the CREATE TABLE statement to the binlog. */ - if (binlog_row_based && !create_table_written) + if (thd->current_stmt_binlog_row_based && !create_table_written) { binlog_show_create_table(); create_table_written= TRUE; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index bf4bf272f4d..08167f8b6d2 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -27,7 +27,7 @@ class sp_instr; class sp_pcontext; class st_alter_tablespace; class partition_info; -class event_timed; +class Event_timed; #ifdef MYSQL_SERVER /* @@ -932,7 +932,7 @@ typedef struct st_lex st_sp_chistics sp_chistics; - event_timed *et; + Event_timed *et; bool et_compile_phase; bool only_view; /* used for SHOW CREATE TABLE/VIEW */ diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 1d6442ba7d6..30d83370255 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -426,7 +426,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, version for the binary log to mark that table maps are invalid after this point. */ - if (binlog_row_based) + if (thd->current_stmt_binlog_row_based) thd->binlog_flush_pending_rows_event(true); else #endif @@ -491,7 +491,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, version for the binary log to mark that table maps are invalid after this point. */ - if (binlog_row_based) + if (thd->current_stmt_binlog_row_based) thd->binlog_flush_pending_rows_event(true); else #endif @@ -948,7 +948,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs, if (get_it_from_net) cache.read_function = _my_b_net_read; - if (!binlog_row_based && mysql_bin_log.is_open()) + if (mysql_bin_log.is_open()) cache.pre_read = cache.pre_close = (IO_CACHE_CALLBACK) log_loaded_block; #endif diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b84eb1cfcb8..4ee47a574b1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2111,6 +2111,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, void log_slow_statement(THD *thd) { + DBUG_ENTER("log_slow_statement"); time_t start_of_query; /* @@ -2142,6 +2143,7 @@ void log_slow_statement(THD *thd) slow_log_print(thd, thd->query, thd->query_length, start_of_query); } } + DBUG_VOID_RETURN; } @@ -3715,7 +3717,7 @@ end_with_restore_list: } if (!strip_sp(db) || check_db_name(db)) { - my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), db); break; } /* @@ -3727,8 +3729,8 @@ end_with_restore_list: */ #ifdef HAVE_REPLICATION if (thd->slave_thread && - (!rpl_filter->db_ok(lex->name) || - !rpl_filter->db_ok_with_wild_table(lex->name))) + (!rpl_filter->db_ok(db) || + !rpl_filter->db_ok_with_wild_table(db))) { my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); break; @@ -4972,7 +4974,9 @@ end_with_restore_list: break; } default: +#ifndef EMBEDDED_LIBRARY DBUG_ASSERT(0); /* Impossible */ +#endif send_ok(thd); break; } @@ -4990,6 +4994,7 @@ end_with_restore_list: */ if (thd->one_shot_set && lex->sql_command != SQLCOM_SET_OPTION) reset_one_shot_variables(thd); + thd->reset_current_stmt_binlog_row_based(); /* The return value for ROW_COUNT() is "implementation dependent" if the @@ -5916,10 +5921,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, */ char buf[32]; my_snprintf(buf, sizeof(buf), "TIMESTAMP(%s)", length); - push_warning_printf(thd,MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_SYNTAX, - ER(ER_WARN_DEPRECATED_SYNTAX), - buf, "TIMESTAMP"); + WARN_DEPRECATED(thd, "5.2", buf, "'TIMESTAMP'"); } if (!(new_field= new create_field()) || @@ -6149,10 +6151,11 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, /* table_list.next points to the last inserted TABLE_LIST->next_local' element + We don't use the offsetof() macro here to avoid warnings from gcc */ - previous_table_ref= (TABLE_LIST*) (table_list.next - - offsetof(TABLE_LIST, next_local)); - DBUG_ASSERT(previous_table_ref); + previous_table_ref= (TABLE_LIST*) ((char*) table_list.next - + ((char*) &(ptr->next_local) - + (char*) ptr)); /* Set next_name_resolution_table of the previous table reference to point to the current table reference. In effect the list diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 71fbbcd2426..c98f8f915b9 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -15,10 +15,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* - This file was introduced as a container for general functionality related + This file is a container for general functionality related to partitioning introduced in MySQL version 5.1. It contains functionality - used by all handlers that support partitioning, which in the first version - is the partitioning handler itself and the NDB handler. + used by all handlers that support partitioning, such as + the partitioning handler itself and the NDB handler. The first version was written by Mikael Ronstrom. @@ -26,7 +26,7 @@ partitioning and composite partitioning (hereafter called subpartitioning) where each RANGE/LIST partitioning is HASH partitioned. The hash function can either be supplied by the user or by only a list of fields (also - called KEY partitioning, where the MySQL server will use an internal + called KEY partitioning), where the MySQL server will use an internal hash function. There are quite a few defaults that can be used as well. */ @@ -181,59 +181,6 @@ bool is_name_in_list(char *name, } -/* - A support function to check partition names for duplication in a - partitioned table - - SYNOPSIS - are_partitions_in_table() - new_part_info New partition info - old_part_info Old partition info - - RETURN VALUES - TRUE Duplicate names found - FALSE Duplicate names not found - - DESCRIPTION - Can handle that the new and old parts are the same in which case it - checks that the list of names in the partitions doesn't contain any - duplicated names. -*/ - -char *are_partitions_in_table(partition_info *new_part_info, - partition_info *old_part_info) -{ - uint no_new_parts= new_part_info->partitions.elements; - uint no_old_parts= old_part_info->partitions.elements; - uint new_count, old_count; - List_iterator<partition_element> new_parts_it(new_part_info->partitions); - bool is_same_part_info= (new_part_info == old_part_info); - DBUG_ENTER("are_partitions_in_table"); - DBUG_PRINT("enter", ("%u", no_new_parts)); - - new_count= 0; - do - { - List_iterator<partition_element> old_parts_it(old_part_info->partitions); - char *new_name= (new_parts_it++)->partition_name; - DBUG_PRINT("info", ("%s", new_name)); - new_count++; - old_count= 0; - do - { - char *old_name= (old_parts_it++)->partition_name; - old_count++; - if (is_same_part_info && old_count == new_count) - break; - if (!(my_strcasecmp(system_charset_info, old_name, new_name))) - { - DBUG_PRINT("info", ("old_name = %s, not ok", old_name)); - DBUG_RETURN(old_name); - } - } while (old_count < no_old_parts); - } while (new_count < no_new_parts); - DBUG_RETURN(NULL); -} /* Set-up defaults for partitions. @@ -262,7 +209,7 @@ bool partition_default_handling(TABLE *table, partition_info *part_info, DBUG_RETURN(TRUE); } } - else if (is_sub_partitioned(part_info) && + else if (part_info->is_sub_partitioned() && part_info->use_default_no_subpartitions) { uint no_parts; @@ -274,8 +221,8 @@ bool partition_default_handling(TABLE *table, partition_info *part_info, part_info->no_subparts= no_parts / part_info->no_parts; DBUG_ASSERT((no_parts % part_info->no_parts) == 0); } - set_up_defaults_for_partitioning(part_info, table->file, - (ulonglong)0, (uint)0); + part_info->set_up_defaults_for_partitioning(table->file, + (ulonglong)0, (uint)0); DBUG_RETURN(FALSE); } @@ -660,244 +607,9 @@ end: } -/* - Create a memory area where default partition names are stored and fill it - up with the names. - - SYNOPSIS - create_default_partition_names() - no_parts Number of partitions - start_no Starting partition number - subpart Is it subpartitions - RETURN VALUE - A pointer to the memory area of the default partition names - DESCRIPTION - A support routine for the partition code where default values are - generated. - The external routine needing this code is check_partition_info -*/ -#define MAX_PART_NAME_SIZE 8 - -static char *create_default_partition_names(uint no_parts, uint start_no, - bool is_subpart) -{ - char *ptr= sql_calloc(no_parts*MAX_PART_NAME_SIZE); - char *move_ptr= ptr; - uint i= 0; - DBUG_ENTER("create_default_partition_names"); - - if (likely(ptr != 0)) - { - do - { - if (is_subpart) - my_sprintf(move_ptr, (move_ptr,"sp%u", (start_no + i))); - else - my_sprintf(move_ptr, (move_ptr,"p%u", (start_no + i))); - move_ptr+=MAX_PART_NAME_SIZE; - } while (++i < no_parts); - } - else - { - mem_alloc_error(no_parts*MAX_PART_NAME_SIZE); - } - DBUG_RETURN(ptr); -} - - -/* - Set up all the default partitions not set-up by the user in the SQL - statement. Also perform a number of checks that the user hasn't tried - to use default values where no defaults exists. - - SYNOPSIS - set_up_default_partitions() - part_info The reference to all partition information - file A reference to a handler of the table - max_rows Maximum number of rows stored in the table - start_no Starting partition number - - RETURN VALUE - TRUE Error, attempted default values not possible - FALSE Ok, default partitions set-up - - DESCRIPTION - The routine uses the underlying handler of the partitioning to define - the default number of partitions. For some handlers this requires - knowledge of the maximum number of rows to be stored in the table. - This routine only accepts HASH and KEY partitioning and thus there is - no subpartitioning if this routine is successful. - The external routine needing this code is check_partition_info -*/ - -static bool set_up_default_partitions(partition_info *part_info, - handler *file, ulonglong max_rows, - uint start_no) -{ - uint no_parts, i; - char *default_name; - bool result= TRUE; - DBUG_ENTER("set_up_default_partitions"); - - if (part_info->part_type != HASH_PARTITION) - { - const char *error_string; - if (part_info->part_type == RANGE_PARTITION) - error_string= partition_keywords[PKW_RANGE].str; - else - error_string= partition_keywords[PKW_LIST].str; - my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), error_string); - goto end; - } - if (part_info->no_parts == 0) - part_info->no_parts= file->get_default_no_partitions(max_rows); - no_parts= part_info->no_parts; - if (unlikely(no_parts > MAX_PARTITIONS)) - { - my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); - goto end; - } - if (unlikely((!(default_name= create_default_partition_names(no_parts, - start_no, - FALSE))))) - goto end; - i= 0; - do - { - partition_element *part_elem= new partition_element(); - if (likely(part_elem != 0 && - (!part_info->partitions.push_back(part_elem)))) - { - part_elem->engine_type= part_info->default_engine_type; - part_elem->partition_name= default_name; - default_name+=MAX_PART_NAME_SIZE; - } - else - { - mem_alloc_error(sizeof(partition_element)); - goto end; - } - } while (++i < no_parts); - result= FALSE; -end: - DBUG_RETURN(result); -} - - -/* - Set up all the default subpartitions not set-up by the user in the SQL - statement. Also perform a number of checks that the default partitioning - becomes an allowed partitioning scheme. - - SYNOPSIS - set_up_default_subpartitions() - part_info The reference to all partition information - file A reference to a handler of the table - max_rows Maximum number of rows stored in the table - - RETURN VALUE - TRUE Error, attempted default values not possible - FALSE Ok, default partitions set-up - - DESCRIPTION - The routine uses the underlying handler of the partitioning to define - the default number of partitions. For some handlers this requires - knowledge of the maximum number of rows to be stored in the table. - This routine is only called for RANGE or LIST partitioning and those - need to be specified so only subpartitions are specified. - The external routine needing this code is check_partition_info -*/ - -static bool set_up_default_subpartitions(partition_info *part_info, - handler *file, ulonglong max_rows) -{ - uint i, j, no_parts, no_subparts; - char *default_name, *name_ptr; - bool result= TRUE; - partition_element *part_elem; - List_iterator<partition_element> part_it(part_info->partitions); - DBUG_ENTER("set_up_default_subpartitions"); - - if (part_info->no_subparts == 0) - part_info->no_subparts= file->get_default_no_partitions(max_rows); - no_parts= part_info->no_parts; - no_subparts= part_info->no_subparts; - if (unlikely((no_parts * no_subparts) > MAX_PARTITIONS)) - { - my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); - goto end; - } - if (unlikely((!(default_name= - create_default_partition_names(no_subparts, (uint)0, TRUE))))) - goto end; - i= 0; - do - { - part_elem= part_it++; - j= 0; - name_ptr= default_name; - do - { - partition_element *subpart_elem= new partition_element(); - if (likely(subpart_elem != 0 && - (!part_elem->subpartitions.push_back(subpart_elem)))) - { - subpart_elem->engine_type= part_info->default_engine_type; - subpart_elem->partition_name= name_ptr; - name_ptr+= MAX_PART_NAME_SIZE; - } - else - { - mem_alloc_error(sizeof(partition_element)); - goto end; - } - } while (++j < no_subparts); - } while (++i < no_parts); - result= FALSE; -end: - DBUG_RETURN(result); -} - - -/* - Support routine for check_partition_info - - SYNOPSIS - set_up_defaults_for_partitioning() - part_info The reference to all partition information - file A reference to a handler of the table - max_rows Maximum number of rows stored in the table - start_no Starting partition number - - RETURN VALUE - TRUE Error, attempted default values not possible - FALSE Ok, default partitions set-up - - DESCRIPTION - Set up defaults for partition or subpartition (cannot set-up for both, - this will return an error. -*/ - -bool set_up_defaults_for_partitioning(partition_info *part_info, - handler *file, - ulonglong max_rows, uint start_no) -{ - DBUG_ENTER("set_up_defaults_for_partitioning"); - - if (!part_info->default_partitions_setup) - { - part_info->default_partitions_setup= TRUE; - if (part_info->use_default_partitions) - DBUG_RETURN(set_up_default_partitions(part_info, file, max_rows, - start_no)); - if (is_sub_partitioned(part_info) && part_info->use_default_subpartitions) - DBUG_RETURN(set_up_default_subpartitions(part_info, file, max_rows)); - } - DBUG_RETURN(FALSE); -} /* @@ -967,7 +679,7 @@ bool check_partition_info(partition_info *part_info,handlerton **eng_type, char *same_name; DBUG_ENTER("check_partition_info"); - if (unlikely(is_sub_partitioned(part_info) && + if (unlikely(part_info->is_sub_partitioned() && (!(part_info->part_type == RANGE_PARTITION || part_info->part_type == LIST_PARTITION)))) { @@ -975,17 +687,17 @@ bool check_partition_info(partition_info *part_info,handlerton **eng_type, my_error(ER_SUBPARTITION_ERROR, MYF(0)); goto end; } - if (unlikely(set_up_defaults_for_partitioning(part_info, file, - max_rows, (uint)0))) + if (unlikely(part_info->set_up_defaults_for_partitioning(file, + max_rows, + (uint)0))) goto end; - tot_partitions= get_tot_partitions(part_info); + tot_partitions= part_info->get_tot_partitions(); if (unlikely(tot_partitions > MAX_PARTITIONS)) { my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); goto end; } - if (((same_name= are_partitions_in_table(part_info, - part_info)))) + if ((same_name= part_info->has_unique_names())) { my_error(ER_SAME_NAME_PARTITION, MYF(0), same_name); goto end; @@ -1001,7 +713,7 @@ bool check_partition_info(partition_info *part_info,handlerton **eng_type, do { partition_element *part_elem= part_it++; - if (!is_sub_partitioned(part_info)) + if (!part_info->is_sub_partitioned()) { if (part_elem->engine_type == NULL) part_elem->engine_type= part_info->default_engine_type; @@ -1194,7 +906,7 @@ static bool create_full_part_field_array(TABLE *table, bool result= FALSE; DBUG_ENTER("create_full_part_field_array"); - if (!is_sub_partitioned(part_info)) + if (!part_info->is_sub_partitioned()) { part_info->full_part_field_array= part_info->part_field_array; part_info->no_full_part_fields= part_info->no_part_fields; @@ -1702,6 +1414,7 @@ static bool set_up_partition_bitmap(THD *thd, partition_info *part_info) DBUG_RETURN(TRUE); } bitmap_init(&part_info->used_partitions, bitmap_buf, bitmap_bytes*8, FALSE); + bitmap_set_all(&part_info->used_partitions); DBUG_RETURN(FALSE); } @@ -1751,7 +1464,7 @@ static void set_up_partition_key_maps(TABLE *table, part_info->all_fields_in_PF.set_bit(i); if (some_fields) part_info->some_fields_in_PF.set_bit(i); - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { check_fields_in_PF(part_info->part_field_array, &all_fields, &some_fields); @@ -1789,7 +1502,7 @@ static void set_up_partition_func_pointers(partition_info *part_info) { DBUG_ENTER("set_up_partition_func_pointers"); - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { if (part_info->part_type == RANGE_PARTITION) { @@ -2011,7 +1724,7 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table, DBUG_RETURN(TRUE); } } - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { DBUG_ASSERT(part_info->subpart_type == HASH_PARTITION); /* @@ -2442,7 +2155,7 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_int(fptr, part_info->no_parts); err+= add_space(fptr); } - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { err+= add_subpartition_by(fptr); /* Must be hash partitioning for subpartitioning */ @@ -2528,9 +2241,9 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_string(fptr, part_elem->partition_name); err+= add_space(fptr); err+= add_partition_values(fptr, part_info, part_elem); - if (!is_sub_partitioned(part_info)) + if (!part_info->is_sub_partitioned()) err+= add_partition_options(fptr, part_elem); - if (is_sub_partitioned(part_info) && + if (part_info->is_sub_partitioned() && (write_all || (!part_info->use_default_subpartitions))) { err+= add_space(fptr); @@ -2630,6 +2343,29 @@ bool partition_key_modified(TABLE *table, List<Item> &fields) /* + A function to handle correct handling of NULL values in partition + functions. + SYNOPSIS + part_val_int() + item_expr The item expression to evaluate + RETURN VALUES + The value of the partition function, LONGLONG_MIN if any null value + in function +*/ + +static +inline +longlong +part_val_int(Item *item_expr) +{ + longlong value= item_expr->val_int(); + if (item_expr->null_value) + value= LONGLONG_MIN; + return value; +} + + +/* The next set of functions are used to calculate the partition identity. A handler sets up a variable that corresponds to one of these functions to be able to quickly call it whenever the partition id needs to calculated @@ -2725,7 +2461,7 @@ static uint32 get_part_id_hash(uint no_parts, longlong *func_value) { DBUG_ENTER("get_part_id_hash"); - *func_value= part_expr->val_int(); + *func_value= part_val_int(part_expr); longlong int_hash_id= *func_value % no_parts; DBUG_RETURN(int_hash_id < 0 ? -int_hash_id : int_hash_id); } @@ -2754,7 +2490,7 @@ static uint32 get_part_id_linear_hash(partition_info *part_info, { DBUG_ENTER("get_part_id_linear_hash"); - *func_value= part_expr->val_int(); + *func_value= part_val_int(part_expr); DBUG_RETURN(get_part_id_from_linear_hash(*func_value, part_info->linear_hash_mask, no_parts)); @@ -2892,7 +2628,7 @@ int get_partition_id_list(partition_info *part_info, longlong list_value; int min_list_index= 0; int max_list_index= part_info->no_list_values - 1; - longlong part_func_value= part_info->part_expr->val_int(); + longlong part_func_value= part_val_int(part_info->part_expr); DBUG_ENTER("get_partition_id_list"); *func_value= part_func_value; @@ -2968,7 +2704,7 @@ uint32 get_list_array_idx_for_endpoint(partition_info *part_info, longlong list_value; uint min_list_index= 0, max_list_index= part_info->no_list_values - 1; /* Get the partitioning function value for the endpoint */ - longlong part_func_value= part_info->part_expr->val_int(); + longlong part_func_value= part_val_int(part_info->part_expr); while (max_list_index >= min_list_index) { list_index= (max_list_index + min_list_index) >> 1; @@ -3002,7 +2738,7 @@ int get_partition_id_range(partition_info *part_info, uint min_part_id= 0; uint max_part_id= max_partition; uint loc_part_id; - longlong part_func_value= part_info->part_expr->val_int(); + longlong part_func_value= part_val_int(part_info->part_expr); DBUG_ENTER("get_partition_id_int_range"); while (max_part_id > min_part_id) @@ -3077,7 +2813,7 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info, uint max_partition= part_info->no_parts - 1; uint min_part_id= 0, max_part_id= max_partition, loc_part_id; /* Get the partitioning function value for the endpoint */ - longlong part_func_value= part_info->part_expr->val_int(); + longlong part_func_value= part_val_int(part_info->part_expr); while (max_part_id > min_part_id) { loc_part_id= (max_part_id + min_part_id + 1) >> 1; @@ -3680,7 +3416,7 @@ void get_partition_set(const TABLE *table, byte *buf, const uint index, const key_range *key_spec, part_id_range *part_spec) { partition_info *part_info= table->part_info; - uint no_parts= get_tot_partitions(part_info); + uint no_parts= part_info->get_tot_partitions(); uint i, part_id; uint sub_part= no_parts; uint32 part_part= no_parts; @@ -3720,7 +3456,7 @@ void get_partition_set(const TABLE *table, byte *buf, const uint index, prune_partition_set(table, part_spec); DBUG_VOID_RETURN; } - else if (is_sub_partitioned(part_info)) + else if (part_info->is_sub_partitioned()) { if (part_info->all_fields_in_SPF.is_set(index)) sub_part= get_sub_part_id_from_key(table, buf, key_info, key_spec); @@ -3766,7 +3502,7 @@ void get_partition_set(const TABLE *table, byte *buf, const uint index, prune_partition_set(table, part_spec); DBUG_VOID_RETURN; } - else if (is_sub_partitioned(part_info)) + else if (part_info->is_sub_partitioned()) { if (check_part_func_bound(part_info->subpart_field_array)) sub_part= get_sub_part_id_from_key(table, buf, key_info, key_spec); @@ -3894,11 +3630,13 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf, Item *thd_free_list= thd->free_list; bool result= TRUE; partition_info *part_info; + CHARSET_INFO *old_character_set_client= thd->variables.character_set_client; LEX *old_lex= thd->lex; LEX lex; DBUG_ENTER("mysql_unpack_partition"); thd->lex= &lex; + thd->variables.character_set_client= system_charset_info; lex_start(thd, part_buf, part_info_len); /* We need to use the current SELECT_LEX since I need to keep the @@ -4024,6 +3762,7 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf, end: thd->free_list= thd_free_list; thd->lex= old_lex; + thd->variables.character_set_client= old_character_set_client; DBUG_RETURN(result); } @@ -4187,7 +3926,7 @@ static bool check_native_partitioned(HA_CREATE_INFO *create_info,bool *ret_val, do { partition_element *part_elem= part_it++; - if (is_sub_partitioned(part_info) && + if (part_info->is_sub_partitioned() && part_elem->subpartitions.elements) { uint no_subparts= part_elem->subpartitions.elements; @@ -4299,7 +4038,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, is freed by setting version to 0. table->s->version= 0 forces a flush of the table object in close_thread_tables(). */ - uint flags; + uint flags= 0; table->s->version= 0L; if (alter_info->flags == ALTER_TABLE_REORG) { @@ -4348,7 +4087,10 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0)); DBUG_RETURN(1); } - *fast_alter_partition= flags ^ HA_PARTITION_FUNCTION_SUPPORTED; + *fast_alter_partition= + ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0); + DBUG_PRINT("info", ("*fast_alter_partition: %d flags: 0x%x", + *fast_alter_partition, flags)); if (alter_info->flags & ALTER_ADD_PARTITION) { /* @@ -4377,7 +4119,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, my_error(ER_ADD_PARTITION_NO_NEW_PARTITION, MYF(0)); DBUG_RETURN(TRUE); } - if (is_sub_partitioned(tab_part_info)) + if (tab_part_info->is_sub_partitioned()) { if (alt_part_info->no_subparts == 0) alt_part_info->no_subparts= tab_part_info->no_subparts; @@ -4395,10 +4137,9 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, DBUG_RETURN(TRUE); } alt_part_info->part_type= tab_part_info->part_type; - if (set_up_defaults_for_partitioning(alt_part_info, - table->file, - ULL(0), - tab_part_info->no_parts)) + if (alt_part_info->set_up_defaults_for_partitioning(table->file, + ULL(0), + tab_part_info->no_parts)) { DBUG_RETURN(TRUE); } @@ -4949,7 +4690,6 @@ the generated partition syntax in a correct manner. DBUG_ASSERT(FALSE); } *partition_changed= TRUE; - create_info->db_type= &partition_hton; thd->lex->part_info= tab_part_info; if (alter_info->flags == ALTER_ADD_PARTITION || alter_info->flags == ALTER_REORGANIZE_PARTITION) @@ -5606,7 +5346,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) uint partition_id= 0; List_iterator<partition_element> it(part_info->partitions); - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { partition_element *head_pe; while ((head_pe= it++)) @@ -6065,7 +5805,7 @@ static uint32 get_next_partition_via_walking(PARTITION_ITERATOR *part_iter) field->store(part_iter->field_vals.start, FALSE); part_iter->field_vals.start++; longlong dummy; - if (is_sub_partitioned(part_iter->part_info) && + if (part_iter->part_info->is_sub_partitioned() && !part_iter->part_info->get_part_partition_id(part_iter->part_info, &part_id, &dummy) || !part_iter->part_info->get_partition_id(part_iter->part_info, diff --git a/sql/sql_partition.h b/sql/sql_partition.h new file mode 100644 index 00000000000..4982b1fcf1f --- /dev/null +++ b/sql/sql_partition.h @@ -0,0 +1,190 @@ +/* Copyright (C) 2006 MySQL AB + + 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; either version 2 of the License, or + (at your option) any later version. + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifdef __GNUC__ +#pragma interface /* gcc class implementation */ +#endif + +/* Flags for partition handlers */ +#define HA_CAN_PARTITION (1 << 0) /* Partition support */ +#define HA_CAN_UPDATE_PARTITION_KEY (1 << 1) +#define HA_CAN_PARTITION_UNIQUE (1 << 2) +#define HA_USE_AUTO_PARTITION (1 << 3) + +/*typedef struct { + ulonglong data_file_length; + ulonglong max_data_file_length; + ulonglong index_file_length; + ulonglong delete_length; + ha_rows records; + ulong mean_rec_length; + time_t create_time; + time_t check_time; + time_t update_time; + ulonglong check_sum; +} PARTITION_INFO; +*/ +typedef struct { + longlong list_value; + uint32 partition_id; +} LIST_PART_ENTRY; + +typedef struct { + uint32 start_part; + uint32 end_part; +} part_id_range; + +struct st_partition_iter; +#define NOT_A_PARTITION_ID ((uint32)-1) + +bool is_partition_in_list(char *part_name, List<char> list_part_names); +char *are_partitions_in_table(partition_info *new_part_info, + partition_info *old_part_info); +bool check_reorganise_list(partition_info *new_part_info, + partition_info *old_part_info, + List<char> list_part_names); +handler *get_ha_partition(partition_info *part_info); +int get_parts_for_update(const byte *old_data, byte *new_data, + const byte *rec0, partition_info *part_info, + uint32 *old_part_id, uint32 *new_part_id, + longlong *func_value); +int get_part_for_delete(const byte *buf, const byte *rec0, + partition_info *part_info, uint32 *part_id); +void prune_partition_set(const TABLE *table, part_id_range *part_spec); +bool check_partition_info(partition_info *part_info,handlerton **eng_type, + handler *file, ulonglong max_rows); +bool fix_partition_func(THD *thd, const char *name, TABLE *table, + bool create_table_ind); +char *generate_partition_syntax(partition_info *part_info, + uint *buf_length, bool use_sql_alloc, + bool write_all); +bool partition_key_modified(TABLE *table, List<Item> &fields); +void get_partition_set(const TABLE *table, byte *buf, const uint index, + const key_range *key_spec, + part_id_range *part_spec); +void get_full_part_id_from_key(const TABLE *table, byte *buf, + KEY *key_info, + const key_range *key_spec, + part_id_range *part_spec); +bool mysql_unpack_partition(THD *thd, const uchar *part_buf, + uint part_info_len, + uchar *part_state, uint part_state_len, + TABLE *table, bool is_create_table_ind, + handlerton *default_db_type); +void make_used_partitions_str(partition_info *part_info, String *parts_str); +uint32 get_list_array_idx_for_endpoint(partition_info *part_info, + bool left_endpoint, + bool include_endpoint); +uint32 get_partition_id_range_for_endpoint(partition_info *part_info, + bool left_endpoint, + bool include_endpoint); + +/* + A "Get next" function for partition iterator. + SYNOPSIS + partition_iter_func() + part_iter Partition iterator, you call only "iter.get_next(&iter)" + + RETURN + NOT_A_PARTITION_ID if there are no more partitions. + [sub]partition_id of the next partition +*/ + +typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter); + + +/* + Partition set iterator. Used to enumerate a set of [sub]partitions + obtained in partition interval analysis (see get_partitions_in_range_iter). + + For the user, the only meaningful field is get_next, which may be used as + follows: + part_iterator.get_next(&part_iterator); + + Initialization is done by any of the following calls: + - get_partitions_in_range_iter-type function call + - init_single_partition_iterator() + - init_all_partitions_iterator() + Cleanup is not needed. +*/ + +typedef struct st_partition_iter +{ + partition_iter_func get_next; + + struct st_part_num_range + { + uint32 start; + uint32 end; + }; + + struct st_field_value_range + { + longlong start; + longlong end; + }; + + union + { + struct st_part_num_range part_nums; + struct st_field_value_range field_vals; + }; + partition_info *part_info; +} PARTITION_ITERATOR; + + +/* + Get an iterator for set of partitions that match given field-space interval + + SYNOPSIS + get_partitions_in_range_iter() + part_info Partitioning info + is_subpart + min_val Left edge, field value in opt_range_key format. + max_val Right edge, field value in opt_range_key format. + flags Some combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE, + NO_MAX_RANGE. + part_iter Iterator structure to be initialized + + DESCRIPTION + Functions with this signature are used to perform "Partitioning Interval + Analysis". This analysis is applicable for any type of [sub]partitioning + by some function of a single fieldX. The idea is as follows: + Given an interval "const1 <=? fieldX <=? const2", find a set of partitions + that may contain records with value of fieldX within the given interval. + + The min_val, max_val and flags parameters specify the interval. + The set of partitions is returned by initializing an iterator in *part_iter + + NOTES + There are currently two functions of this type: + - get_part_iter_for_interval_via_walking + - get_part_iter_for_interval_via_mapping + + RETURN + 0 - No matching partitions, iterator not initialized + 1 - Some partitions would match, iterator intialized for traversing them + -1 - All partitions would match, iterator not initialized +*/ + +typedef int (*get_partitions_in_range_iter)(partition_info *part_info, + bool is_subpart, + char *min_val, char *max_val, + uint flags, + PARTITION_ITERATOR *part_iter); + +#include "partition_info.h" + diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 2046596c428..ad99d81d7b4 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -681,7 +681,7 @@ void plugin_load(void) if (simple_open_n_lock_tables(new_thd, &tables)) { DBUG_PRINT("error",("Can't open plugin table")); - sql_print_error("Can't open the mysql.plugin table. Please run the mysql_install_db script to create it."); + sql_print_error("Can't open the mysql.plugin table. Please run the mysql_upgrade script to create it."); goto end; } table= tables.table; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 1b9cca9d84f..a66b2bdb9b6 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1142,7 +1142,7 @@ static int mysql_test_update(Prepared_statement *stmt, break; if (!need_reopen) goto error; - close_tables_for_reopen(thd, table_list); + close_tables_for_reopen(thd, &table_list); } /* diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 5f20442cc84..e3468b2b5cf 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -19,6 +19,7 @@ */ #include "mysql_priv.h" +#include "sql_trigger.h" static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list, @@ -173,9 +174,30 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) if (table_type == DB_TYPE_UNKNOWN) my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); else - rc= mysql_rename_table(ha_resolve_by_legacy_type(thd, table_type), - ren_table->db, old_alias, - new_table->db, new_alias); + { + if (!(rc= mysql_rename_table(ha_resolve_by_legacy_type(thd, + table_type), + ren_table->db, old_alias, + new_table->db, new_alias))) + { + if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db, + old_alias, + new_table->db, + new_alias))) + { + /* + We've succeeded in renaming table's .frm and in updating + corresponding handler data, but have failed to update table's + triggers appropriately. So let us revert operations on .frm + and handler's data and report about failure to rename table. + */ + (void) mysql_rename_table(ha_resolve_by_legacy_type(thd, + table_type), + new_table->db, new_alias, + ren_table->db, old_alias); + } + } + } break; } case FRMTYPE_VIEW: diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index bf9a6078a8f..743a0a6b565 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1576,6 +1576,8 @@ int log_loaded_block(IO_CACHE* file) if (!(block_len = (char*) file->read_end - (char*) buffer)) return 0; lf_info = (LOAD_FILE_INFO*) file->arg; + if (lf_info->thd->current_stmt_binlog_row_based) + return 0; if (lf_info->last_pos_in_file != HA_POS_ERROR && lf_info->last_pos_in_file >= file->pos_in_file) return 0; diff --git a/sql/sql_select.h b/sql/sql_select.h index 4f93a4aa996..459d2ff89a8 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -104,6 +104,7 @@ typedef int (*Read_record_func)(struct st_join_table *tab); Next_select_func setup_end_select_func(JOIN *join); typedef struct st_join_table { + st_join_table() {} /* Remove gcc warning */ TABLE *table; KEYUSE *keyuse; /* pointer to first used key */ SQL_SELECT *select; @@ -175,7 +176,9 @@ typedef struct st_rollup class JOIN :public Sql_alloc { - public: + JOIN(const JOIN &rhs); /* not implemented */ + JOIN& operator=(const JOIN &rhs); /* not implemented */ +public: JOIN_TAB *join_tab,**best_ref; JOIN_TAB **map2table; // mapping between table indexes and JOIN_TABs JOIN_TAB *join_tab_save; // saved join_tab for subquery reexecution @@ -287,13 +290,6 @@ class JOIN :public Sql_alloc init(thd_arg, fields_arg, select_options_arg, result_arg); } - JOIN(JOIN &join) - :fields_list(join.fields_list) - { - init(join.thd, join.fields_list, join.select_options, - join.result); - } - void init(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg, select_result *result_arg) { diff --git a/sql/sql_show.cc b/sql/sql_show.cc index cc2bec73ccf..13f880ef228 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -247,7 +247,7 @@ static struct show_privileges_st sys_privileges[]= {"Create user", "Server Admin", "To create new users"}, {"Delete", "Tables", "To delete existing rows"}, {"Drop", "Databases,Tables", "To drop databases, tables, and views"}, - {"Event","Server Admin","Creation, alteration, deletion and execution of events."}, + {"Event","Server Admin","To create, alter, drop and execute events"}, {"Execute", "Functions,Procedures", "To execute stored routines"}, {"File", "File access on server", "To read and write files on the server"}, {"Grant option", "Databases,Tables,Functions,Procedures", "To give to other users those privileges you possess"}, @@ -513,12 +513,15 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) { if (!table_list->view || thd->net.last_errno != ER_VIEW_INVALID) DBUG_RETURN(TRUE); + /* Clear all messages with 'error' level status and issue a warning with 'warning' level status in case of invalid view and last error is ER_VIEW_INVALID */ mysql_reset_errors(thd, true); + thd->clear_error(); + push_warning_printf(thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_VIEW_INVALID, ER(ER_VIEW_INVALID), @@ -1654,7 +1657,7 @@ static int show_var_cmp(const void *var1, const void *var2) */ static void shrink_var_array(DYNAMIC_ARRAY *array) { - int a,b; + uint a,b; SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *); for (a= b= 0; b < array->elements; b++) @@ -3775,7 +3778,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables, table->field[9]->set_notnull(); } - if (is_sub_partitioned(part_info)) + if (part_info->is_sub_partitioned()) { /* Subpartition method */ if (part_info->list_of_subpart_fields) @@ -3933,14 +3936,14 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; CHARSET_INFO *scs= system_charset_info; TIME time; - event_timed et; + Event_timed et; DBUG_ENTER("fill_events_copy_to_schema_tab"); restore_record(sch_table, s->default_values); if (et.load_from_row(thd->mem_root, event_table)) { - my_error(ER_EVENT_CANNOT_LOAD_FROM_TABLE, MYF(0)); + my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0)); DBUG_RETURN(1); } @@ -3954,7 +3957,7 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) sch_table->field[3]->store(et.definer.str, et.definer.length, scs); sch_table->field[4]->store(et.body.str, et.body.length, scs); - // [9] is SQL_MODE + /* [9] is SQL_MODE */ { byte *sql_mode_str; ulong sql_mode_len=0; @@ -3969,39 +3972,38 @@ fill_events_copy_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) String show_str; //type sch_table->field[5]->store(STRING_WITH_LEN("RECURRING"), scs); - //execute_at + /* execute_at */ sch_table->field[6]->set_null(); - //interval_value + /* interval_value */ //interval_type if (event_reconstruct_interval_expression(&show_str, et.interval, et.expression)) DBUG_RETURN(1); + sch_table->field[7]->set_notnull(); sch_table->field[7]->store(show_str.c_ptr(), show_str.length(), scs); LEX_STRING *ival= &interval_type_to_name[et.interval]; sch_table->field[8]->set_notnull(); sch_table->field[8]->store(ival->str, ival->length, scs); - //starts & ends + + //starts & ends sch_table->field[10]->set_notnull(); sch_table->field[10]->store_time(&et.starts, MYSQL_TIMESTAMP_DATETIME); - sch_table->field[11]->set_notnull(); - sch_table->field[11]->store_time(&et.ends, MYSQL_TIMESTAMP_DATETIME); + + if (!et.ends_null) + { + sch_table->field[11]->set_notnull(); + sch_table->field[11]->store_time(&et.ends, MYSQL_TIMESTAMP_DATETIME); + } } else { //type sch_table->field[5]->store(STRING_WITH_LEN("ONE TIME"), scs); - //execute_at + sch_table->field[6]->set_notnull(); sch_table->field[6]->store_time(&et.execute_at, MYSQL_TIMESTAMP_DATETIME); - //interval - sch_table->field[7]->set_null(); - //interval_type - sch_table->field[8]->set_null(); - //starts & ends - sch_table->field[10]->set_null(); - sch_table->field[11]->set_null(); } //status diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2737e9448f9..757321b5ccf 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -565,7 +565,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, String built_query; DBUG_ENTER("mysql_rm_table_part2"); - if (binlog_row_based && !dont_log_query) + if (thd->current_stmt_binlog_row_based && !dont_log_query) { built_query.set_charset(system_charset_info); if (if_exists) @@ -612,7 +612,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, being built. The string always end in a comma and the comma will be chopped off before being written to the binary log. */ - if (binlog_row_based && !dont_log_query) + if (thd->current_stmt_binlog_row_based && !dont_log_query) { ++non_temp_tables_count; /* @@ -722,7 +722,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, query_cache_invalidate3(thd, tables, 0); if (!dont_log_query) { - if (!binlog_row_based || + if (!thd->current_stmt_binlog_row_based || non_temp_tables_count > 0 && !tmp_table_deleted) { /* @@ -734,7 +734,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, */ write_bin_log(thd, !error, thd->query, thd->query_length); } - else if (binlog_row_based && + else if (thd->current_stmt_binlog_row_based && non_temp_tables_count > 0 && tmp_table_deleted) { @@ -1127,6 +1127,12 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, { CHARSET_INFO *save_cs; + /* + Initialize length from its original value (number of characters), + which was set in the parser. This is necessary if we're + executing a prepared statement for the second time. + */ + sql_field->length= sql_field->char_length; if (!sql_field->charset) sql_field->charset= create_info->default_table_charset; /* @@ -1311,7 +1317,7 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, sql_field->charset= (dup_field->charset ? dup_field->charset : create_info->default_table_charset); - sql_field->length= dup_field->chars_length; + sql_field->length= dup_field->char_length; sql_field->pack_length= dup_field->pack_length; sql_field->key_length= dup_field->key_length; sql_field->create_length_to_internal_length(); @@ -1742,7 +1748,9 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (length > file->max_key_part_length() && key->type != Key::FULLTEXT) { - length=file->max_key_part_length(); + length= file->max_key_part_length(); + /* Align key length to multibyte char boundary */ + length-= length % sql_field->charset->mbmaxlen; if (key->type == Key::MULTIPLE) { /* not a critical problem */ @@ -2248,8 +2256,8 @@ bool mysql_create_table_internal(THD *thd, Otherwise, the statement shall be binlogged. */ if (!internal_tmp_table && - (!binlog_row_based || - (binlog_row_based && + (!thd->current_stmt_binlog_row_based || + (thd->current_stmt_binlog_row_based && !(create_info->options & HA_LEX_CREATE_TMP_TABLE)))) write_bin_log(thd, TRUE, thd->query, thd->query_length); error= FALSE; @@ -3475,7 +3483,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, /* We have to write the query before we unlock the tables. */ - if (binlog_row_based) + if (thd->current_stmt_binlog_row_based) { /* Since temporary tables are not replicated under row-based @@ -4029,6 +4037,13 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, close_cached_table(thd, table); if (mysql_rename_table(old_db_type,db,table_name,new_db,new_alias)) error= -1; + else if (Table_triggers_list::change_table_name(thd, db, table_name, + new_db, new_alias)) + { + VOID(mysql_rename_table(old_db_type, new_db, new_alias, db, + table_name)); + error= -1; + } } VOID(pthread_mutex_unlock(&LOCK_open)); } @@ -4861,7 +4876,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, goto err; } /* We don't replicate alter table statement on temporary tables */ - if (!binlog_row_based) + if (!thd->current_stmt_binlog_row_based) write_bin_log(thd, TRUE, thd->query, thd->query_length); goto end_temporary; } @@ -4931,7 +4946,11 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, VOID(quick_rm_table(new_db_type,new_db,tmp_name)); } else if (mysql_rename_table(new_db_type,new_db,tmp_name,new_db, - new_alias)) + new_alias) || + (new_name != table_name || new_db != db) && // we also do rename + Table_triggers_list::change_table_name(thd, db, table_name, + new_db, new_alias)) + { // Try to get everything back error=1; VOID(quick_rm_table(new_db_type,new_db,new_alias)); @@ -5031,7 +5050,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, thd->query, thd->query_length, db, table_name); - DBUG_ASSERT(!(mysql_bin_log.is_open() && binlog_row_based && + DBUG_ASSERT(!(mysql_bin_log.is_open() && thd->current_stmt_binlog_row_based && (create_info->options & HA_LEX_CREATE_TMP_TABLE))); write_bin_log(thd, TRUE, thd->query, thd->query_length); /* diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 0198dba780d..e33dc52df8f 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -65,7 +65,6 @@ File_option sql_modes_parameters= */ static const int TRG_NUM_REQUIRED_PARAMETERS= 4; -static const int TRG_MAX_VERSIONS= 3; /* Structure representing contents of .TRN file which are used to support @@ -318,8 +317,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, { LEX *lex= thd->lex; TABLE *table= tables->table; - char file_buff[FN_REFLEN], trigname_buff[FN_REFLEN], - trigname_path[FN_REFLEN]; + char file_buff[FN_REFLEN], trigname_buff[FN_REFLEN]; LEX_STRING file, trigname_file; LEX_STRING *trg_def, *name; ulonglong *trg_sql_mode; @@ -472,12 +470,11 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, definer_host->str, NullS) - trg_definer->str; if (!sql_create_definition_file(NULL, &file, &triggers_file_type, - (gptr)this, triggers_file_parameters, - TRG_MAX_VERSIONS)) + (gptr)this, triggers_file_parameters, 0)) return 0; err_with_cleanup: - my_delete(trigname_path, MYF(MY_WME)); + my_delete(trigname_buff, MYF(MY_WME)); return 1; } @@ -497,7 +494,8 @@ err_with_cleanup: True - error */ -static bool rm_trigger_file(char *path, char *db, char *table_name) +static bool rm_trigger_file(char *path, const char *db, + const char *table_name) { build_table_filename(path, FN_REFLEN-1, db, table_name, triggers_file_ext); return my_delete(path, MYF(MY_WME)); @@ -519,7 +517,8 @@ static bool rm_trigger_file(char *path, char *db, char *table_name) True - error */ -static bool rm_trigname_file(char *path, char *db, char *trigger_name) +static bool rm_trigname_file(char *path, const char *db, + const char *trigger_name) { build_table_filename(path, FN_REFLEN-1, db, trigger_name, trigname_file_ext); return my_delete(path, MYF(MY_WME)); @@ -527,6 +526,35 @@ static bool rm_trigname_file(char *path, char *db, char *trigger_name) /* + Helper function that saves .TRG file for Table_triggers_list object. + + SYNOPSIS + save_trigger_file() + triggers Table_triggers_list object for which file should be saved + db Name of database for subject table + table_name Name of subject table + + RETURN VALUE + FALSE Success + TRUE Error +*/ + +static bool save_trigger_file(Table_triggers_list *triggers, const char *db, + const char *table_name) +{ + char file_buff[FN_REFLEN]; + LEX_STRING file; + + file.length= build_table_filename(file_buff, FN_REFLEN-1, db, table_name, + triggers_file_ext); + file.str= file_buff; + return sql_create_definition_file(NULL, &file, &triggers_file_type, + (gptr)triggers, triggers_file_parameters, + 0); +} + + +/* Drop trigger for table. SYNOPSIS @@ -579,16 +607,7 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables) } else { - char file_buff[FN_REFLEN]; - LEX_STRING file; - - file.length= build_table_filename(file_buff, FN_REFLEN-1, - tables->db, tables->table_name, - triggers_file_ext); - file.str= file_buff; - if (sql_create_definition_file(NULL, &file, &triggers_file_type, - (gptr)this, triggers_file_parameters, - TRG_MAX_VERSIONS)) + if (save_trigger_file(this, tables->db, tables->table_name)) return 1; } @@ -827,12 +846,12 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, if (!names_only && triggers->prepare_record1_accessors(table)) DBUG_RETURN(1); - char *trg_name_buff; List_iterator_fast<ulonglong> itm(triggers->definition_modes_list); List_iterator_fast<LEX_STRING> it_definer(triggers->definers_list); LEX *old_lex= thd->lex, lex; sp_rcontext *save_spcont= thd->spcont; ulong save_sql_mode= thd->variables.sql_mode; + LEX_STRING *on_table_name; thd->lex= &lex; @@ -898,6 +917,21 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, &table->mem_root)) goto err_with_lex_cleanup; + if (!(on_table_name= (LEX_STRING*) alloc_root(&table->mem_root, + sizeof(LEX_STRING)))) + goto err_with_lex_cleanup; + *on_table_name= lex.ident; + if (triggers->on_table_names_list.push_back(on_table_name, &table->mem_root)) + goto err_with_lex_cleanup; + + /* + Let us check that we correctly update trigger definitions when we + rename tables with triggers. + */ + DBUG_ASSERT(!my_strcasecmp(table_alias_charset, lex.query_tables->db, db) && + !my_strcasecmp(table_alias_charset, lex.query_tables->table_name, + table_name)); + if (names_only) { lex_end(&lex); @@ -1063,7 +1097,7 @@ static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig) lex->query_tables= 0; lex->query_tables_last= &lex->query_tables; DBUG_RETURN(sp_add_to_query_tables(thd, lex, trig->m_db.str, - trigname.trigger_table.str, TL_WRITE)); + trigname.trigger_table.str, TL_IGNORE)); } @@ -1133,6 +1167,218 @@ end: } +/* + Update .TRG file after renaming triggers' subject table + (change name of table in triggers' definitions). + + SYNOPSIS + change_table_name_in_triggers() + thd Thread context + db_name Database of subject table + old_table_name Old subject table's name + new_table_name New subject table's name + + RETURN VALUE + FALSE Success + TRUE Failure +*/ + +bool +Table_triggers_list::change_table_name_in_triggers(THD *thd, + const char *db_name, + LEX_STRING *old_table_name, + LEX_STRING *new_table_name) +{ + char path_buff[FN_REFLEN]; + LEX_STRING *def, *on_table_name, new_def; + ulonglong *sql_mode; + ulong save_sql_mode= thd->variables.sql_mode; + List_iterator_fast<LEX_STRING> it_def(definitions_list); + List_iterator_fast<LEX_STRING> it_on_table_name(on_table_names_list); + List_iterator_fast<ulonglong> it_mode(definition_modes_list); + uint on_q_table_name_len, before_on_len; + String buff; + + DBUG_ASSERT(definitions_list.elements == on_table_names_list.elements && + definitions_list.elements == definition_modes_list.elements); + + while ((def= it_def++)) + { + on_table_name= it_on_table_name++; + thd->variables.sql_mode= *(it_mode++); + + /* Construct CREATE TRIGGER statement with new table name. */ + buff.length(0); + before_on_len= on_table_name->str - def->str; + buff.append(def->str, before_on_len); + buff.append(STRING_WITH_LEN("ON ")); + append_identifier(thd, &buff, new_table_name->str, new_table_name->length); + on_q_table_name_len= buff.length() - before_on_len; + buff.append(on_table_name->str + on_table_name->length, + def->length - (before_on_len + on_table_name->length)); + /* + It is OK to allocate some memory on table's MEM_ROOT since this + table instance will be thrown out at the end of rename anyway. + */ + new_def.str= memdup_root(&table->mem_root, buff.ptr(), buff.length()); + new_def.length= buff.length(); + on_table_name->str= new_def.str + before_on_len; + on_table_name->length= on_q_table_name_len; + *def= new_def; + } + + thd->variables.sql_mode= save_sql_mode; + + if (thd->is_fatal_error) + return TRUE; /* OOM */ + + if (save_trigger_file(this, db_name, new_table_name->str)) + return TRUE; + if (rm_trigger_file(path_buff, db_name, old_table_name->str)) + { + (void) rm_trigger_file(path_buff, db_name, new_table_name->str); + return TRUE; + } + return FALSE; +} + + +/* + Iterate though Table_triggers_list::names_list list and update .TRN files + after renaming triggers' subject table. + + SYNOPSIS + change_table_name_in_trignames() + db_name Database of subject table + new_table_name New subject table's name + stopper Pointer to Table_triggers_list::names_list at + which we should stop updating. + + RETURN VALUE + 0 Success + non-0 Failure, pointer to Table_triggers_list::names_list element + for which update failed. +*/ + +LEX_STRING* +Table_triggers_list::change_table_name_in_trignames(const char *db_name, + LEX_STRING *new_table_name, + LEX_STRING *stopper) +{ + char trigname_buff[FN_REFLEN]; + struct st_trigname trigname; + LEX_STRING trigname_file; + LEX_STRING *trigger; + List_iterator_fast<LEX_STRING> it_name(names_list); + + while ((trigger= it_name++) != stopper) + { + trigname_file.length= build_table_filename(trigname_buff, FN_REFLEN-1, + db_name, trigger->str, + trigname_file_ext); + trigname_file.str= trigname_buff; + + trigname.trigger_table= *new_table_name; + + if (sql_create_definition_file(NULL, &trigname_file, &trigname_file_type, + (gptr)&trigname, trigname_file_parameters, + 0)) + return trigger; + } + + return 0; +} + + +/* + Update .TRG and .TRN files after renaming triggers' subject table. + + SYNOPSIS + change_table_name() + thd Thread context + db Old database of subject table + old_table Old name of subject table + new_db New database for subject table + new_table New name of subject table + + NOTE + This method tries to leave trigger related files in consistent state, + i.e. it either will complete successfully, or will fail leaving files + in their initial state. + + RETURN VALUE + FALSE Success + TRUE Error +*/ + +bool Table_triggers_list::change_table_name(THD *thd, const char *db, + const char *old_table, + const char *new_db, + const char *new_table) +{ + TABLE table; + bool result= 0; + LEX_STRING *err_trigname; + DBUG_ENTER("change_table_name"); + + bzero(&table, sizeof(table)); + init_alloc_root(&table.mem_root, 8192, 0); + + safe_mutex_assert_owner(&LOCK_open); + + if (Table_triggers_list::check_n_load(thd, db, old_table, &table, TRUE)) + { + result= 1; + goto end; + } + if (table.triggers) + { + LEX_STRING_WITH_INIT old_table_name(old_table, strlen(old_table)); + LEX_STRING_WITH_INIT new_table_name(new_table, strlen(new_table)); + /* + Since triggers should be in the same schema as their subject tables + moving table with them between two schemas raises too many questions. + (E.g. what should happen if in new schema we already have trigger + with same name ?). + */ + if (my_strcasecmp(table_alias_charset, db, new_db)) + { + my_error(ER_TRG_IN_WRONG_SCHEMA, MYF(0)); + result= 1; + goto end; + } + if (table.triggers->change_table_name_in_triggers(thd, db, + &old_table_name, + &new_table_name)) + { + result= 1; + goto end; + } + if ((err_trigname= table.triggers->change_table_name_in_trignames( + db, &new_table_name, 0))) + { + /* + If we were unable to update one of .TRN files properly we will + revert all changes that we have done and report about error. + We assume that we will be able to undo our changes without errors + (we can't do much if there will be an error anyway). + */ + (void) table.triggers->change_table_name_in_trignames(db, + &old_table_name, + err_trigname); + (void) table.triggers->change_table_name_in_triggers(thd, db, + &new_table_name, + &old_table_name); + result= 1; + goto end; + } + } +end: + delete table.triggers; + free_root(&table.mem_root, MYF(0)); + DBUG_RETURN(result); +} + bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, trg_action_time_type time_type, diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 8992de63b37..b67c22e0588 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -47,6 +47,11 @@ class Table_triggers_list: public Sql_alloc */ List<LEX_STRING> names_list; /* + List of "ON table_name" parts in trigger definitions, used for + updating trigger definitions during RENAME TABLE. + */ + List<LEX_STRING> on_table_names_list; + /* Key representing triggers for this table in set of all stored routines used by statement. TODO: We won't need this member once triggers namespace will be @@ -97,7 +102,10 @@ public: static bool check_n_load(THD *thd, const char *db, const char *table_name, TABLE *table, bool names_only); static bool drop_all_triggers(THD *thd, char *db, char *table_name); - + static bool change_table_name(THD *thd, const char *db, + const char *old_table, + const char *new_db, + const char *new_table); bool has_delete_triggers() { return (bodies[TRG_EVENT_DELETE][TRG_ACTION_BEFORE] || @@ -117,6 +125,13 @@ public: private: bool prepare_record1_accessors(TABLE *table); + LEX_STRING* change_table_name_in_trignames(const char *db_name, + LEX_STRING *new_table_name, + LEX_STRING *stopper); + bool change_table_name_in_triggers(THD *thd, + const char *db_name, + LEX_STRING *old_table_name, + LEX_STRING *new_table_name); }; extern const LEX_STRING trg_action_time_type_names[]; diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 77bfba5ba28..69c5388f776 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -146,7 +146,7 @@ void udf_init() if (simple_open_n_lock_tables(new_thd, &tables)) { DBUG_PRINT("error",("Can't open udf table")); - sql_print_error("Can't open the mysql.func table. Please run the mysql_install_db script to create it."); + sql_print_error("Can't open the mysql.func table. Please run the mysql_upgrade script to create it."); goto end; } @@ -284,6 +284,10 @@ static void del_udf(udf_func *udf) void free_udf(udf_func *udf) { DBUG_ENTER("free_udf"); + + if (!initialized) + DBUG_VOID_RETURN; + rw_wrlock(&THR_LOCK_udf); if (!--udf->usage_count) { @@ -308,6 +312,9 @@ udf_func *find_udf(const char *name,uint length,bool mark_used) udf_func *udf=0; DBUG_ENTER("find_udf"); + if (!initialized) + DBUG_RETURN(NULL); + /* TODO: This should be changed to reader locks someday! */ if (mark_used) rw_wrlock(&THR_LOCK_udf); /* Called during fix_fields */ diff --git a/sql/sql_update.cc b/sql/sql_update.cc index b1abf2c0777..b19d6504b2e 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -158,7 +158,7 @@ int mysql_update(THD *thd, break; if (!need_reopen) DBUG_RETURN(1); - close_tables_for_reopen(thd, table_list); + close_tables_for_reopen(thd, &table_list); } if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) || @@ -958,7 +958,7 @@ reopen_tables: for (TABLE_LIST *tbl= table_list; tbl; tbl= tbl->next_global) tbl->cleanup_items(); - close_tables_for_reopen(thd, table_list); + close_tables_for_reopen(thd, &table_list); goto reopen_tables; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 2c7f17a7a99..a744d941a4b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -48,12 +48,7 @@ const LEX_STRING null_lex_str={0,0}; #define yyoverflow(A,B,C,D,E,F) {ulong val= *(F); if (my_yyoverflow((B), (D), &val)) { yyerror((char*) (A)); return 2; } else { *(F)= (YYSIZE_T)val; }} -#define WARN_DEPRECATED(A,B) \ - push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, \ - ER_WARN_DEPRECATED_SYNTAX, \ - ER(ER_WARN_DEPRECATED_SYNTAX), (A), (B)); - -#define YYERROR_UNLESS(A) \ +#define YYERROR_UNLESS(A) \ if (!(A)) \ { \ yyerror(ER(ER_SYNTAX_ERROR)); \ @@ -1343,7 +1338,7 @@ create: lex->create_info.options= $3; - if (!(lex->et= new event_timed())) // implicitly calls event_timed::init() + if (!(lex->et= new Event_timed())) // implicitly calls Event_timed::init() YYABORT; /* @@ -1419,6 +1414,8 @@ ev_schedule_time: EVERY_SYM expr interval break; case EVEX_BAD_PARAMS: my_error(ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG, MYF(0)); + case EVEX_MICROSECOND_UNSUP: + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "MICROSECOND"); YYABORT; break; } @@ -1474,6 +1471,9 @@ opt_ev_status: /* empty */ { $$= 0; } ; ev_starts: /* empty */ + { + Lex->et->init_starts(YYTHD, new Item_func_now_local()); + } | STARTS_SYM expr { LEX *lex= Lex; @@ -1679,6 +1679,16 @@ create_function_tail: LEX *lex= Lex; sp_head *sp; + /* + First check if AGGREGATE was used, in that case it's a + syntax error. + */ + if (lex->udf.type == UDFTYPE_AGGREGATE) + { + my_error(ER_SP_NO_AGGREGATE, MYF(0)); + YYABORT; + } + if (lex->sphead) { my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION"); @@ -3474,7 +3484,7 @@ part_func: uint expr_len= (uint)($4 - $2) - 1; lex->part_info->list_of_part_fields= FALSE; lex->part_info->part_expr= $3; - lex->part_info->part_func_string= $2+1; + lex->part_info->part_func_string= (char* ) sql_memdup($2+1, expr_len); lex->part_info->part_func_len= expr_len; } ; @@ -3486,7 +3496,7 @@ sub_part_func: uint expr_len= (uint)($4 - $2) - 1; lex->part_info->list_of_subpart_fields= FALSE; lex->part_info->subpart_expr= $3; - lex->part_info->subpart_func_string= $2+1; + lex->part_info->subpart_func_string= (char* ) sql_memdup($2+1, expr_len); lex->part_info->subpart_func_len= expr_len; } ; @@ -3994,6 +4004,13 @@ create_table_options: create_table_option: ENGINE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; } + | TYPE_SYM opt_equal storage_engines + { + Lex->create_info.db_type= $3; + WARN_DEPRECATED(yythd, "5.2", "TYPE=storage_engine", + "'ENGINE=storage_engine'"); + Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; + } | MAX_ROWS opt_equal ulonglong_num { Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;} | MIN_ROWS opt_equal ulonglong_num { Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;} | AVG_ROW_LENGTH opt_equal ulong_num { Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;} @@ -4807,7 +4824,7 @@ alter: */ { LEX *lex=Lex; - event_timed *et; + Event_timed *et; if (lex->et) { @@ -4820,7 +4837,7 @@ alter: } lex->spname= 0;//defensive programming - if (!(et= new event_timed()))// implicitly calls event_timed::init() + if (!(et= new Event_timed()))// implicitly calls Event_timed::init() YYABORT; lex->et = et; @@ -4896,7 +4913,7 @@ opt_ev_rename_to: /* empty */ { $$= 0;} { LEX *lex=Lex; lex->spname= $3; //use lex's spname to hold the new name - //the original name is in the event_timed object + //the original name is in the Event_timed object $$= 1; } ; @@ -5350,11 +5367,8 @@ restore: RESTORE_SYM table_or_tables { Lex->sql_command = SQLCOM_RESTORE_TABLE; - push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_STATEMENT, - ER(ER_WARN_DEPRECATED_STATEMENT), - "RESTORE TABLE", "5.2", - "mysqldump, mysql, MySQL Administrator"); + WARN_DEPRECATED(yythd, "5.2", "RESTORE TABLE", + "MySQL Administrator (mysqldump, mysql)"); } table_list FROM TEXT_STRING_sys { @@ -5365,11 +5379,8 @@ backup: BACKUP_SYM table_or_tables { Lex->sql_command = SQLCOM_BACKUP_TABLE; - push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_STATEMENT, - ER(ER_WARN_DEPRECATED_STATEMENT), - "BACKUP TABLE", "5.2", - "mysqldump, mysql, MySQL Administrator"); + WARN_DEPRECATED(yythd, "5.2", "BACKUP TABLE", + "MySQL Administrator (mysqldump, mysql)"); } table_list TO_SYM TEXT_STRING_sys { @@ -7719,7 +7730,7 @@ drop: YYABORT; } - if (!(lex->et= new event_timed())) + if (!(lex->et= new Event_timed())) YYABORT; if (!lex->et_compile_phase) @@ -8212,7 +8223,7 @@ show_param: { LEX *lex=Lex; lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES; - WARN_DEPRECATED("SHOW TABLE TYPES", "SHOW [STORAGE] ENGINES"); + WARN_DEPRECATED(yythd, "5.2", "SHOW TABLE TYPES", "'SHOW [STORAGE] ENGINES'"); } | opt_storage ENGINES_SYM { @@ -8248,7 +8259,7 @@ show_param: lex->option_type= $1; if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS)) YYABORT; - } + } | INNOBASE_SYM STATUS_SYM { LEX *lex= Lex; @@ -8259,19 +8270,19 @@ show_param: my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB"); YYABORT; } - WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); + WARN_DEPRECATED(yythd, "5.2", "SHOW INNODB STATUS", "'SHOW ENGINE INNODB STATUS'"); } | MUTEX_SYM STATUS_SYM { LEX *lex= Lex; - lex->sql_command = SQLCOM_SHOW_ENGINE_MUTEX; + lex->sql_command = SQLCOM_SHOW_ENGINE_MUTEX; if (!(lex->create_info.db_type= ha_resolve_by_legacy_type(YYTHD, DB_TYPE_INNODB))) { my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB"); YYABORT; } - WARN_DEPRECATED("SHOW MUTEX STATUS", "SHOW ENGINE INNODB MUTEX"); + WARN_DEPRECATED(yythd, "5.2", "SHOW MUTEX STATUS", "'SHOW ENGINE INNODB MUTEX'"); } | opt_full PROCESSLIST_SYM { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;} @@ -8310,7 +8321,7 @@ show_param: my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "BerkeleyDB"); YYABORT; } - WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); + WARN_DEPRECATED(yythd, "5.2", "SHOW BDB LOGS", "'SHOW ENGINE BDB LOGS'"); } | LOGS_SYM { @@ -8322,7 +8333,7 @@ show_param: my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "BerkeleyDB"); YYABORT; } - WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); + WARN_DEPRECATED(yythd, "5.2", "SHOW LOGS", "'SHOW ENGINE BDB LOGS'"); } | GRANTS { @@ -8443,7 +8454,7 @@ show_param: { Lex->sql_command = SQLCOM_SHOW_CREATE_EVENT; Lex->spname= $3; - Lex->et= new event_timed(); + Lex->et= new Event_timed(); if (!Lex->et) YYABORT; Lex->et->init_definer(YYTHD); @@ -8676,11 +8687,8 @@ load: LOAD DATA_SYM LOAD TABLE_SYM table_ident FROM MASTER_SYM { LEX *lex=Lex; - push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_STATEMENT, - ER(ER_WARN_DEPRECATED_STATEMENT), - "LOAD TABLE FROM MASTER", "5.2", - "mysqldump, mysql, MySQL Administrator"); + WARN_DEPRECATED(yythd, "5.2", "LOAD TABLE FROM MASTER", + "MySQL Administrator (mysqldump, mysql)"); if (lex->sphead) { my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD TABLE"); @@ -10919,7 +10927,7 @@ view_check_option: trigger_tail: TRIGGER_SYM remember_name sp_name trg_action_time trg_event - ON table_ident FOR_SYM EACH_SYM ROW_SYM + ON remember_name table_ident remember_end FOR_SYM EACH_SYM ROW_SYM { LEX *lex= Lex; sp_head *sp; @@ -10936,6 +10944,8 @@ trigger_tail: sp->init(lex); lex->trigger_definition_begin= $2; + lex->ident.str= $7; + lex->ident.length= $9 - $7; sp->m_type= TYPE_ENUM_TRIGGER; lex->sphead= sp; @@ -10963,7 +10973,7 @@ trigger_tail: sp->init_strings(YYTHD, lex, $3); /* Restore flag if it was cleared above */ - YYTHD->client_capabilities |= $<ulong_num>11; + YYTHD->client_capabilities |= $<ulong_num>13; sp->restore_thd_mem_root(YYTHD); if (sp->is_not_allowed_in_function("trigger")) @@ -10973,15 +10983,11 @@ trigger_tail: We have to do it after parsing trigger body, because some of sp_proc_stmt alternatives are not saving/restoring LEX, so lex->query_tables can be wiped out. - - QQ: What are other consequences of this? - - QQ: Could we loosen lock type in certain cases ? */ - if (!lex->select_lex.add_table_to_list(YYTHD, $7, + if (!lex->select_lex.add_table_to_list(YYTHD, $8, (LEX_STRING*) 0, TL_OPTION_UPDATING, - TL_WRITE)) + TL_IGNORE)) YYABORT; } ; diff --git a/sql/table.cc b/sql/table.cc index 7c266243d29..d6a715ae1b4 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -130,6 +130,24 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, share->version= refresh_version; share->flush_version= flush_version; +#ifdef HAVE_ROW_BASED_REPLICATION + /* + This constant is used to mark that no table map version has been + assigned. No arithmetic is done on the value: it will be + overwritten with a value taken from MYSQL_BIN_LOG. + */ + share->table_map_version= ~(ulonglong)0; + + /* + Since alloc_table_share() can be called without any locking (for + example, ha_create_table... functions), we do not assign a table + map id here. Instead we assign a value that is not used + elsewhere, and then assign a table map id inside open_table() + under the protection of the LOCK_open mutex. + */ + share->table_map_id= ULONG_MAX; +#endif + memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); pthread_cond_init(&share->cond, NULL); @@ -180,6 +198,15 @@ void init_tmp_table_share(TABLE_SHARE *share, const char *key, share->path.length= share->normalized_path.length= strlen(path); share->frm_version= FRM_VER_TRUE_VARCHAR; +#ifdef HAVE_ROW_BASED_REPLICATION + /* + Temporary tables are not replicated, but we set up these fields + anyway to be able to catch errors. + */ + share->table_map_version= ~(ulonglong)0; + share->table_map_id= ULONG_MAX; +#endif + DBUG_VOID_RETURN; } @@ -371,6 +398,7 @@ err_not_open: share->error= error; open_table_error(share, error, (share->open_errno= my_errno), 0); } + DBUG_RETURN(error); } @@ -1503,24 +1531,6 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, *root_ptr= old_root; thd->status_var.opened_tables++; -#ifdef HAVE_REPLICATION - - /* - This constant is used to mark that no table map version has been - assigned. No arithmetic is done on the value: it will be - overwritten with a value taken from MYSQL_BIN_LOG. - */ - share->table_map_version= ~(ulonglong)0; - - /* - Since openfrm() can be called without any locking (for example, - ha_create_table... functions), we do not assign a table map id - here. Instead we assign a value that is not used elsewhere, and - then assign a table map id inside open_table() under the - protection of the LOCK_open mutex. - */ - share->table_map_id= ULONG_MAX; -#endif DBUG_RETURN (0); @@ -3326,8 +3336,15 @@ const char *Natural_join_column::db_name() if (view_field) return table_ref->view_db.str; + /* + Test that TABLE_LIST::db is the same as st_table_share::db to + ensure consistency. An exception are I_S schema tables, which + are inconsistent in this respect. + */ DBUG_ASSERT(!strcmp(table_ref->db, - table_ref->table->s->db.str)); + table_ref->table->s->db.str) || + (table_ref->schema_table && + table_ref->table->s->db.str[0] == 0)); return table_ref->db; } @@ -3529,7 +3546,15 @@ const char *Field_iterator_table_ref::db_name() else if (table_ref->is_natural_join) return natural_join_it.column_ref()->db_name(); - DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str)); + /* + Test that TABLE_LIST::db is the same as st_table_share::db to + ensure consistency. An exception are I_S schema tables, which + are inconsistent in this respect. + */ + DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) || + (table_ref->schema_table && + table_ref->table->s->db.str[0] == 0)); + return table_ref->db; } diff --git a/sql/table.h b/sql/table.h index d1009ade09b..2bde68e5919 100644 --- a/sql/table.h +++ b/sql/table.h @@ -216,6 +216,8 @@ typedef struct st_table_share /* Information for one open table */ struct st_table { + st_table() {} /* Remove gcc warning */ + TABLE_SHARE *s; handler *file; #ifdef NOT_YET @@ -490,6 +492,7 @@ public: typedef struct st_table_list { + st_table_list() {} /* Remove gcc warning */ /* List of tables local to a subquery (used by SQL_LIST). Considers views as leaves (unlike 'next_leaf' below). Created at parse time @@ -722,6 +725,7 @@ class Item; class Field_iterator: public Sql_alloc { public: + Field_iterator() {} /* Remove gcc warning */ virtual ~Field_iterator() {} virtual void set(TABLE_LIST *)= 0; virtual void next()= 0; diff --git a/sql/tztime.cc b/sql/tztime.cc index 96eb31449da..94c1eb8ac63 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -973,6 +973,7 @@ static const String tz_SYSTEM_name("SYSTEM", 6, &my_charset_latin1); class Time_zone_system : public Time_zone { public: + Time_zone_system() {} /* Remove gcc warning */ virtual my_time_t TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const; virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const; @@ -1066,6 +1067,7 @@ Time_zone_system::get_name() const class Time_zone_utc : public Time_zone { public: + Time_zone_utc() {} /* Remove gcc warning */ virtual my_time_t TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const; virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const; diff --git a/sql/tztime.h b/sql/tztime.h index 2d574eadf18..42e50988e52 100644 --- a/sql/tztime.h +++ b/sql/tztime.h @@ -30,6 +30,7 @@ class Time_zone: public Sql_alloc { public: + Time_zone() {} /* Remove gcc warning */ /* Converts local time in broken down TIME representation to my_time_t (UTC seconds since Epoch) represenation. diff --git a/sql/udf_example.cc b/sql/udf_example.cc index a186b4fbf6c..35833e63fab 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -144,6 +144,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, my_bool myfunc_double_init(UDF_INIT *, UDF_ARGS *args, char *message); double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); +my_bool myfunc_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message); longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); my_bool sequence_init(UDF_INIT *initid, UDF_ARGS *args, char *message); @@ -597,6 +598,14 @@ longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, return val; } +/* + At least one of _init/_deinit is needed unless the server is started + with --allow_suspicious_udfs. +*/ +my_bool myfunc_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + return 0; +} /* Simple example of how to get a sequences starting from the first argument diff --git a/storage/archive/Makefile.am b/storage/archive/Makefile.am index fabeca81eda..c2ae9d6b728 100644 --- a/storage/archive/Makefile.am +++ b/storage/archive/Makefile.am @@ -17,9 +17,10 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ @ZLIB_INCLUDES@ -LDADD = libarchive.a $(top_srcdir)/mysys/libmysys.a \ - $(top_srcdir)/dbug/libdbug.a \ - $(top_srcdir)/strings/libmystrings.a \ +LDADD = libarchive.a \ + $(top_builddir)/mysys/libmysys.a \ + $(top_builddir)/dbug/libdbug.a \ + $(top_builddir)/strings/libmystrings.a \ @ZLIB_LIBS@ pkglib_LIBRARIES = libarchive.a noinst_PROGRAMS = archive_test diff --git a/storage/csv/Makefile.am b/storage/csv/Makefile.am index 509cef954ff..5573df720a3 100644 --- a/storage/csv/Makefile.am +++ b/storage/csv/Makefile.am @@ -20,7 +20,8 @@ MYSQLDATAdir = $(localstatedir) MYSQLSHAREdir = $(pkgdatadir) MYSQLBASEdir= $(prefix) MYSQLLIBdir= $(pkglibdir) -INCLUDES = -I$(top_srcdir)/include \ +INCLUDES = -I$(top_builddir)/include \ + -I$(top_srcdir)/include \ -I$(top_srcdir)/regex \ -I$(top_srcdir)/sql \ -I$(srcdir) diff --git a/storage/heap/Makefile.am b/storage/heap/Makefile.am index 2890dc6ee23..79e0379f9a4 100644 --- a/storage/heap/Makefile.am +++ b/storage/heap/Makefile.am @@ -15,9 +15,10 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -LDADD = libheap.a $(top_srcdir)/mysys/libmysys.a \ - $(top_srcdir)/dbug/libdbug.a \ - $(top_srcdir)/strings/libmystrings.a +LDADD = libheap.a \ + $(top_builddir)/mysys/libmysys.a \ + $(top_builddir)/dbug/libdbug.a \ + $(top_builddir)/strings/libmystrings.a pkglib_LIBRARIES = libheap.a noinst_PROGRAMS = hp_test1 hp_test2 hp_test1_LDFLAGS = @NOINST_LDFLAGS@ diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 9ce1dff51af..eb2f42697ce 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -3900,9 +3900,6 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) create_info.data_file_length=file_length; create_info.auto_increment=share.state.auto_increment; - create_info.raid_type= share.base.raid_type; - create_info.raid_chunks= share.base.raid_chunks; - create_info.raid_chunksize= share.base.raid_chunksize; create_info.language = (param->language ? param->language : share.state.header.language); create_info.key_file_length= status_info.key_file_length; diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c index cdcd7b95ce1..36d88bd362a 100644 --- a/storage/myisam/mi_dynrec.c +++ b/storage/myisam/mi_dynrec.c @@ -201,6 +201,7 @@ uint mi_mmap_pwrite(MI_INFO *info, byte *Buffer, } else { + info->s->nonmmaped_inserts++; if (info->s->concurrent_insert) rw_unlock(&info->s->mmap_lock); return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); diff --git a/storage/myisam/mi_info.c b/storage/myisam/mi_info.c index bdece9c2ee3..ebe59d82f0e 100644 --- a/storage/myisam/mi_info.c +++ b/storage/myisam/mi_info.c @@ -85,13 +85,6 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag) x->key_map = share->state.key_map; x->data_file_name = share->data_file_name; x->index_file_name = share->index_file_name; - /* - The following should be included even if we are not compiling with - USE_RAID as the client must be able to request it! - */ - x->raid_type= share->base.raid_type; - x->raid_chunks= share->base.raid_chunks; - x->raid_chunksize= share->base.raid_chunksize; } if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0))) x->update_time=state.st_mtime; diff --git a/storage/myisam/mi_locking.c b/storage/myisam/mi_locking.c index 7c418cb9531..ecb737867f5 100644 --- a/storage/myisam/mi_locking.c +++ b/storage/myisam/mi_locking.c @@ -85,11 +85,13 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (share->changed && !share->w_locks) { #ifdef HAVE_MMAP - if (info->s->mmaped_length != info->s->state.state.data_file_length) + if ((info->s->mmaped_length != info->s->state.state.data_file_length) && + (info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS)) { if (info->s->concurrent_insert) rw_wrlock(&info->s->mmap_lock); mi_remap_file(info, info->s->state.state.data_file_length); + info->s->nonmmaped_inserts= 0; if (info->s->concurrent_insert) rw_unlock(&info->s->mmap_lock); } diff --git a/storage/myisam/myisam_ftdump.c b/storage/myisam/myisam_ftdump.c index 28aac0a8ecf..edf1af144d4 100644 --- a/storage/myisam/myisam_ftdump.c +++ b/storage/myisam/myisam_ftdump.c @@ -86,7 +86,7 @@ int main(int argc,char *argv[]) init_key_cache(dflt_key_cache,MI_KEY_BLOCK_LENGTH,USE_BUFFER_INIT, 0, 0); - if (!(info=mi_open(argv[0],2,HA_OPEN_ABORT_IF_LOCKED))) + if (!(info=mi_open(argv[0],2,HA_OPEN_ABORT_IF_LOCKED|HA_OPEN_FROM_SQL_LAYER))) { error=my_errno; goto err; diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index 4e5c6be68fd..caf6254c321 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -152,6 +152,7 @@ typedef struct st_mi_isam_pack { uchar version; } MI_PACK; +#define MAX_NONMAPPED_INSERTS 1000 typedef struct st_mi_isam_share { /* Shared between opens */ MI_STATE_INFO state; @@ -211,6 +212,8 @@ typedef struct st_mi_isam_share { /* Shared between opens */ rw_lock_t *key_root_lock; #endif my_off_t mmaped_length; + uint nonmmaped_inserts; /* counter of writing in non-mmaped + area */ rw_lock_t mmap_lock; } MYISAM_SHARE; diff --git a/storage/myisammrg/myrg_queue.c b/storage/myisammrg/myrg_queue.c index 7172b9f0e2a..2e600a526c0 100644 --- a/storage/myisammrg/myrg_queue.c +++ b/storage/myisammrg/myrg_queue.c @@ -18,12 +18,26 @@ static int queue_key_cmp(void *keyseg, byte *a, byte *b) { - MI_INFO *aa=((MYRG_TABLE *)a)->table; - MI_INFO *bb=((MYRG_TABLE *)b)->table; + MYRG_TABLE *ma= (MYRG_TABLE *)a; + MYRG_TABLE *mb= (MYRG_TABLE *)b; + MI_INFO *aa= ma->table; + MI_INFO *bb= mb->table; uint not_used[2]; int ret= ha_key_cmp((HA_KEYSEG *)keyseg, aa->lastkey, bb->lastkey, USE_WHOLE_KEY, SEARCH_FIND, not_used); - return ret < 0 ? -1 : ret > 0 ? 1 : 0; + if (ret < 0) + return -1; + if (ret > 0) + return 1; + + /* + If index tuples have the same values, let the record with least rowid + value be "smaller", so index scans return records ordered by (keytuple, + rowid). This is used by index_merge access method, grep for ROR in + sql/opt_range.cc for details. + */ + return (ma->file_offset < mb->file_offset)? -1 : (ma->file_offset > + mb->file_offset) ? 1 : 0; } /* queue_key_cmp */ diff --git a/storage/ndb/include/kernel/ndb_limits.h b/storage/ndb/include/kernel/ndb_limits.h index ef6b8370888..6bf9256bf95 100644 --- a/storage/ndb/include/kernel/ndb_limits.h +++ b/storage/ndb/include/kernel/ndb_limits.h @@ -66,6 +66,7 @@ #define MAX_FRAGMENT_DATA_BYTES (4+(2 * 8 * MAX_REPLICAS * MAX_NDB_NODES)) #define MAX_NDB_PARTITIONS 1024 #define MAX_RANGE_DATA (131072+MAX_NDB_PARTITIONS) //0.5 MByte of list data +#define MAX_WORDS_META_FILE 16382 #define MIN_ATTRBUF ((MAX_ATTRIBUTES_IN_TABLE/24) + 1) /* diff --git a/storage/ndb/include/kernel/signaldata/AlterTable.hpp b/storage/ndb/include/kernel/signaldata/AlterTable.hpp index 427179a389f..1cdc7c00fcb 100644 --- a/storage/ndb/include/kernel/signaldata/AlterTable.hpp +++ b/storage/ndb/include/kernel/signaldata/AlterTable.hpp @@ -39,6 +39,7 @@ class AlterTableReq { friend class NdbEventOperationImpl; friend class NdbDictInterface; friend class Dbdict; + friend class Suma; /** * For printing diff --git a/storage/ndb/include/ndbapi/NdbDictionary.hpp b/storage/ndb/include/ndbapi/NdbDictionary.hpp index f3a017f8c49..63b3d407e65 100644 --- a/storage/ndb/include/ndbapi/NdbDictionary.hpp +++ b/storage/ndb/include/ndbapi/NdbDictionary.hpp @@ -61,12 +61,15 @@ typedef struct charset_info_st CHARSET_INFO; */ class NdbDictionary { public: + NdbDictionary() {} /* Remove gcc warning */ /** * @class Object * @brief Meta information about a database object (a table, index, etc) */ class Object { public: + Object() {} /* Remove gcc warning */ + virtual ~Object() {} /* Remove gcc warning */ /** * Status of object */ @@ -1598,6 +1601,14 @@ public: */ const Table * getTable(const char * name) const; +#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL + /* + * Save a table definition in dictionary cache + * @param table Object to put into cache + */ + void putTable(const Table * table); +#endif + /** * Get index with given name, NULL if undefined * @param indexName Name of index to get. diff --git a/storage/ndb/include/ndbapi/NdbEventOperation.hpp b/storage/ndb/include/ndbapi/NdbEventOperation.hpp index 698b66ce701..25d7b8c6644 100644 --- a/storage/ndb/include/ndbapi/NdbEventOperation.hpp +++ b/storage/ndb/include/ndbapi/NdbEventOperation.hpp @@ -220,6 +220,7 @@ public: #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** these are subject to change at any time */ + const NdbDictionary::Table* getTable() const; const NdbDictionary::Event *getEvent() const; const NdbRecAttr *getFirstPkAttr() const; const NdbRecAttr *getFirstPkPreAttr() const; diff --git a/storage/ndb/src/common/transporter/Transporter.cpp b/storage/ndb/src/common/transporter/Transporter.cpp index 377fabe27ab..820aa4cfc18 100644 --- a/storage/ndb/src/common/transporter/Transporter.cpp +++ b/storage/ndb/src/common/transporter/Transporter.cpp @@ -105,10 +105,10 @@ Transporter::connect_server(NDB_SOCKET_TYPE sockfd) { } { - struct sockaddr addr; + struct sockaddr_in addr; SOCKET_SIZE_TYPE addrlen= sizeof(addr); - int r= getpeername(sockfd, &addr, &addrlen); - m_connect_address= ((struct sockaddr_in *)&addr)->sin_addr; + int r= getpeername(sockfd, (struct sockaddr*)&addr, &addrlen); + m_connect_address= (&addr)->sin_addr; } bool res = connect_server_impl(sockfd); @@ -198,10 +198,10 @@ Transporter::connect_client(NDB_SOCKET_TYPE sockfd) { } { - struct sockaddr addr; + struct sockaddr_in addr; SOCKET_SIZE_TYPE addrlen= sizeof(addr); - int r= getpeername(sockfd, &addr, &addrlen); - m_connect_address= ((struct sockaddr_in *)&addr)->sin_addr; + int r= getpeername(sockfd, (struct sockaddr*)&addr, &addrlen); + m_connect_address= (&addr)->sin_addr; } bool res = connect_client_impl(sockfd); diff --git a/storage/ndb/src/kernel/blocks/backup/Backup.hpp b/storage/ndb/src/kernel/blocks/backup/Backup.hpp index dcbd878b201..5eb1a6d0e23 100644 --- a/storage/ndb/src/kernel/blocks/backup/Backup.hpp +++ b/storage/ndb/src/kernel/blocks/backup/Backup.hpp @@ -530,7 +530,7 @@ public: Config c_defaults; Uint32 m_diskless; - STATIC_CONST(NO_OF_PAGES_META_FILE = 2); + STATIC_CONST(NO_OF_PAGES_META_FILE = MAX_WORDS_META_FILE/BACKUP_WORDS_PER_PAGE); /** * Pools diff --git a/storage/ndb/src/kernel/blocks/suma/Suma.cpp b/storage/ndb/src/kernel/blocks/suma/Suma.cpp index 76cce0ff254..c91f16cdb57 100644 --- a/storage/ndb/src/kernel/blocks/suma/Suma.cpp +++ b/storage/ndb/src/kernel/blocks/suma/Suma.cpp @@ -42,6 +42,7 @@ #include <signaldata/GCPSave.hpp> #include <signaldata/CreateTab.hpp> #include <signaldata/DropTab.hpp> +#include <signaldata/AlterTable.hpp> #include <signaldata/AlterTab.hpp> #include <signaldata/DihFragCount.hpp> #include <signaldata/SystemError.hpp> @@ -3440,7 +3441,7 @@ Suma::execDROP_TAB_CONF(Signal *signal) DBUG_VOID_RETURN; } -static Uint32 b_dti_buf[10000]; +static Uint32 b_dti_buf[MAX_WORDS_META_FILE]; void Suma::execALTER_TAB_REQ(Signal *signal) @@ -3462,7 +3463,7 @@ Suma::execALTER_TAB_REQ(Signal *signal) } DBUG_PRINT("info",("alter table id: %d[i=%u]", tableId, tabPtr.i)); - + Table::State old_state = tabPtr.p->m_state; tabPtr.p->m_state = Table::ALTERED; // triggers must be removed, waiting for sub stop req for that @@ -3520,6 +3521,11 @@ Suma::execALTER_TAB_REQ(Signal *signal) DBUG_PRINT("info",("sent to subscriber %d", subbPtr.i)); } } + if (AlterTableReq::getFrmFlag(changeMask)) + { + // Frm changes only are handled on-line + tabPtr.p->m_state = old_state; + } DBUG_VOID_RETURN; } diff --git a/storage/ndb/src/mgmsrv/Services.cpp b/storage/ndb/src/mgmsrv/Services.cpp index 3564c5c40ba..aebadec933c 100644 --- a/storage/ndb/src/mgmsrv/Services.cpp +++ b/storage/ndb/src/mgmsrv/Services.cpp @@ -451,9 +451,9 @@ MgmApiSession::get_nodeid(Parser_t::Context &, return; } - struct sockaddr addr; + struct sockaddr_in addr; SOCKET_SIZE_TYPE addrlen= sizeof(addr); - int r = getpeername(m_socket, &addr, &addrlen); + int r = getpeername(m_socket, (struct sockaddr*)&addr, &addrlen); if (r != 0 ) { m_output->println(cmd); m_output->println("result: getpeername(%d) failed, err= %d", m_socket, r); @@ -465,7 +465,7 @@ MgmApiSession::get_nodeid(Parser_t::Context &, if(tmp == 0 || !m_allocated_resources->is_reserved(tmp)){ BaseString error_string; if (!m_mgmsrv.alloc_node_id(&tmp, (enum ndb_mgm_node_type)nodetype, - &addr, &addrlen, error_string)){ + (struct sockaddr*)&addr, &addrlen, error_string)){ const char *alias; const char *str; alias= ndb_mgm_get_node_type_alias_string((enum ndb_mgm_node_type) diff --git a/storage/ndb/src/ndbapi/Ndb.cpp b/storage/ndb/src/ndbapi/Ndb.cpp index 75b8f58a813..fefd573b2ff 100644 --- a/storage/ndb/src/ndbapi/Ndb.cpp +++ b/storage/ndb/src/ndbapi/Ndb.cpp @@ -1200,7 +1200,7 @@ Ndb::internalize_index_name(const NdbTableImpl * table, if (!table) { DBUG_PRINT("error", ("!table")); - return ret; + DBUG_RETURN(ret); } if (fullyQualifiedNames) diff --git a/storage/ndb/src/ndbapi/NdbDictionary.cpp b/storage/ndb/src/ndbapi/NdbDictionary.cpp index e64f5968ed2..6e777599fd6 100644 --- a/storage/ndb/src/ndbapi/NdbDictionary.cpp +++ b/storage/ndb/src/ndbapi/NdbDictionary.cpp @@ -1349,6 +1349,13 @@ NdbDictionary::Dictionary::getTable(const char * name, void **data) const return 0; } +void NdbDictionary::Dictionary::putTable(const NdbDictionary::Table * table) +{ + NdbDictionary::Table *copy_table = new NdbDictionary::Table; + *copy_table = *table; + m_impl.putTable(&NdbTableImpl::getImpl(*copy_table)); +} + void NdbDictionary::Dictionary::set_local_table_data_size(unsigned sz) { m_impl.m_local_table_data_size= sz; diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 41168bb9279..3f2752172c9 100644 --- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -1305,7 +1305,16 @@ NdbDictionaryImpl::fetchGlobalTableImpl(const BaseString& internalTableName) void NdbDictionaryImpl::putTable(NdbTableImpl *impl) { + NdbTableImpl *old; + m_globalHash->lock(); + if ((old= m_globalHash->get(impl->m_internalName.c_str()))) + { + m_globalHash->alter_table_rep(old->m_internalName.c_str(), + impl->m_id, + impl->m_version, + FALSE); + } m_globalHash->put(impl->m_internalName.c_str(), impl); m_globalHash->unlock(); Ndb_local_table_info *info= @@ -1313,6 +1322,8 @@ NdbDictionaryImpl::putTable(NdbTableImpl *impl) m_localHash.put(impl->m_internalName.c_str(), info); + addBlobTables(*impl); + m_ndb.theFirstTupleId[impl->getTableId()] = ~0; m_ndb.theLastTupleId[impl->getTableId()] = ~0; } @@ -2045,59 +2056,94 @@ int NdbDictionaryImpl::createTable(NdbTableImpl &t) { DBUG_ENTER("NdbDictionaryImpl::createTable"); - // If the a new name has not been set, used the copied name + + // if the new name has not been set, use the copied name if (t.m_newExternalName.empty()) t.m_newExternalName.assign(t.m_externalName); + + // create table if (m_receiver.createTable(m_ndb, t) != 0) - { + DBUG_RETURN(-1); + Uint32* data = (Uint32*)m_receiver.m_buffer.get_data(); + t.m_id = data[0]; + t.m_version = data[1]; + + // update table def from DICT - by-pass cache + NdbTableImpl* t2 = + m_receiver.getTable(t.m_internalName, m_ndb.usingFullyQualifiedNames()); + + // check if we got back same table + if (t2 == NULL) { + DBUG_PRINT("info", ("table %s dropped by another thread", + t.m_internalName.c_str())); + m_error.code = 283; DBUG_RETURN(-1); } - if (t.m_noOfBlobs == 0) - { - DBUG_RETURN(0); - } - // update table def from DICT - Ndb_local_table_info *info= - get_local_table_info(t.m_internalName,false); - if (info == NULL) { - m_error.code= 709; + if (t.m_id != t2->m_id || t.m_version != t2->m_version) { + DBUG_PRINT("info", ("table %s re-created by another thread", + t.m_internalName.c_str())); + m_error.code = 283; + delete t2; DBUG_RETURN(-1); } - if (createBlobTables(t, *(info->m_table_impl)) != 0) { + + // auto-increment - use "t" because initial value is not in DICT + { + bool autoIncrement = false; + Uint64 initialValue = 0; + for (Uint32 i = 0; i < t.m_columns.size(); i++) { + const NdbColumnImpl* c = t.m_columns[i]; + assert(c != NULL); + if (c->m_autoIncrement) { + if (autoIncrement) { + m_error.code = 4335; + delete t2; + DBUG_RETURN(-1); + } + autoIncrement = true; + initialValue = c->m_autoIncrementInitialValue; + } + } + if (autoIncrement) { + // XXX unlikely race condition - t.m_id may no longer be same table + if (! m_ndb.setTupleIdInNdb(t.m_id, initialValue, false)) { + if (m_ndb.theError.code) + m_error.code = m_ndb.theError.code; + else + m_error.code = 4336; + delete t2; + DBUG_RETURN(-1); + } + } + } + + // blob tables - use "t2" to get values set by kernel + if (t2->m_noOfBlobs != 0 && createBlobTables(*t2) != 0) { int save_code = m_error.code; - (void)dropTable(t); - m_error.code= save_code; + (void)dropTable(*t2); + m_error.code = save_code; + delete t2; DBUG_RETURN(-1); } + + // not entered in cache + delete t2; DBUG_RETURN(0); } int -NdbDictionaryImpl::createBlobTables(NdbTableImpl& org, NdbTableImpl &t) +NdbDictionaryImpl::createBlobTables(NdbTableImpl &t) { DBUG_ENTER("NdbDictionaryImpl::createBlobTables"); for (unsigned i = 0; i < t.m_columns.size(); i++) { NdbColumnImpl & c = *t.m_columns[i]; - NdbColumnImpl & oc = *org.m_columns[i]; if (! c.getBlobType() || c.getPartSize() == 0) continue; NdbTableImpl bt; - NdbDictionary::Column::StorageType save = c.getStorageType(); - c.setStorageType(oc.getStorageType()); NdbBlob::getBlobTable(bt, &t, &c); - c.setStorageType(save); - if (createTable(bt) != 0) - { - DBUG_RETURN(-1); - } - // Save BLOB table handle - Ndb_local_table_info *info= - get_local_table_info(bt.m_internalName, false); - if (info == 0) - { + if (createTable(bt) != 0) { DBUG_RETURN(-1); } - c.m_blobTable = info->m_table_impl; } DBUG_RETURN(0); } @@ -2281,21 +2327,13 @@ NdbDictInterface::createOrAlterTable(Ndb & ndb, sizeof(tmpTab->TableName), internalName.c_str()); - bool haveAutoIncrement = false; - Uint64 autoIncrementValue = 0; Uint32 distKeys= 0; - for(i = 0; i<sz; i++){ + for(i = 0; i<sz; i++) { const NdbColumnImpl * col = impl.m_columns[i]; - if(col == 0) - continue; - if (col->m_autoIncrement) { - if (haveAutoIncrement) { - m_error.code= 4335; - NdbMem_Free((void*)tmpTab); - DBUG_RETURN(-1); - } - haveAutoIncrement = true; - autoIncrementValue = col->m_autoIncrementInitialValue; + if (col == NULL) { + m_error.code = 4272; + NdbMem_Free((void*)tmpTab); + DBUG_RETURN(-1); } if (col->m_distributionKey) { @@ -2559,17 +2597,6 @@ loop: errCodes); } - if (!ret && !alter && haveAutoIncrement) { - if (!ndb.setAutoIncrementValue(impl.m_externalName.c_str(), - autoIncrementValue)) { - if (ndb.theError.code == 0) { - m_error.code = 4336; - ndb.theError = m_error; - } else - m_error= ndb.theError; - ret = -1; // errorcode set in initialize_autoincrement - } - } DBUG_RETURN(ret); } @@ -2577,12 +2604,12 @@ void NdbDictInterface::execCREATE_TABLE_CONF(NdbApiSignal * signal, LinearSectionPtr ptr[3]) { -#if 0 const CreateTableConf* const conf= CAST_CONSTPTR(CreateTableConf, signal->getDataPtr()); - Uint32 tableId= conf->tableId; - Uint32 tableVersion= conf->tableVersion; -#endif + m_buffer.grow(4 * 2); // 2 words + Uint32* data = (Uint32*)m_buffer.get_data(); + data[0] = conf->tableId; + data[1] = conf->tableVersion; m_waiter.signal(NO_WAIT); } @@ -3453,7 +3480,7 @@ NdbDictInterface::stopSubscribeEvent(class Ndb & ndb, } NdbEventImpl * -NdbDictionaryImpl::getEvent(const char * eventName) +NdbDictionaryImpl::getEvent(const char * eventName, NdbTableImpl* tab) { DBUG_ENTER("NdbDictionaryImpl::getEvent"); DBUG_PRINT("enter",("eventName= %s", eventName)); @@ -3472,19 +3499,10 @@ NdbDictionaryImpl::getEvent(const char * eventName) DBUG_RETURN(NULL); } - // We only have the table name with internal name - DBUG_PRINT("info",("table %s", ev->getTableName())); - Ndb_local_table_info *info; - info= get_local_table_info(ev->getTableName(), true); - if (info == 0) - { - DBUG_PRINT("error",("unable to find table %s", ev->getTableName())); - delete ev; - DBUG_RETURN(NULL); - } - if (info->m_table_impl->m_status != NdbDictionary::Object::Retrieved) - { - removeCachedObject(*info->m_table_impl); + if (tab == NULL) { + // We only have the table name with internal name + DBUG_PRINT("info",("table %s", ev->getTableName())); + Ndb_local_table_info *info; info= get_local_table_info(ev->getTableName(), true); if (info == 0) { @@ -3492,8 +3510,21 @@ NdbDictionaryImpl::getEvent(const char * eventName) delete ev; DBUG_RETURN(NULL); } + if (info->m_table_impl->m_status != NdbDictionary::Object::Retrieved) + { + removeCachedObject(*info->m_table_impl); + info= get_local_table_info(ev->getTableName(), true); + if (info == 0) + { + DBUG_PRINT("error",("unable to find table %s", ev->getTableName())); + delete ev; + DBUG_RETURN(NULL); + } + } + tab = info->m_table_impl; } - ev->setTable(info->m_table_impl); + + ev->setTable(tab); ev->setTable(m_ndb.externalizeTableName(ev->getTableName())); // get the columns from the attrListBitmask NdbTableImpl &table = *ev->m_tableImpl; @@ -3541,6 +3572,26 @@ NdbDictionaryImpl::getEvent(const char * eventName) DBUG_RETURN(ev); } +// ev is main event and has been retrieved previously +NdbEventImpl * +NdbDictionaryImpl::getBlobEvent(const NdbEventImpl& ev, uint col_no) +{ + DBUG_ENTER("NdbDictionaryImpl::getBlobEvent"); + DBUG_PRINT("enter", ("ev=%s col=%u", ev.m_name.c_str(), col_no)); + + NdbTableImpl* tab = ev.m_tableImpl; + assert(tab != NULL && col_no < tab->m_columns.size()); + NdbColumnImpl* col = tab->m_columns[col_no]; + assert(col != NULL && col->getBlobType() && col->getPartSize() != 0); + NdbTableImpl* blob_tab = col->m_blobTable; + assert(blob_tab != NULL); + char bename[MAX_TAB_NAME_SIZE]; + NdbBlob::getBlobEventName(bename, &ev, col); + + NdbEventImpl* blob_ev = getEvent(bename, blob_tab); + DBUG_RETURN(blob_ev); +} + void NdbDictInterface::execCREATE_EVNT_CONF(NdbApiSignal * signal, LinearSectionPtr ptr[3]) diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 064de6e42d4..5c26d386c99 100644 --- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -479,6 +479,7 @@ private: class TransporterFacade * m_transporter; friend class Ndb; + friend class NdbDictionaryImpl; static void execSignal(void* dictImpl, class NdbApiSignal* signal, struct LinearSectionPtr ptr[3]); @@ -540,7 +541,7 @@ public: bool setTransporter(class TransporterFacade * tf); int createTable(NdbTableImpl &t); - int createBlobTables(NdbTableImpl& org, NdbTableImpl & created); + int createBlobTables(NdbTableImpl& t); int addBlobTables(NdbTableImpl &); int alterTable(NdbTableImpl &t); int dropTable(const char * name); @@ -576,7 +577,8 @@ public: const BaseString& internalTableName, bool do_add_blob_tables); NdbIndexImpl * getIndex(const char * indexName, const char * tableName); - NdbEventImpl * getEvent(const char * eventName); + NdbEventImpl * getEvent(const char * eventName, NdbTableImpl* = NULL); + NdbEventImpl * getBlobEvent(const NdbEventImpl& ev, uint col_no); NdbEventImpl * getEventImpl(const char * internalName); int createDatafile(const NdbDatafileImpl &, bool force = false); diff --git a/storage/ndb/src/ndbapi/NdbEventOperation.cpp b/storage/ndb/src/ndbapi/NdbEventOperation.cpp index 71bb8889614..4e96ee63565 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperation.cpp +++ b/storage/ndb/src/ndbapi/NdbEventOperation.cpp @@ -144,6 +144,10 @@ NdbEventOperation::print() /* * Internal for the mysql server */ +const NdbDictionary::Table *NdbEventOperation::getTable() const +{ + return m_impl.m_eventImpl->m_tableImpl->m_facade; +} const NdbDictionary::Event *NdbEventOperation::getEvent() const { return m_impl.m_eventImpl->m_facade; diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp index 411c151410d..01421be085b 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp @@ -88,18 +88,55 @@ print_std(const SubTableData * sdata, LinearSectionPtr ptr[3]) // todo handle several ndb objects // todo free allocated data when closing NdbEventBuffer -NdbEventOperationImpl::NdbEventOperationImpl(NdbEventOperation &N, +NdbEventOperationImpl::NdbEventOperationImpl(NdbEventOperation &f, Ndb *theNdb, - const char* eventName) - : NdbEventOperation(*this), m_facade(&N), m_magic_number(0), - m_ndb(theNdb), m_state(EO_ERROR), mi_type(0), m_oid(~(Uint32)0), - m_change_mask(0), -#ifdef VM_TRACE - m_data_done_count(0), m_data_count(0), -#endif - m_next(0), m_prev(0) + const char* eventName) : + NdbEventOperation(*this), + m_facade(&f), + m_ndb(theNdb), + m_state(EO_ERROR) { DBUG_ENTER("NdbEventOperationImpl::NdbEventOperationImpl"); + + assert(m_ndb != NULL); + NdbDictionary::Dictionary *myDict = m_ndb->getDictionary(); + assert(myDict != NULL); + + const NdbDictionary::Event *myEvnt = myDict->getEvent(eventName); + if (!myEvnt) { m_error.code= myDict->getNdbError().code; DBUG_VOID_RETURN; } + + init(myEvnt->m_impl); + DBUG_VOID_RETURN; +} + +NdbEventOperationImpl::NdbEventOperationImpl(Ndb *theNdb, + NdbEventImpl& evnt) : + NdbEventOperation(*this), + m_facade(this), + m_ndb(theNdb), + m_state(EO_ERROR) +{ + DBUG_ENTER("NdbEventOperationImpl::NdbEventOperationImpl [evnt]"); + init(evnt); + DBUG_VOID_RETURN; +} + +void +NdbEventOperationImpl::init(NdbEventImpl& evnt) +{ + DBUG_ENTER("NdbEventOperationImpl::init"); + + m_magic_number = 0; + mi_type = 0; + m_oid = ~(Uint32)0; + m_change_mask = 0; +#ifdef VM_TRACE + m_data_done_count = 0; + m_data_count = 0; +#endif + m_next = 0; + m_prev = 0; + m_eventId = 0; theFirstPkAttrs[0] = NULL; theCurrentPkAttrs[0] = NULL; @@ -123,15 +160,7 @@ NdbEventOperationImpl::NdbEventOperationImpl(NdbEventOperation &N, // we should lookup id in Dictionary, TODO // also make sure we only have one listener on each event - if (!m_ndb) abort(); - - NdbDictionary::Dictionary *myDict = m_ndb->getDictionary(); - if (!myDict) { m_error.code= m_ndb->getNdbError().code; DBUG_VOID_RETURN; } - - const NdbDictionary::Event *myEvnt = myDict->getEvent(eventName); - if (!myEvnt) { m_error.code= myDict->getNdbError().code; DBUG_VOID_RETURN; } - - m_eventImpl = &myEvnt->m_impl; + m_eventImpl = &evnt; m_eventId = m_eventImpl->m_eventId; @@ -347,20 +376,27 @@ NdbEventOperationImpl::getBlobHandle(const NdbColumnImpl *tAttrInfo, int n) // create blob event op if not found if (tBlobOp == NULL) { - // to hide blob op it is linked under main op, not under m_ndb - NdbEventOperation* tmp = - m_ndb->theEventBuffer->createEventOperation(bename, m_error); - if (tmp == NULL) { - m_error.code = m_ndb->theEventBuffer->m_error.code; + // get blob event + NdbDictionaryImpl& dict = + NdbDictionaryImpl::getImpl(*m_ndb->getDictionary()); + NdbEventImpl* blobEvnt = + dict.getBlobEvent(*this->m_eventImpl, tAttrInfo->m_column_no); + if (blobEvnt == NULL) { + m_error.code = dict.m_error.code; DBUG_RETURN(NULL); } - tBlobOp = &tmp->m_impl; + + // create blob event operation + tBlobOp = + m_ndb->theEventBuffer->createEventOperation(*blobEvnt, m_error); + if (tBlobOp == NULL) + DBUG_RETURN(NULL); // pointer to main table op tBlobOp->theMainOp = this; tBlobOp->m_mergeEvents = m_mergeEvents; - // add to list end + // to hide blob op it is linked under main op, not under m_ndb if (tLastBlopOp == NULL) theBlobOpList = tBlobOp; else @@ -645,6 +681,14 @@ NdbEventOperationImpl::receive_event() m_buffer.length() / 4, true); m_buffer.clear(); + if (at) + at->buildColumnHash(); + else + { + DBUG_PRINT_EVENT("info", ("Failed to parse DictTabInfo error %u", + error.code)); + DBUG_RETURN_EVENT(1); + } if ( m_eventImpl->m_tableImpl) delete m_eventImpl->m_tableImpl; m_eventImpl->m_tableImpl = at; @@ -2125,6 +2169,25 @@ NdbEventBuffer::createEventOperation(const char* eventName, DBUG_RETURN(tOp); } +NdbEventOperationImpl* +NdbEventBuffer::createEventOperation(NdbEventImpl& evnt, + NdbError &theError) +{ + DBUG_ENTER("NdbEventBuffer::createEventOperation [evnt]"); + NdbEventOperationImpl* tOp= new NdbEventOperationImpl(m_ndb, evnt); + if (tOp == 0) + { + theError.code= 4000; + DBUG_RETURN(NULL); + } + if (tOp->getState() != NdbEventOperation::EO_CREATED) { + theError.code= tOp->getNdbError().code; + delete tOp; + DBUG_RETURN(NULL); + } + DBUG_RETURN(tOp); +} + void NdbEventBuffer::dropEventOperation(NdbEventOperation* tOp) { diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp index 61d91d71332..3e7d313fe02 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp @@ -202,9 +202,12 @@ struct Gci_container class NdbEventOperationImpl : public NdbEventOperation { public: - NdbEventOperationImpl(NdbEventOperation &N, + NdbEventOperationImpl(NdbEventOperation &f, Ndb *theNdb, const char* eventName); + NdbEventOperationImpl(Ndb *theNdb, + NdbEventImpl& evnt); + void init(NdbEventImpl& evnt); NdbEventOperationImpl(NdbEventOperationImpl&); //unimplemented NdbEventOperationImpl& operator=(const NdbEventOperationImpl&); //unimplemented ~NdbEventOperationImpl(); @@ -293,6 +296,8 @@ public: Vector<Gci_container> m_active_gci; NdbEventOperation *createEventOperation(const char* eventName, NdbError &); + NdbEventOperationImpl *createEventOperation(NdbEventImpl& evnt, + NdbError &); void dropEventOperation(NdbEventOperation *); static NdbEventOperationImpl* getEventOperationImpl(NdbEventOperation* tOp); diff --git a/storage/ndb/src/ndbapi/ndberror.c b/storage/ndb/src/ndbapi/ndberror.c index 6ea45fd0d60..979313d6f83 100644 --- a/storage/ndb/src/ndbapi/ndberror.c +++ b/storage/ndb/src/ndbapi/ndberror.c @@ -596,7 +596,9 @@ ErrorBundle ErrorCodes[] = { { 4269, DMEC, IE, "No connection to ndb management server" }, { 4270, DMEC, IE, "Unknown blob error" }, { 4335, DMEC, AE, "Only one autoincrement column allowed per table. Having a table without primary key uses an autoincremented hidden key, i.e. a table without a primary key can not have an autoincremented column" }, - { 4271, DMEC, AE, "Invalid index object, not retrieved via getIndex()" } + { 4336, DMEC, AE, "Auto-increment value set below current value" }, + { 4271, DMEC, AE, "Invalid index object, not retrieved via getIndex()" }, + { 4272, DMEC, AE, "Table definition has undefined column" } }; static diff --git a/storage/ndb/tools/restore/consumer_restore.cpp b/storage/ndb/tools/restore/consumer_restore.cpp index e4d8f98363a..3b39a1373a0 100644 --- a/storage/ndb/tools/restore/consumer_restore.cpp +++ b/storage/ndb/tools/restore/consumer_restore.cpp @@ -748,10 +748,17 @@ BackupRestore::table(const TableS & table){ my_event.addTableEvent(NdbDictionary::Event::TE_ALL); // add all columns to the event + bool has_blobs = false; for(int a= 0; a < tab->getNoOfColumns(); a++) { my_event.addEventColumn(a); + NdbDictionary::Column::Type t = tab->getColumn(a)->getType(); + if (t == NdbDictionary::Column::Blob || + t == NdbDictionary::Column::Text) + has_blobs = true; } + if (has_blobs) + my_event.mergeEvents(true); while ( dict->createEvent(my_event) ) // Add event to database { diff --git a/strings/decimal.c b/strings/decimal.c index 919d4c7d3bc..c3ab9f51a99 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -1353,6 +1353,8 @@ int bin2decimal(char *from, decimal_t *to, int precision, int scale) } from+=i; *buf=x ^ mask; + if (((uint32)*buf) >= powers10[intg0x+1]) + goto err; if (buf > to->buf || *buf != 0) buf++; else @@ -1362,6 +1364,8 @@ int bin2decimal(char *from, decimal_t *to, int precision, int scale) { DBUG_ASSERT(sizeof(dec1) == 4); *buf=mi_sint4korr(from) ^ mask; + if (((uint32)*buf) > DIG_MAX) + goto err; if (buf > to->buf || *buf != 0) buf++; else @@ -1372,6 +1376,8 @@ int bin2decimal(char *from, decimal_t *to, int precision, int scale) { DBUG_ASSERT(sizeof(dec1) == 4); *buf=mi_sint4korr(from) ^ mask; + if (((uint32)*buf) > DIG_MAX) + goto err; buf++; } if (frac0x) @@ -1387,10 +1393,17 @@ int bin2decimal(char *from, decimal_t *to, int precision, int scale) default: DBUG_ASSERT(0); } *buf=(x ^ mask) * powers10[DIG_PER_DEC1 - frac0x]; + if (((uint32)*buf) > DIG_MAX) + goto err; buf++; } my_afree(d_copy); return error; + +err: + my_afree(d_copy); + decimal_make_zero(((decimal_t*) to)); + return(E_DEC_BAD_NUM); } /* diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index 2697236949b..7bea933654a 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -709,7 +709,7 @@ fi # itself - note that they must be ordered by date (important when # merging BK trees) %changelog -* Mon Feb 20 03:04:32 CET 2006 +* Mon Feb 20 2006 Kent Boortz <kent@mysql.com> - Reintroduced a max build - Limited testing of 'debug' and 'max' servers diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 7db643574c5..5730efced35 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -14724,9 +14724,9 @@ static void test_bug12744() mysql_close(mysql); - if (rc= mysql_stmt_execute(prep_stmt)) + if ((rc= mysql_stmt_execute(prep_stmt))) { - if (rc= mysql_stmt_reset(prep_stmt)) + if ((rc= mysql_stmt_reset(prep_stmt))) printf("OK!\n"); else { @@ -14840,6 +14840,40 @@ static void test_bug15613() mysql_stmt_close(stmt); } /* + Bug#14169: type of group_concat() result changed to blob if tmp_table was used +*/ +static void test_bug14169() +{ + MYSQL_STMT *stmt; + const char *stmt_text; + MYSQL_RES *res; + MYSQL_FIELD *field; + int rc; + + myheader("test_bug14169"); + + rc= mysql_query(mysql, "drop table if exists t1"); + myquery(rc); + rc= mysql_query(mysql, "set session group_concat_max_len=1024"); + myquery(rc); + rc= mysql_query(mysql, "create table t1 (f1 int unsigned, f2 varchar(255))"); + myquery(rc); + rc= mysql_query(mysql, "insert into t1 values (1,repeat('a',255))," + "(2,repeat('b',255))"); + myquery(rc); + stmt= mysql_stmt_init(mysql); + stmt_text= "select f2,group_concat(f1) from t1 group by f2"; + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + myquery(rc); + res= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_fields(res); + if (!opt_silent) + printf("GROUP_CONCAT() result type %i", field[1].type); + DIE_UNLESS(field[1].type == MYSQL_TYPE_BLOB); + + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); +}/* Read and parse arguments and MySQL options from my.cnf */ @@ -15104,6 +15138,7 @@ static struct my_tests_st my_tests[]= { { "test_bug16143", test_bug16143 }, { "test_bug16144", test_bug16144 }, { "test_bug15613", test_bug15613 }, + { "test_bug14169", test_bug14169 }, { 0, 0 } }; diff --git a/win/cmakefiles/base b/win/cmakefiles/base index 4430ac0ec46..caa059b98f5 100644 --- a/win/cmakefiles/base +++ b/win/cmakefiles/base @@ -32,4 +32,5 @@ ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 7" OR CMAKE_GENERATOR MATCHES "Visu ADD_DEFINITIONS("-D_WINDOWS -D__WIN__") SUBDIRS(vio dbug strings regex mysys extra zlib storage/innobase storage/heap storage/myisam storage/myisammrg - extra/yassl extra/yassl/taocrypt client sql server-tools/instance-manager) + extra/yassl extra/yassl/taocrypt client sql server-tools/instance-manager + libmysql tests) diff --git a/win/cmakefiles/client b/win/cmakefiles/client index 7c0c6f2400b..7914f8aac1b 100644 --- a/win/cmakefiles/client +++ b/win/cmakefiles/client @@ -1,11 +1,16 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -ADD_DEFINITIONS(-DUSE_TLS -DMYSQL_CLIENT) +# The old Windows build method used renamed (.cc -> .cpp) source files, fails +# in #include in mysqlbinlog.cc. So disable that using the USING_CMAKE define. +ADD_DEFINITIONS(-DUSING_CMAKE) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib ${CMAKE_SOURCE_DIR}/extra/yassl/include - ${CMAKE_SOURCE_DIR}/libmysql) + ${CMAKE_SOURCE_DIR}/libmysql + ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/strings) ADD_LIBRARY(mysqlclient ../mysys/array.c ../strings/bchange.c ../strings/bmove.c ../strings/bmove_upp.c ../mysys/charset-def.c ../mysys/charset.c @@ -47,3 +52,29 @@ ADD_DEPENDENCIES(mysqlclient GenError) ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc sql_string.cc) LINK_DIRECTORIES(${MYSQL_BINARY_DIR}/mysys ${MYSQL_BINARY_DIR}/zlib) TARGET_LINK_LIBRARIES(mysql mysqlclient mysys yassl zlib dbug yassl taocrypt wsock32) + +ADD_EXECUTABLE(mysqltest mysqltest.c) +TARGET_LINK_LIBRARIES(mysqltest mysqlclient mysys yassl zlib dbug regex wsock32) + +ADD_EXECUTABLE(mysqlcheck mysqlcheck.c) +TARGET_LINK_LIBRARIES(mysqlcheck mysqlclient dbug yassl zlib wsock32) + +ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c) +TARGET_LINK_LIBRARIES(mysqldump mysqlclient mysys dbug yassl zlib wsock32) + +ADD_EXECUTABLE(mysqlimport mysqlimport.c) +TARGET_LINK_LIBRARIES(mysqlimport mysqlclient mysys dbug yassl zlib wsock32) + +ADD_EXECUTABLE(mysqlshow mysqlshow.c) +TARGET_LINK_LIBRARIES(mysqlshow mysqlclient mysys dbug yassl zlib wsock32) + +ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc ../mysys/mf_tempdir.c ../mysys/my_new.cc + ../mysys/my_bit.c ../mysys/my_bitmap.c ../mysys/my_vle.c + ../mysys/base64.c) +TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient dbug yassl zlib wsock32) + +ADD_EXECUTABLE(mysqladmin mysqladmin.cc) +TARGET_LINK_LIBRARIES(mysqladmin mysqlclient mysys dbug yassl zlib wsock32) + +ADD_EXECUTABLE(mysqlslap mysqlslap.c) +TARGET_LINK_LIBRARIES(mysqlslap mysqlclient mysys zlib wsock32) diff --git a/win/cmakefiles/deploy.bat b/win/cmakefiles/deploy.bat index cb55b8cdb12..44ecb2d55fb 100644 --- a/win/cmakefiles/deploy.bat +++ b/win/cmakefiles/deploy.bat @@ -17,3 +17,5 @@ copy innobase ..\..\storage\innobase\cmakelists.txt copy myisam ..\..\storage\myisam\cmakelists.txt copy myisammrg ..\..\storage\myisammrg\cmakelists.txt copy im ..\..\server-tools\instance-manager\cmakelists.txt +copy libmysql ..\..\libmysql\cmakelists.txt +copy tests ..\..\tests\cmakelists.txt diff --git a/win/cmakefiles/extra b/win/cmakefiles/extra index 40327eac0ad..d31779fca63 100644 --- a/win/cmakefiles/extra +++ b/win/cmakefiles/extra @@ -19,3 +19,11 @@ ADD_CUSTOM_TARGET(GenError +ADD_EXECUTABLE(my_print_defaults my_print_defaults.c) +TARGET_LINK_LIBRARIES(my_print_defaults strings mysys dbug taocrypt odbc32 odbccp32 wsock32) + +ADD_EXECUTABLE(perror perror.c) +TARGET_LINK_LIBRARIES(perror strings mysys dbug wsock32) + +ADD_EXECUTABLE(replace replace.c) +TARGET_LINK_LIBRARIES(replace strings mysys dbug wsock32) diff --git a/win/cmakefiles/libmysql b/win/cmakefiles/libmysql new file mode 100644 index 00000000000..a1953244c0a --- /dev/null +++ b/win/cmakefiles/libmysql @@ -0,0 +1,53 @@ +SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/extra/yassl/include + ${CMAKE_SOURCE_DIR}/libmysql + ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/strings) + +ADD_LIBRARY(libmysql MODULE dll.c libmysql.def + ../mysys/array.c ../strings/bchange.c ../strings/bmove.c + ../strings/bmove_upp.c ../mysys/charset-def.c ../mysys/charset.c + ../sql-common/client.c ../strings/ctype-big5.c ../strings/ctype-bin.c + ../strings/ctype-cp932.c ../strings/ctype-czech.c ../strings/ctype-euc_kr.c + ../strings/ctype-eucjpms.c ../strings/ctype-extra.c ../strings/ctype-gb2312.c + ../strings/ctype-gbk.c ../strings/ctype-latin1.c ../strings/ctype-mb.c + ../strings/ctype-simple.c ../strings/ctype-sjis.c ../strings/ctype-tis620.c + ../strings/ctype-uca.c ../strings/ctype-ucs2.c ../strings/ctype-ujis.c + ../strings/ctype-utf8.c ../strings/ctype-win1250ch.c ../strings/ctype.c + ../mysys/default.c ../libmysql/errmsg.c ../mysys/errors.c + ../libmysql/get_password.c ../strings/int2str.c ../strings/is_prefix.c + ../libmysql/libmysql.c ../mysys/list.c ../strings/llstr.c + ../strings/longlong2str.c ../libmysql/manager.c ../mysys/mf_cache.c + ../mysys/mf_dirname.c ../mysys/mf_fn_ext.c ../mysys/mf_format.c + ../mysys/mf_iocache.c ../mysys/mf_iocache2.c ../mysys/mf_loadpath.c + ../mysys/mf_pack.c ../mysys/mf_path.c ../mysys/mf_tempfile.c ../mysys/mf_unixpath.c + ../mysys/mf_wcomp.c ../mysys/mulalloc.c ../mysys/my_access.c ../mysys/my_alloc.c + ../mysys/my_chsize.c ../mysys/my_compress.c ../mysys/my_create.c + ../mysys/my_delete.c ../mysys/my_div.c ../mysys/my_error.c ../mysys/my_file.c + ../mysys/my_fopen.c ../mysys/my_fstream.c ../mysys/my_gethostbyname.c + ../mysys/my_getopt.c ../mysys/my_getwd.c ../mysys/my_init.c ../mysys/my_lib.c + ../mysys/my_malloc.c ../mysys/my_messnc.c ../mysys/my_net.c ../mysys/my_once.c + ../mysys/my_open.c ../mysys/my_pread.c ../mysys/my_pthread.c ../mysys/my_read.c + ../mysys/my_realloc.c ../mysys/my_rename.c ../mysys/my_seek.c + ../mysys/my_static.c ../strings/my_strtoll10.c ../mysys/my_symlink.c + ../mysys/my_symlink2.c ../mysys/my_thr_init.c ../sql-common/my_time.c + ../strings/my_vsnprintf.c ../mysys/my_wincond.c ../mysys/my_winthread.c + ../mysys/my_write.c ../sql/net_serv.cc ../sql-common/pack.c ../sql/password.c + ../mysys/safemalloc.c ../mysys/sha1.c ../strings/str2int.c + ../strings/str_alloc.c ../strings/strcend.c ../strings/strcont.c ../strings/strend.c + ../strings/strfill.c ../mysys/string.c ../strings/strinstr.c ../strings/strmake.c + ../strings/strmov.c ../strings/strnlen.c ../strings/strnmov.c ../strings/strtod.c + ../strings/strtoll.c ../strings/strtoull.c ../strings/strxmov.c ../strings/strxnmov.c + ../mysys/thr_mutex.c ../mysys/typelib.c ../vio/vio.c ../vio/viosocket.c + ../vio/viossl.c ../vio/viosslfactories.c ../strings/xml.c) +ADD_DEPENDENCIES(libmysql GenError zlib) +TARGET_LINK_LIBRARIES(libmysql mysys strings wsock32) + +# ToDo: We should move the mytest.c program out in libmysql/ +ADD_EXECUTABLE(myTest ../VC++Files/libmysqltest/mytest.c) +TARGET_LINK_LIBRARIES(myTest libmysql) diff --git a/win/cmakefiles/myisam b/win/cmakefiles/myisam index 80fe4e81138..3ba7aba4555 100644 --- a/win/cmakefiles/myisam +++ b/win/cmakefiles/myisam @@ -12,3 +12,15 @@ ADD_LIBRARY(myisam ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c f mi_rsame.c mi_rsamepos.c mi_scan.c mi_search.c mi_static.c mi_statrec.c mi_unique.c mi_update.c mi_write.c rt_index.c rt_key.c rt_mbr.c rt_split.c sort.c sp_key.c ft_eval.h myisamdef.h rt_index.h mi_rkey.c) + +ADD_EXECUTABLE(myisam_ftdump myisam_ftdump.c) +TARGET_LINK_LIBRARIES(myisam_ftdump myisam mysys dbug strings zlib wsock32) + +ADD_EXECUTABLE(myisamchk myisamchk.c) +TARGET_LINK_LIBRARIES(myisamchk myisam mysys dbug strings zlib wsock32) + +ADD_EXECUTABLE(myisamlog myisamlog.c) +TARGET_LINK_LIBRARIES(myisamlog myisam mysys dbug strings zlib wsock32) + +ADD_EXECUTABLE(myisampack myisampack.c) +TARGET_LINK_LIBRARIES(myisampack myisam mysys dbug strings zlib wsock32) diff --git a/win/cmakefiles/mysys b/win/cmakefiles/mysys index 3596825cded..ceecc1368ec 100644 --- a/win/cmakefiles/mysys +++ b/win/cmakefiles/mysys @@ -16,6 +16,6 @@ ADD_LIBRARY(mysys array.c charset-def.c charset.c checksum.c default.c default_m my_mkdir.c my_mmap.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_sleep.c my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c my_wincond.c - my_windac.c my_winsem.c my_winthread.c my_write.c ptr_cmp.c queues.c raid.cc + my_windac.c my_winsem.c my_winthread.c my_write.c ptr_cmp.c queues.c rijndael.c safemalloc.c sha1.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c tree.c typelib.c my_vle.c base64.c) diff --git a/win/cmakefiles/sql b/win/cmakefiles/sql index ee53436a1a6..72a71cbf14f 100644 --- a/win/cmakefiles/sql +++ b/win/cmakefiles/sql @@ -40,7 +40,7 @@ ADD_EXECUTABLE(mysqld ../sql-common/client.c derror.cc des_key_file.cc discover. sql_state.c sql_string.cc sql_table.cc sql_test.cc sql_trigger.cc sql_udf.cc sql_union.cc sql_update.cc sql_view.cc sql_yacc.h sql_yacc.cc strfunc.cc table.cc thr_malloc.cc time.cc tztime.cc uniques.cc unireg.cc item_xmlfunc.cc rpl_tblmap.cc sql_binlog.cc event_executor.cc - event_timed.cc sql_tablespace.cc event.cc ../sql-common/my_user.c + event_timed.cc sql_tablespace.cc event.cc ../sql-common/my_user.c partition_info.cc ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h ${PROJECT_SOURCE_DIR}/include/mysqld_error.h @@ -76,14 +76,14 @@ ADD_CUSTOM_COMMAND( #ADD_CUSTOM_COMMAND( # SOURCE ${PROJECT_SOURCE_DIR}/include/mysql_version.h.in # OUTPUT ${PROJECT_SOURCE_DIR}/include/mysql_version.h -# COMMAND ${PROJECT_SOURCE_DIR}/win/config-version.js +# COMMAND cscript.exe ${PROJECT_SOURCE_DIR}/win/config-version.js # DEPENDS ${PROJECT_SOURCE_DIR}/include/mysql_version.h.in) # Handlerton file ADD_CUSTOM_COMMAND( SOURCE ${PROJECT_SOURCE_DIR}/sql/handlerton.cc.in OUTPUT ${PROJECT_SOURCE_DIR}/sql/handlerton.cc - COMMAND ${PROJECT_SOURCE_DIR}/win/config-handlerton.js ARGS ${PROJECT_SOURCE_DIR}/win/configure.data + COMMAND cscript.exe ${PROJECT_SOURCE_DIR}/win/config-handlerton.js ARGS ${PROJECT_SOURCE_DIR}/win/configure.data DEPENDS ${PROJECT_SOURCE_DIR}/sql/handlerton.cc.in) # Error file diff --git a/win/cmakefiles/tests b/win/cmakefiles/tests new file mode 100644 index 00000000000..cde41dca85c --- /dev/null +++ b/win/cmakefiles/tests @@ -0,0 +1,9 @@ +SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") + +ADD_DEFINITIONS("-DMYSQL_CLIENT") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +ADD_EXECUTABLE(mysql_client_test mysql_client_test.c) +TARGET_LINK_LIBRARIES(mysql_client_test mysqlclient zlib wsock32) |