From: Tor Didriksen Date: January 10 2011 9:35am Subject: bzr commit into mysql-trunk branch (tor.didriksen:3472) Bug#59331 List-Archive: http://lists.mysql.com/commits/128256 X-Bug: 59331 Message-Id: <20110110093545.474733127@atum07.norway.sun.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1755271818997358789==" --===============1755271818997358789== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #At file:///export/home/didrik/repo/trunk-bugxxxxx-pqinit-error/ based on revid:jorgen.loland@stripped 3472 Tor Didriksen 2011-01-06 Bug#59331 filesort with priority queue: handling of out-of-memory Verifies that we have an error if init_queue() fails. @ mysql-test/r/filesort_debug.result New test case. @ mysql-test/t/filesort_debug.test New test case. @ sql/bounded_queue.h Add DBUG code to simulate out-of-memory. @ sql/filesort.cc Terminate filesort if pq.init() fails. Also: don't allocate more memory than we actually need for the 'strip-off-addon-fields' case. added: mysql-test/r/filesort_debug.result mysql-test/t/filesort_debug.test modified: sql/bounded_queue.h sql/filesort.cc === added file 'mysql-test/r/filesort_debug.result' --- a/mysql-test/r/filesort_debug.result 1970-01-01 00:00:00 +0000 +++ b/mysql-test/r/filesort_debug.result 2011-01-06 14:38:38 +0000 @@ -0,0 +1,11 @@ +# +# Bug#59331 filesort with priority queue: handling of out-of-memory +# +CREATE TABLE t1(f0 int auto_increment primary key, f1 int, f2 varchar(200)); +INSERT INTO t1(f1, f2) VALUES +(0,"0"),(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5"), +(6,"6"),(7,"7"),(8,"8"),(9,"9"),(10,"10"); +set debug= '+d,bounded_queue_init_fail'; +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 1; +ERROR HY000: Out of memory (Needed 24 bytes) +DROP TABLE t1; === added file 'mysql-test/t/filesort_debug.test' --- a/mysql-test/t/filesort_debug.test 1970-01-01 00:00:00 +0000 +++ b/mysql-test/t/filesort_debug.test 2011-01-06 14:38:38 +0000 @@ -0,0 +1,16 @@ +--source include/have_debug.inc + +--echo # +--echo # Bug#59331 filesort with priority queue: handling of out-of-memory +--echo # + +CREATE TABLE t1(f0 int auto_increment primary key, f1 int, f2 varchar(200)); +INSERT INTO t1(f1, f2) VALUES +(0,"0"),(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5"), +(6,"6"),(7,"7"),(8,"8"),(9,"9"),(10,"10"); + +set debug= '+d,bounded_queue_init_fail'; +--error 5 +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 1; + +DROP TABLE t1; === modified file 'sql/bounded_queue.h' --- a/sql/bounded_queue.h 2010-12-17 09:41:21 +0000 +++ b/sql/bounded_queue.h 2011-01-06 14:38:38 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -166,6 +166,10 @@ int Bounded_queue(get_ptr_compare(compare_length)); + + DBUG_EXECUTE_IF("bounded_queue_init_fail", + DBUG_SET("+d,simulate_out_of_memory");); + // We allocate space for one extra element, for replace when queue is full. return init_queue(&m_queue, (uint) max_elements + 1, 0, max_at_top, === modified file 'sql/filesort.cc' --- a/sql/filesort.cc 2011-01-04 15:23:59 +0000 +++ b/sql/filesort.cc 2011-01-06 14:38:38 +0000 @@ -226,10 +226,15 @@ ha_rows filesort(THD *thd, TABLE *table, compare_length, &make_sortkey, ¶m, table_sort.sort_keys)) { - // If failed to init pq, fall back to merge-sort. - DBUG_PRINT("info", ("failed to allocate PQ, fallback to sort-merge")); + /* + If we fail to init pq, we have to give up: + out of memory means my_malloc() will call my_error(). + */ + DBUG_PRINT("info", ("failed to allocate PQ")); my_free(table_sort.sort_keys); table_sort.sort_keys= NULL; + DBUG_ASSERT(thd->is_error()); + goto err; } } else @@ -1222,7 +1227,8 @@ bool check_if_pq_applicable(Sort_param * DBUG_RETURN(false); make_char_array(filesort_info, - param->max_keys_per_buffer, param->rec_length); + param->max_keys_per_buffer, + param->sort_length + param->ref_length); if (filesort_info->sort_keys) { // Make attached data to be references instead of fields. --===============1755271818997358789== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/tor.didriksen@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: tor.didriksen@stripped\ # tcimyx8pvf4hxhxs # target_branch: file:///export/home/didrik/repo/trunk-bugxxxxx-\ # pqinit-error/ # testament_sha1: c622959f585ec670b6ef4ed37a75f2e2f175fca6 # timestamp: 2011-01-10 10:35:45 +0100 # base_revision_id: jorgen.loland@stripped\ # iep4ek5s7klq6rwk # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWXonM3IABJ9/gDgREABY//// f+f/YL////BgCc++3OvsCvRoOlYxXd6PXoekum1mgbbhqNENU9T9RNNpqep6YaUw0mQDARtIDExD EBKSMI0anqGamiZT1HpH6o2po0B+qYmmgMI2oPUDgGEYTTEMAgGQAwjTJkwjAQ0EiKamJT9TU2TI aaZEYjR5CNNAAGjQDTQEUlPTU1Tyn6NT0J6kzRqaB6QD1GjQDQGgaNDQSSAgJhNA0AINSj1PUZPU 2oPRPSepkA2po4OGNLz0EFn/YbLiSWQI2wfgkkUuZh2OypbYmOyxo9RdV54iPjCnrO0ZDROd/eMK GjQr2ekFGMDRCuqvGCiP70rqnGK0TH6CSpNS97h8c+fo0es5u2GrRCRCc/2FSQoIKFBBBFA6EhkV NsCvpPDEobluNEUZ6cjXK2I/QMNkdcJxlpApMuzVgfEuJ79mqcUXbpuRXOoqddA6hQj6xSEUzbr6 Xo0urdOz8SHjqUWNMll4MqO5HI6jBwSix4VCpiiq37zM+Yx+ZICii3G6tjwbr79u1y89fE9knrac dzZtppsDi28c3XOMIlZAqInmKR5QaOfPZIORibGMbGxYYKNNobEauZsfCqQWDzafjLt/Lf0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