Commit 0061da91 authored by kent@mysql.com's avatar kent@mysql.com

mysql-test-run.sh:

  Added timing output for each test case.
  Added --embedded-server option.
mysqltest.c:
  Added 'start_timer', 'end_timer' commands
Makefile.am:
  Include mysys/my_getsystime.c to get time function in mysqltest
Many files:
  new file
parent 010f4242
......@@ -34,7 +34,7 @@ mysqlcheck_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
mysqlshow_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
mysqldump_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
mysqlimport_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
mysqltest_SOURCES= mysqltest.c
mysqltest_SOURCES= mysqltest.c ../mysys/my_getsystime.c
mysqltest_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
mysqlbinlog_SOURCES = mysqlbinlog.cc ../mysys/mf_tempdir.c
mysqlbinlog_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) $(DEPLIB)
......
......@@ -58,6 +58,13 @@
#include <stdarg.h>
#include <sys/stat.h>
#include <violite.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif
#define MAX_QUERY 131072
#define MAX_VAR_NAME 256
......@@ -75,7 +82,7 @@
#ifndef MYSQL_MANAGER_PORT
#define MYSQL_MANAGER_PORT 23546
#endif
#define MAX_SERVER_ARGS 20
#define MAX_SERVER_ARGS 64
/*
Sometimes in a test the client starts before
......@@ -132,6 +139,13 @@ static char *embedded_server_args[MAX_SERVER_ARGS];
static my_bool display_result_vertically= FALSE, display_metadata= FALSE;
/* See the timer_output() definition for details */
static char *timer_file = NULL;
static ulonglong timer_start;
static int got_end_timer= FALSE;
static void timer_output(void);
static ulonglong timer_now(void);
static const char *embedded_server_groups[] = {
"server",
"embedded",
......@@ -230,6 +244,7 @@ Q_ENABLE_METADATA, Q_DISABLE_METADATA,
Q_EXEC, Q_DELIMITER,
Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS,
Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL,
Q_START_TIMER, Q_END_TIMER,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
......@@ -308,6 +323,8 @@ const char *command_names[]=
"horizontal_results",
"query_vertical",
"query_horizontal",
"start_timer",
"end_timer",
0
};
......@@ -1986,6 +2003,8 @@ static struct my_option my_long_options[] =
#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},
{"timer-file", 'm', "File where the timing in micro seconds is stored.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"tmpdir", 't', "Temporary directory where sockets are put.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0, GET_STR,
......@@ -2047,6 +2066,19 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
die("Could not open %s: errno = %d", argument, errno);
break;
}
case 'm':
{
static char buff[FN_REFLEN];
if (!test_if_hard_path(argument))
{
strxmov(buff, opt_basedir, argument, NullS);
argument= buff;
}
fn_format(buff, argument, "", "", 4);
timer_file= buff;
unlink(timer_file); /* Ignore error, may not exist */
break;
}
case 'p':
if (argument)
{
......@@ -2128,7 +2160,7 @@ char* safe_str_append(char* buf, const char* str, int size)
void str_to_file(const char* fname, char* str, int size)
{
int fd;
char buff[FN_REFLEN];
char buff[MAXPATHLEN];
if (!test_if_hard_path(fname))
{
strxmov(buff, opt_basedir, fname, NullS);
......@@ -2599,6 +2631,9 @@ int main(int argc, char **argv)
DBUG_ENTER("main");
DBUG_PROCESS(argv[0]);
/* Use all time until exit if no explicit 'start_timer' */
timer_start= timer_now();
save_file[0]=0;
TMPDIR[0]=0;
memset(cons, 0, sizeof(cons));
......@@ -2813,6 +2848,15 @@ int main(int argc, char **argv)
case Q_EXEC:
(void) do_exec(q);
break;
case Q_START_TIMER:
/* Overwrite possible earlier start of timer */
timer_start= timer_now();
break;
case Q_END_TIMER:
/* End timer before ending mysqltest */
timer_output();
got_end_timer= TRUE;
break;
default: processed = 0; break;
}
}
......@@ -2847,6 +2891,8 @@ int main(int argc, char **argv)
printf("ok\n");
}
if (!got_end_timer)
timer_output(); /* No end_timer cmd, end it */
free_used_memory();
exit(error ? 1 : 0);
return error ? 1 : 0; /* Keep compiler happy */
......@@ -2900,6 +2946,45 @@ static int read_server_arguments(const char *name)
return 0;
}
/****************************************************************************\
*
* A primitive timer that give results in milliseconds if the
* --timer-file=<filename> is given. The timer result is written
* to that file when the result is available. To not confuse
* mysql-test-run with an old obsolete result, we remove the file
* before executing any commands. The time we measure is
*
* - If no explicit 'start_timer' or 'end_timer' is given in the
* test case, the timer measure how long we execute in mysqltest.
*
* - If only 'start_timer' is given we measure how long we execute
* from that point until we terminate mysqltest.
*
* - If only 'end_timer' is given we measure how long we execute
* from that we enter mysqltest to the 'end_timer' is command is
* executed.
*
* - If both 'start_timer' and 'end_timer' are given we measure
* the time between executing the two commands.
*
\****************************************************************************/
static void timer_output(void)
{
if (timer_file)
{
char buf[1024];
ulonglong timer= timer_now() - timer_start;
sprintf(buf,"%llu",timer);
str_to_file(timer_file,buf,strlen(buf));
}
}
static ulonglong timer_now(void)
{
return my_getsystime() / 10000;
}
/****************************************************************************
* Handle replacement of strings
****************************************************************************/
......
......@@ -232,9 +232,13 @@ DBUSER=""
START_WAIT_TIMEOUT=10
STOP_WAIT_TIMEOUT=10
MYSQL_TEST_SSL_OPTS=""
USE_EMBEDDED_SERVER=""
RESULT_EXT=""
while test $# -gt 0; do
case "$1" in
--embedded-server) USE_EMBEDDED_SERVER=1 ; USE_MANAGER=0 ; NO_SLAVE=1 ; \
USE_RUNNING_SERVER="" RESULT_EXT=".es" ;;
--user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
--force) FORCE=1 ;;
--verbose-manager) MANAGER_QUIET_OPT="" ;;
......@@ -458,11 +462,19 @@ fi
if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi
E=`$EXPR $COLUMNS - 8`
DASH72=`$ECHO '------------------------------------------'|$CUT -c 1-$E`
DASH72=`$ECHO '-------------------------------------------------------'|$CUT -c 1-$E`
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
if [ -f "$BASEDIR/libmysqld/examples/mysqltest" ] ; then
MYSQL_TEST="$VALGRIND $BASEDIR/libmysqld/examples/mysqltest"
else
echo "Fatal error: Cannot find embedded server 'mysqltest'" 1>&2
exit 1
fi
else
MYSQLD="$VALGRIND $BASEDIR/sql/mysqld"
if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
......@@ -471,6 +483,7 @@ if [ x$SOURCE_DIST = x1 ] ; then
else
MYSQL_TEST="$BASEDIR/client/mysqltest"
fi
fi
if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
else
......@@ -565,7 +578,8 @@ export MYSQL MYSQL_DUMP MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
--user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
--tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
--tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT --timer-file=$MY_LOG_DIR/timer \
$MYSQL_TEST_SSL_OPTS"
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
......@@ -599,6 +613,13 @@ show_failed_diff ()
result_file=r/$1.result
eval_file=r/$1.eval
# If we have an special externsion for result files we use it if we are recording
# or a result file with that extension exists.
if [ -n "$RESULT_EXT" -a \( x$RECORD = x1 -o -f "$result_file$RESULT_EXT" \) ]
then
result_file="$result_file$RESULT_EXT"
fi
if [ -f $eval_file ]
then
result_file=$eval_file
......@@ -880,6 +901,8 @@ EOF
abort_if_failed "Could not execute manager command"
}
# The embedded server needs the cleanup so we do some of the start work
# but stop before actually running mysqld or anything.
start_master()
{
......@@ -949,6 +972,18 @@ start_master()
CUR_MYERR=$MASTER_MYERR
CUR_MYSOCK=$MASTER_MYSOCK
# For embedded server we collect the server flags and return
if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
# Add a -A to each argument to pass it to embedded server
EMBEDDED_SERVER_OPTS=""
for opt in $master_args
do
EMBEDDED_SERVER_OPTS="$EMBEDDED_SERVER_OPTS -A $opt"
done
EXTRA_MYSQL_TEST_OPT="$EMBEDDED_SERVER_OPTS"
return
fi
if [ x$DO_DDD = x1 ]
then
$ECHO "set args $master_args" > $GDB_MASTER_INIT
......@@ -1159,6 +1194,9 @@ stop_master ()
{
if [ x$MASTER_RUNNING = x1 ]
then
# For embedded server we don't stop anyting but mark that
# MASTER_RUNNING=0 to get cleanup when calling start_master().
if [ x$USE_EMBEDDED_SERVER != x1 ] ; then
pid=`$CAT $MASTER_MYPID`
manager_term $pid master
if [ $? != 0 ] && [ -f $MASTER_MYPID ]
......@@ -1176,6 +1214,7 @@ stop_master ()
else
sleep $SLEEP_TIME_AFTER_RESTART
fi
fi
MASTER_RUNNING=0
fi
}
......@@ -1217,9 +1256,13 @@ run_testcase ()
master_init_script=$TESTDIR/$tname-master.sh
slave_init_script=$TESTDIR/$tname-slave.sh
slave_master_info_file=$TESTDIR/$tname.slave-mi
result_file=$tname
tsrcdir=$TESTDIR/$tname-src
result_file="r/$tname.result"
echo $tname > $CURRENT_TEST
SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
if [ -n "$RESULT_EXT" -a \( x$RECORD = x1 -o -f "$result_file$RESULT_EXT" \) ] ; then
result_file="$result_file$RESULT_EXT"
fi
if [ "$USE_MANAGER" = 1 ] ; then
many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
fi
......@@ -1249,11 +1292,46 @@ run_testcase ()
return
fi
# Stop all slave threads, so that we don't have useless reconnection attempts
# and error messages in case the slave and master servers restart.
if [ "x$USE_EMBEDDED_SERVER" != "x1" ] ; then
# Stop all slave threads, so that we don't have useless reconnection
# attempts and error messages in case the slave and master servers restart.
stop_slave_threads
stop_slave_threads 1
stop_slave_threads 2
fi
# FIXME temporary solution, we will get a new C version of this
# script soon anyway so it is not worth it spending the time
if [ "x$USE_EMBEDDED_SERVER" = "x1" -a -z "$DO_TEST" ] ; then
for t in \
"bdb-deadlock" \
"connect" \
"flush_block_commit" \
"grant2" \
"grant_cache" \
"grant" \
"init_connect" \
"innodb-deadlock" \
"innodb-lock" \
"mix_innodb_myisam_binlog" \
"mysqlbinlog2" \
"mysqlbinlog" \
"mysqldump" \
"mysql_protocols" \
"ps_1general" \
"rename" \
"show_check" \
"system_mysql_db_fix" \
"user_var" \
"variables"
do
if [ "$tname" = "$t" ] ; then
skip_test $tname
return
fi
done
fi
if [ -z "$USE_RUNNING_SERVER" ] ;
then
......@@ -1269,6 +1347,10 @@ run_testcase ()
;;
--result-file=*)
result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
result_file="r/$result_file.result"
if [ -n "$RESULT_EXT" -a \( x$RECORD = x1 -o -f "$result_file$RESULT_EXT" \) ] ; then
result_file="$result_file$RESULT_EXT"
fi
# Note that this must be set to space, not "" for test-reset to work
EXTRA_MASTER_OPT=" "
;;
......@@ -1278,7 +1360,11 @@ run_testcase ()
start_master
TZ=$MY_TZ; export TZ
else
if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || [ -f $master_init_script ]
# If we had extra master opts to the previous run
# or there is no master running (FIXME strange.....)
# or there is a master init script
if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || \
[ -f $master_init_script ]
then
EXTRA_MASTER_OPT=""
stop_master
......@@ -1289,6 +1375,8 @@ run_testcase ()
fi
fi
# We never start a slave if embedded server is used
if [ "x$USE_EMBEDDED_SERVER" != "x1" ] ; then
do_slave_restart=0
if [ -f $slave_opt_file ] ;
then
......@@ -1325,11 +1413,12 @@ run_testcase ()
start_slave 2
fi
fi
fi
cd $MYSQL_TEST_DIR
if [ -f $tf ] ; then
$RM -f r/$tname.*reject
mysql_test_args="-R r/$result_file.result $EXTRA_MYSQL_TEST_OPT"
mysql_test_args="-R $result_file $EXTRA_MYSQL_TEST_OPT"
if [ -z "$DO_CLIENT_GDB" ] ; then
`$MYSQL_TEST $mysql_test_args < $tf 2> $TIMEFILE`;
else
......@@ -1349,7 +1438,12 @@ run_testcase ()
if [ $res = 0 ]; then
total_inc
pass_inc
$ECHO "$RES$RES_SPACE [ pass ]"
TIMER=""
if [ -f "$MY_LOG_DIR/timer" ]; then
TIMER=`cat $MY_LOG_DIR/timer`
TIMER=`$PRINTF "%13s" $TIMER`
fi
$ECHO "$RES$RES_SPACE [ pass ] $TIMER"
else
# why the following ``if'' ? That is why res==1 is special ?
if [ $res = 2 ]; then
......@@ -1364,12 +1458,13 @@ run_testcase ()
$ECHO "$RES$RES_SPACE [ fail ]"
$ECHO
error_is
show_failed_diff $result_file
show_failed_diff $tname
$ECHO
if [ x$FORCE != x1 ] ; then
$ECHO "Aborting: $tname failed. To continue, re-run with '--force'."
$ECHO
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && \
[ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
then
mysql_stop
stop_manager
......@@ -1377,7 +1472,8 @@ run_testcase ()
exit 1
fi
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && \
[ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
then
mysql_restart
fi
......@@ -1511,7 +1607,7 @@ then
fi
$ECHO
$ECHO " TEST RESULT"
$ECHO "TEST RESULT TIME (ms)"
$ECHO $DASH72
if [ -z "$1" ] ;
......
This diff is collapsed.
reset master;
create database `drop-temp+table-test`;
use `drop-temp+table-test`;
create temporary table `table:name` (a int);
select get_lock("a",10);
get_lock("a",10)
1
select get_lock("a",10);
get_lock("a",10)
1
show binlog events;
drop database `drop-temp+table-test`;
drop table if exists t1,t2;
create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
create table t2 (payoutID SMALLINT UNSIGNED NOT NULL PRIMARY KEY);
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
ERROR 23000: Duplicate entry '16' for key 1
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
select * from t2;
payoutID
1
4
6
9
10
11
12
14
16
19
20
22
drop table t1,t2;
CREATE TABLE `t1` (
`numeropost` bigint(20) unsigned NOT NULL default '0',
`icone` tinyint(4) unsigned NOT NULL default '0',
`numreponse` bigint(20) unsigned NOT NULL auto_increment,
`contenu` text NOT NULL,
`pseudo` varchar(50) NOT NULL default '',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`ip` bigint(11) NOT NULL default '0',
`signature` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`,`numreponse`)
,KEY `ip` (`ip`),
KEY `date` (`date`),
KEY `pseudo` (`pseudo`),
KEY `numreponse` (`numreponse`)
) ENGINE=MyISAM;
CREATE TABLE `t2` (
`numeropost` bigint(20) unsigned NOT NULL default '0',
`icone` tinyint(4) unsigned NOT NULL default '0',
`numreponse` bigint(20) unsigned NOT NULL auto_increment,
`contenu` text NOT NULL,
`pseudo` varchar(50) NOT NULL default '',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`ip` bigint(11) NOT NULL default '0',
`signature` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`,`numreponse`),
KEY `ip` (`ip`),
KEY `date` (`date`),
KEY `pseudo` (`pseudo`),
KEY `numreponse` (`numreponse`)
) ENGINE=MyISAM;
INSERT INTO t2
(numeropost,icone,numreponse,contenu,pseudo,date,ip,signature) VALUES
(9,1,56,'test','joce','2001-07-25 13:50:53'
,3649052399,0);
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
SELECT 1618,icone,contenu,pseudo,date,signature,ip FROM t2
WHERE numeropost=9 ORDER BY numreponse ASC;
show variables like '%bulk%';
Variable_name Value
bulk_insert_buffer_size 8388608
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
SELECT 1718,icone,contenu,pseudo,date,signature,ip FROM t2
WHERE numeropost=9 ORDER BY numreponse ASC;
DROP TABLE t1,t2;
create table t1(a int, unique(a));
insert into t1 values(2);
create table t2(a int);
insert into t2 values(1),(2);
reset master;
insert into t1 select * from t2;
ERROR 23000: Duplicate entry '2' for key 1
show binlog events;
select * from t1;
a
1
2
drop table t1, t2;
create table t1 (a int not null);
create table t2 (a int not null);
insert into t1 values (1);
insert into t1 values (a+2);
insert into t1 values (a+3);
insert into t1 values (4),(a+5);
insert into t1 select * from t1;
select * from t1;
a
1
2
3
4
5
1
2
3
4
5
insert into t1 select * from t1 as t2;
select * from t1;
a
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
insert into t2 select * from t1 as t2;
select * from t1;
a
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
insert into t1 select t2.a from t1,t2;
select * from t1;
a
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
insert into t1 select * from t1,t1;
ERROR 42000: Not unique table/alias: 't1'
drop table t1,t2;
create table t1 (a int not null primary key, b char(10));
create table t2 (a int not null, b char(10));
insert into t1 values (1,"t1:1"),(3,"t1:3");
insert into t2 values (2,"t2:2"), (3,"t2:3");
insert into t1 select * from t2;
ERROR 23000: Duplicate entry '3' for key 1
select * from t1;
a b
1 t1:1
3 t1:3
2 t2:2
replace into t1 select * from t2;
select * from t1;
a b
1 t1:1
3 t2:3
2 t2:2
drop table t1,t2;
CREATE TABLE t1 ( USID INTEGER UNSIGNED, ServerID TINYINT UNSIGNED, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User CHAR(32) NOT NULL DEFAULT '<UNKNOWN>', NASAddr INTEGER UNSIGNED, NASPort INTEGER UNSIGNED, NASPortType INTEGER UNSIGNED, ConnectSpeed INTEGER UNSIGNED, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER UNSIGNED, SessionTime INTEGER UNSIGNED, PacketsIn INTEGER UNSIGNED, OctetsIn INTEGER UNSIGNED, PacketsOut INTEGER UNSIGNED, OctetsOut INTEGER UNSIGNED, TerminateCause INTEGER UNSIGNED, UnauthTime TINYINT UNSIGNED, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL);
CREATE TABLE t2 ( USID INTEGER UNSIGNED AUTO_INCREMENT, ServerID TINYINT UNSIGNED, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User TEXT NOT NULL, NASAddr INTEGER UNSIGNED, NASPort INTEGER UNSIGNED, NASPortType INTEGER UNSIGNED, ConnectSpeed INTEGER UNSIGNED, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER UNSIGNED, SessionTime INTEGER UNSIGNED, PacketsIn INTEGER UNSIGNED, OctetsIn INTEGER UNSIGNED, PacketsOut INTEGER UNSIGNED, OctetsOut INTEGER UNSIGNED, TerminateCause INTEGER UNSIGNED, UnauthTime TINYINT UNSIGNED, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL, INDEX(USID,ServerID,NASAddr,SessionID), INDEX(AssignedAddr));
INSERT INTO t1 VALUES (39,42,'Access-Granted','46','491721000045',2130706433,17690,NULL,NULL,'Localnet','491721000045','49172200000',754974766,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2003-07-18 00:11:21',NULL,NULL,20030718001121);
INSERT INTO t2 SELECT USID, ServerID, State, SessionID, User, NASAddr, NASPort, NASPortType, ConnectSpeed, CarrierType, CallingStationID, CalledStationID, AssignedAddr, SessionTime, PacketsIn, OctetsIn, PacketsOut, OctetsOut, TerminateCause, UnauthTime, AccessRequestTime, AcctStartTime, AcctLastTime, LastModification from t1 LIMIT 1;
drop table t1,t2;
CREATE TABLE t1(
Month date NOT NULL,
Type tinyint(3) unsigned NOT NULL auto_increment,
Field int(10) unsigned NOT NULL,
Count int(10) unsigned NOT NULL,
UNIQUE KEY Month (Month,Type,Field)
);
insert into t1 Values
(20030901, 1, 1, 100),
(20030901, 1, 2, 100),
(20030901, 2, 1, 100),
(20030901, 2, 2, 100),
(20030901, 3, 1, 100);
select * from t1;
Month Type Field Count
2003-09-01 1 1 100
2003-09-01 1 2 100
2003-09-01 2 1 100
2003-09-01 2 2 100
2003-09-01 3 1 100
Select null, Field, Count From t1 Where Month=20030901 and Type=2;
NULL Field Count
NULL 1 100
NULL 2 100
create table t2(No int not null, Field int not null, Count int not null);
insert into t2 Select null, Field, Count From t1 Where Month=20030901 and Type=2;
Warnings:
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'No' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'No' at row 2
select * from t2;
No Field Count
0 1 100
0 2 100
drop table t1, t2;
set global max_allowed_packet=100;
set max_allowed_packet=100;
set global net_buffer_length=100;
set net_buffer_length=100;
SELECT length("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") as len;
len
1024
select repeat('a',2000);
repeat('a',2000)
NULL
Warnings:
Warning 1301 Result of repeat() was larger than max_allowed_packet (1024) - truncated
select @@net_buffer_length, @@max_allowed_packet;
@@net_buffer_length @@max_allowed_packet
1024 1024
SELECT length("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") as len;
set global max_allowed_packet=default;
set max_allowed_packet=default;
set global net_buffer_length=default;
set net_buffer_length=default;
SELECT length("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") as len;
len
100
select length(repeat('a',2000));
length(repeat('a',2000))
2000
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
drop table if exists t1;
SELECT 10,10.0,10.,.1e+2,100.0e-1;
10 10.0 10. .1e+2 100.0e-1
10 10.0 10 10 10
SELECT 6e-05, -6e-05, --6e-05, -6e-05+1.000000;
6e-05 -6e-05 --6e-05 -6e-05+1.000000
6e-05 -6e-05 6e-05 0.99994
SELECT 1e1,1.e1,1.0e1,1e+1,1.e+1,1.0e+1,1e-1,1.e-1,1.0e-1;
1e1 1.e1 1.0e1 1e+1 1.e+1 1.0e+1 1e-1 1.e-1 1.0e-1
10 10 10 10 10 10 0.1 0.1 0.1
create table t1 (f1 float(24),f2 float(52));
show full columns from t1;
Field Type Collation Null Key Default Extra Privileges Comment
f1 float NULL YES NULL
f2 double NULL YES NULL
insert into t1 values(10,10),(1e+5,1e+5),(1234567890,1234567890),(1e+10,1e+10),(1e+15,1e+15),(1e+20,1e+20),(1e+50,1e+50),(1e+150,1e+150);
Warnings:
Warning 1264 Data truncated; out of range for column 'f1' at row 7
Warning 1264 Data truncated; out of range for column 'f1' at row 8
insert into t1 values(-10,-10),(1e-5,1e-5),(1e-10,1e-10),(1e-15,1e-15),(1e-20,1e-20),(1e-50,1e-50),(1e-150,1e-150);
select * from t1;
f1 f2
10 10
100000 100000
1.23457e+09 1234567890
1e+10 10000000000
1e+15 1e+15
1e+20 1e+20
3.40282e+38 1e+50
3.40282e+38 1e+150
-10 -10
1e-05 1e-05
1e-10 1e-10
1e-15 1e-15
1e-20 1e-20
0 1e-50
0 1e-150
drop table t1;
create table t1 (datum double);
insert into t1 values (0.5),(1.0),(1.5),(2.0),(2.5);
select * from t1;
datum
0.5
1
1.5
2
2.5
select * from t1 where datum < 1.5;
datum
0.5
1
select * from t1 where datum > 1.5;
datum
2
2.5
select * from t1 where datum = 1.5;
datum
1.5
drop table t1;
create table t1 (a decimal(7,3) not null, key (a));
insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1");
select a from t1 order by a;
a
-0.010
-0.002
-0.000
0.000
1.000
select min(a) from t1;
min(a)
-0.010
drop table t1;
create table t1 (c1 double, c2 varchar(20));
insert t1 values (121,"16");
select c1 + c1 * (c2 / 100) as col from t1;
col
140.36
create table t2 select c1 + c1 * (c2 / 100) as col1, round(c1, 5) as col2, round(c1, 35) as col3, sqrt(c1*1e-15) col4 from t1;
select * from t2;
col1 col2 col3 col4
140.36 121.00000 121 3.47850542618522e-07
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`col1` double default NULL,
`col2` double(22,5) default NULL,
`col3` double default NULL,
`col4` double default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1,t2;
create table t1 (a float);
insert into t1 values (1);
select max(a),min(a),avg(a) from t1;
max(a) min(a) avg(a)
1 1 1
drop table t1;
create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(5,6));
show full columns from t1;
Field Type Collation Null Key Default Extra Privileges Comment
f float NULL YES NULL
f2 float NULL YES NULL
f3 float(6,2) NULL YES NULL
d double NULL YES NULL
d2 double NULL YES NULL
d3 double(10,3) NULL YES NULL
de decimal(10,0) NULL YES NULL
de2 decimal(6,0) NULL YES NULL
de3 decimal(5,2) NULL YES NULL
n decimal(10,0) NULL YES NULL
n2 decimal(8,0) NULL YES NULL
n3 decimal(7,6) NULL YES NULL
drop table t1;
create table t1 (a decimal(7,3) not null, key (a));
insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1");
select a from t1 order by a;
a
-0.010
-0.002
-0.000
0.000
1.000
select min(a) from t1;
min(a)
-0.010
drop table t1;
create table t1 (a float(200,100), b double(200,100));
insert t1 values (1.0, 2.0);
select * from t1;
a b
1.000000000000000000000000000000 2.000000000000000000000000000000
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` float(200,30) default NULL,
`b` double(200,30) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 (c20 char);
insert into t1 values (5000.0);
drop table t1;
create table t1 (f float(54));
ERROR 42000: Incorrect column specifier for column 'f'
drop table if exists t1;
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment