From 614135222f3382e50a0d4962dcf1445f2bc28177 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 May 2007 17:19:36 +0200 Subject: [PATCH 1/3] WL#2247 mysqltest: add option for sorting results - Change from "query_sorted " to "sorted_results" client/mysqltest.c: Replace "query_sorted " with the ability to turn on "one shot result sorting" with the command "sorted_results" mysql-test/r/mysqltest.result: Update test and result mysql-test/t/mysqltest.test: Update test and result --- client/mysqltest.c | 18 ++++++--- mysql-test/r/mysqltest.result | 52 +++++++++++++++++++++++++ mysql-test/t/mysqltest.test | 71 +++++++++++++++++++++++++++++++---- 3 files changed, 128 insertions(+), 13 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 93be37262c8..cf4f0e00504 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -271,7 +271,7 @@ enum enum_commands { Q_EXEC, Q_DELIMITER, Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR, Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, - Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_QUERY_SORTED, + Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULTS, Q_START_TIMER, Q_END_TIMER, Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, @@ -341,7 +341,7 @@ const char *command_names[]= "horizontal_results", "query_vertical", "query_horizontal", - "query_sorted", + "sorted_results", "start_timer", "end_timer", "character_set", @@ -6161,13 +6161,19 @@ int main(int argc, char **argv) case Q_DISPLAY_HORIZONTAL_RESULTS: display_result_vertically= FALSE; break; + case Q_SORTED_RESULTS: + /* + Turn on sorting of result set, will be reset after next + command + */ + display_result_sorted= TRUE; + break; case Q_LET: do_let(command); break; case Q_EVAL_RESULT: eval_result = 1; break; case Q_EVAL: case Q_QUERY_VERTICAL: case Q_QUERY_HORIZONTAL: - case Q_QUERY_SORTED: if (command->query == command->query_buf) { /* Skip the first part of command, i.e query_xxx */ @@ -6179,7 +6185,6 @@ int main(int argc, char **argv) case Q_REAP: { my_bool old_display_result_vertically= display_result_vertically; - my_bool old_display_result_sorted= display_result_sorted; /* Default is full query, both reap and send */ int flags= QUERY_REAP_FLAG | QUERY_SEND_FLAG; @@ -6196,7 +6201,6 @@ int main(int argc, char **argv) /* Check for special property for this query */ display_result_vertically|= (command->type == Q_QUERY_VERTICAL); - display_result_sorted= (command->type == Q_QUERY_SORTED); if (save_file[0]) { @@ -6209,7 +6213,6 @@ int main(int argc, char **argv) /* Restore settings */ display_result_vertically= old_display_result_vertically; - display_result_sorted= old_display_result_sorted; break; } @@ -6366,6 +6369,9 @@ int main(int argc, char **argv) the replace structures should be cleared */ free_all_replace(); + + /* Also reset "sorted_results" */ + display_result_sorted= FALSE; } last_command_executed= command_executed; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index e460275e758..989792160f0 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -546,6 +546,12 @@ a b c 2 Part 2 2007-04-05 00:00:00 2 Part 3 2007-04-05 00:00:00 select * from t1; +a b c +1 Line 1 2007-04-05 00:00:00 +2 Part 2 2007-04-05 00:00:00 +1 Line 1 2007-04-05 00:00:00 +2 Part 3 2007-04-05 00:00:00 +select * from t1; select ''; @@ -561,4 +567,50 @@ hep select "hepp"; hepp hepp +drop table t1; +SELECT 2 as "my_col" +UNION +SELECT 1; +my_col +1 +2 +SELECT 2 as "my_col" UNION SELECT 1; +my_col +1 +2 +SELECT 2 as "my_col" +UNION +SELECT 1; +my_col +1 +2 +SELECT '2' as "3" +UNION +SELECT '1'; +3 +1 +2 +SET @a = 17; +SELECT 2 as "my_col" +UNION +SELECT 1; +my_col +1 +2 +SELECT 2 as "my_col" +UNION +SELECT 1; +my_col +2 +1 +SELECT 2 as "my_col" +UNION +SELECT 1; +my_col +1 +2 +SELECT '2' as "my_col1",2 as "my_col2" +UNION +SELECT '1',1 from t2; +ERROR 42S02: Table 'test.t2' doesn't exist End of tests diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index a9ac2ec8a96..99213d47d38 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1693,15 +1693,72 @@ create table t1( a int, b char(255), c timestamp); insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 2", '2007-04-05'); insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 3", '2007-04-05'); select * from t1; -query_sorted select * from t1; +--sorted_results +select * from t1; +# Should not be sorted +select * from t1; disable_result_log; -query_sorted select * from t1; +sorted_results; +select * from t1; enable_result_log; -query_sorted select ''; -query_sorted select "h"; -query_sorted select "he"; -query_sorted select "hep"; -query_sorted select "hepp"; +--sorted_results +select ''; +sorted_results; +select "h"; +--sorted_results +select "he"; +--sorted_results +select "hep"; +--sorted_results +select "hepp"; +drop table t1; + +# 1. Assignment of result set sorting +sorted_results; + SELECT 2 as "my_col" +UNION +SELECT 1; + +--sorted_results +SELECT 2 as "my_col" UNION SELECT 1; +--sorted_results +SELECT 2 as "my_col" +UNION +SELECT 1; + +# 2. Ensure that the table header will be not sorted into the result +--sorted_results +SELECT '2' as "3" +UNION +SELECT '1'; + +# 3. "sorted_results" changes nothing when applied to a non query statement. +sorted_results; + SET @a = 17; + +# 4. Show that "--sorted_results" affects the next statement only +--sorted_results +SELECT 2 as "my_col" +UNION +SELECT 1; +SELECT 2 as "my_col" +UNION +SELECT 1; + +# 5. Ensure that "sorted_results" in combination with $variables works +let $my_stmt=SELECT 2 as "my_col" +UNION +SELECT 1; +--sorted_results +eval $my_stmt; + +# 6. Ensure that "sorted_results " does not change the semantics of "--error ...." +# or the protocol output after such an expected failure +--sorted_results +--error 1146 +SELECT '2' as "my_col1",2 as "my_col2" +UNION +SELECT '1',1 from t2; --echo End of tests From f106d396c0f80297354b8a6a58ab6006c634f467 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 May 2007 17:51:28 +0200 Subject: [PATCH 2/3] Bug#28473 Does mysql-test-run.pl handle LD_LIBRARY_PATH wrong ? - Fix spelling error mysql-test/mysql-test-run.pl: Fix spelling error --- mysql-test/mysql-test-run.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 102f12a4709..5b2b88d4ec6 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1634,7 +1634,7 @@ sub environment_setup () { } $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths, - $ENV{'LD_LIBRARY_PATHS'} ? + $ENV{'LD_LIBRARY_PATH'} ? split(':', $ENV{'LD_LIBRARY_PATH'}) : ()); mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}"); From 421d8ca9728ff882780599ce36cfa20936c7863e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 18 May 2007 12:50:23 +0200 Subject: [PATCH 3/3] WL#2247 mysqltest: add option for sorting results - Final touchups client/mysqltest.c: Final touch ups, rename sorted_results to sorted_result mysql-test/r/mysqltest.result: Update test result mysql-test/t/mysqltest.test: Update results with additional subtests for empty result set, NULL values and 1024 rows --- client/mysqltest.c | 8 +-- mysql-test/r/mysqltest.result | 54 ++++++++++++++++-- mysql-test/t/mysqltest.test | 102 +++++++++++++++++++++++++--------- 3 files changed, 128 insertions(+), 36 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index cf4f0e00504..d69ef177fb6 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -271,7 +271,7 @@ enum enum_commands { Q_EXEC, Q_DELIMITER, Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR, Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, - Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULTS, + Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULT, Q_START_TIMER, Q_END_TIMER, Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, @@ -341,7 +341,7 @@ const char *command_names[]= "horizontal_results", "query_vertical", "query_horizontal", - "sorted_results", + "sorted_result", "start_timer", "end_timer", "character_set", @@ -6161,7 +6161,7 @@ int main(int argc, char **argv) case Q_DISPLAY_HORIZONTAL_RESULTS: display_result_vertically= FALSE; break; - case Q_SORTED_RESULTS: + case Q_SORTED_RESULT: /* Turn on sorting of result set, will be reset after next command @@ -6370,7 +6370,7 @@ int main(int argc, char **argv) */ free_all_replace(); - /* Also reset "sorted_results" */ + /* Also reset "sorted_result" */ display_result_sorted= FALSE; } last_command_executed= command_executed; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 989792160f0..000bec7023c 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -590,13 +590,35 @@ SELECT '1'; 3 1 2 -SET @a = 17; -SELECT 2 as "my_col" +CREATE TABLE t1( a CHAR); +SELECT * FROM t1; +a +DROP TABLE t1; +SELECT NULL as "my_col1",2 AS "my_col2" UNION -SELECT 1; -my_col -1 -2 +SELECT NULL,1; +my_col1 my_col2 +NULL 2 +NULL 1 +SELECT NULL as "my_col1",2 AS "my_col2" +UNION +SELECT NULL,1; +my_col1 my_col2 +NULL 1 +NULL 2 +SELECT 2 as "my_col1",NULL AS "my_col2" +UNION +SELECT 1,NULL; +my_col1 my_col2 +2 NULL +1 NULL +SELECT 2 as "my_col1",NULL AS "my_col2" +UNION +SELECT 1,NULL; +my_col1 my_col2 +1 NULL +2 NULL +SET @a = 17; SELECT 2 as "my_col" UNION SELECT 1; @@ -613,4 +635,24 @@ SELECT '2' as "my_col1",2 as "my_col2" UNION SELECT '1',1 from t2; ERROR 42S02: Table 'test.t2' doesn't exist +SELECT '1' as "my_col1",2 as "my_col2" +UNION +SELECT '2',1; +my_col1 my_col2 +# 1 +# 2 +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 SET f1 = 1024; +INSERT INTO t1 SELECT f1 - 1 FROM t1; +INSERT INTO t1 SELECT f1 - 2 FROM t1; +INSERT INTO t1 SELECT f1 - 4 FROM t1; +INSERT INTO t1 SELECT f1 - 8 FROM t1; +INSERT INTO t1 SELECT f1 - 16 FROM t1; +INSERT INTO t1 SELECT f1 - 32 FROM t1; +INSERT INTO t1 SELECT f1 - 64 FROM t1; +INSERT INTO t1 SELECT f1 - 128 FROM t1; +INSERT INTO t1 SELECT f1 - 256 FROM t1; +INSERT INTO t1 SELECT f1 - 512 FROM t1; +SELECT * FROM t1; +DROP TABLE t1; End of tests diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 99213d47d38..5a8a4901569 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1686,79 +1686,129 @@ EOF --exec echo "echo Some output; exit; echo Not this;" | $MYSQL_TEST 2>&1 # ---------------------------------------------------------------------------- -# test for query_sorted +# test for sorted_result # ---------------------------------------------------------------------------- create table t1( a int, b char(255), c timestamp); insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 2", '2007-04-05'); insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 3", '2007-04-05'); select * from t1; ---sorted_results +--sorted_result select * from t1; # Should not be sorted select * from t1; disable_result_log; -sorted_results; +sorted_result; select * from t1; enable_result_log; ---sorted_results +--sorted_result select ''; -sorted_results; +sorted_result; select "h"; ---sorted_results +--sorted_result select "he"; ---sorted_results +--sorted_result select "hep"; ---sorted_results +--sorted_result select "hepp"; drop table t1; # 1. Assignment of result set sorting -sorted_results; +sorted_result; SELECT 2 as "my_col" UNION SELECT 1; - ---sorted_results +# +--sorted_result SELECT 2 as "my_col" UNION SELECT 1; ---sorted_results +--sorted_result SELECT 2 as "my_col" UNION SELECT 1; # 2. Ensure that the table header will be not sorted into the result ---sorted_results +--sorted_result SELECT '2' as "3" UNION SELECT '1'; -# 3. "sorted_results" changes nothing when applied to a non query statement. -sorted_results; +# 3. Ensure that an empty result set does not cause problems +CREATE TABLE t1( a CHAR); +--sorted_result +SELECT * FROM t1; +DROP TABLE t1; + +# 4. Ensure that NULL values within the result set do not cause problems +SELECT NULL as "my_col1",2 AS "my_col2" +UNION +SELECT NULL,1; +--sorted_result +SELECT NULL as "my_col1",2 AS "my_col2" +UNION +SELECT NULL,1; +# +SELECT 2 as "my_col1",NULL AS "my_col2" +UNION +SELECT 1,NULL; +--sorted_result +SELECT 2 as "my_col1",NULL AS "my_col2" +UNION +SELECT 1,NULL; + +# 5. "sorted_result" changes nothing when applied to a non query statement. +sorted_result; SET @a = 17; - -# 4. Show that "--sorted_results" affects the next statement only ---sorted_results -SELECT 2 as "my_col" -UNION -SELECT 1; +# +# 6. Show that "sorted_result;" before the "SET @a = 17;" above does not affect +# the now following query. SELECT 2 as "my_col" UNION SELECT 1; -# 5. Ensure that "sorted_results" in combination with $variables works +# 7. Ensure that "sorted_result" in combination with $variables works let $my_stmt=SELECT 2 as "my_col" UNION SELECT 1; ---sorted_results +--sorted_result eval $my_stmt; -# 6. Ensure that "sorted_results " does not change the semantics of "--error ...." -# or the protocol output after such an expected failure ---sorted_results +# 8. Ensure that "sorted_result " does not change the semantics of +# "--error ...." or the protocol output after such an expected failure +--sorted_result --error 1146 SELECT '2' as "my_col1",2 as "my_col2" UNION SELECT '1',1 from t2; +# 9. Ensure that several result formatting options including "sorted_result" +# - have all an effect +# - "--sorted_result" does not need to be direct before the statement +# - Row sorting is applied after modification of the column content +--sorted_result +--replace_column 1 # +SELECT '1' as "my_col1",2 as "my_col2" +UNION +SELECT '2',1; + +# 10. Ensure that at least 1024 rows within a result set do not cause problems +# +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 SET f1 = 1024; +INSERT INTO t1 SELECT f1 - 1 FROM t1; +INSERT INTO t1 SELECT f1 - 2 FROM t1; +INSERT INTO t1 SELECT f1 - 4 FROM t1; +INSERT INTO t1 SELECT f1 - 8 FROM t1; +INSERT INTO t1 SELECT f1 - 16 FROM t1; +INSERT INTO t1 SELECT f1 - 32 FROM t1; +INSERT INTO t1 SELECT f1 - 64 FROM t1; +INSERT INTO t1 SELECT f1 - 128 FROM t1; +INSERT INTO t1 SELECT f1 - 256 FROM t1; +INSERT INTO t1 SELECT f1 - 512 FROM t1; +--disable_result_log +--sorted_result +SELECT * FROM t1; +--enable_result_log +DROP TABLE t1; + --echo End of tests