2011-06-30 17:46:53 +02:00
|
|
|
/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
|
|
|
|
#ifndef FILESORT_INCLUDED
|
|
|
|
#define FILESORT_INCLUDED
|
|
|
|
|
|
|
|
class SQL_SELECT;
|
|
|
|
|
|
|
|
#include "my_global.h" /* uint, uchar */
|
|
|
|
#include "my_base.h" /* ha_rows */
|
2016-02-09 12:35:59 -08:00
|
|
|
#include "sql_list.h" /* Sql_alloc */
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
class SQL_SELECT;
|
|
|
|
class THD;
|
|
|
|
struct TABLE;
|
2015-04-12 04:48:42 +03:00
|
|
|
class Filesort_tracker;
|
2016-02-09 12:35:59 -08:00
|
|
|
struct SORT_FIELD;
|
|
|
|
typedef struct st_order ORDER;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sorting related info.
|
|
|
|
To be extended by another WL to include complete filesort implementation.
|
|
|
|
*/
|
|
|
|
class Filesort: public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** List of expressions to order the table by */
|
|
|
|
ORDER *order;
|
|
|
|
/** Number of records to return */
|
|
|
|
ha_rows limit;
|
|
|
|
/** ORDER BY list with some precalculated info for filesort */
|
|
|
|
SORT_FIELD *sortorder;
|
|
|
|
/** select to use for getting records */
|
|
|
|
SQL_SELECT *select;
|
|
|
|
/** TRUE <=> free select on destruction */
|
|
|
|
bool own_select;
|
|
|
|
/** true means we are using Priority Queue for order by with limit. */
|
|
|
|
bool using_pq;
|
|
|
|
|
|
|
|
Filesort(ORDER *order_arg, ha_rows limit_arg, SQL_SELECT *select_arg):
|
|
|
|
order(order_arg),
|
|
|
|
limit(limit_arg),
|
|
|
|
sortorder(NULL),
|
|
|
|
select(select_arg),
|
|
|
|
own_select(false),
|
|
|
|
using_pq(false)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(order);
|
|
|
|
};
|
|
|
|
|
|
|
|
~Filesort() { cleanup(); }
|
|
|
|
/* Prepare ORDER BY list for sorting. */
|
|
|
|
uint make_sortorder(THD *thd);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void cleanup();
|
|
|
|
};
|
2010-03-31 16:05:33 +02:00
|
|
|
|
2016-02-09 12:35:59 -08:00
|
|
|
ha_rows filesort(THD *thd, TABLE *table, Filesort *filesort,
|
|
|
|
bool sort_positions, ha_rows *examined_rows,
|
|
|
|
ha_rows *found_rows, Filesort_tracker* tracker);
|
2010-03-31 16:05:33 +02:00
|
|
|
void filesort_free_buffers(TABLE *table, bool full);
|
|
|
|
void change_double_for_sort(double nr,uchar *to);
|
|
|
|
|
|
|
|
#endif /* FILESORT_INCLUDED */
|