Commit aba6d06c authored by Michael Widenius's avatar Michael Widenius

Upgraded sphinx to version 2.0.4

Fixed memory leaks and compiler warnings in ha_sphinx.cc
Added HA_MUST_USE_TABLE_CONDITION_PUSHDOWN so that an engine can force index condition to be used

mysql-test/suite/sphinx/sphinx.result:
  Added testing of pushdown conditions and sphinx status variables.
mysql-test/suite/sphinx/sphinx.test:
  Added testing of pushdown conditions and sphinx status variables.
mysql-test/suite/sphinx/suite.pm:
  Print version number if sphinx version is too old.
sql/handler.h:
  Added HA_MUST_USE_TABLE_CONDITION_PUSHDOWN so that an engine can force index condition to be used
sql/sql_base.cc:
  Added 'thd' argument to check_unused() to be able to set 'entry->in_use' if we call handler->extra().
  This was needed as sphinx (and possible other storage engines) assumes that 'in_use' is set if handler functions are called.
sql/sql_select.cc:
  Test if handler is forcing pushdown condition to be used.
storage/sphinx/ha_sphinx.cc:
  Updated to version 2.0.4
  Fixed memory leaks and compiler warnings.
storage/sphinx/ha_sphinx.h:
  Updated to version 2.0.4
storage/sphinx/snippets_udf.cc:
  Updated to version 2.0.4
parent 18c51eee
...@@ -36,4 +36,24 @@ select * from ts where q=';groupby=attr:gid'; ...@@ -36,4 +36,24 @@ select * from ts where q=';groupby=attr:gid';
id w q gid _sph_count id w q gid _sph_count
3 1 ;groupby=attr:gid 2 2 3 1 ;groupby=attr:gid 2 2
1 1 ;groupby=attr:gid 1 2 1 1 ;groupby=attr:gid 1 2
explain select * from ts where q=';groupby=attr:gid';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition
SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='index_condition_pushdown=off';
explain select * from ts where q=';groupby=attr:gid';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition
SET optimizer_switch=@save_optimizer_switch;
drop table ts; drop table ts;
show status like "sphinx_%";
Variable_name Value
sphinx_error_commits 0
sphinx_error_group_commits 0
sphinx_error_snapshot_file
sphinx_error_snapshot_position 0
sphinx_time 0
sphinx_total 2
sphinx_total_found 2
sphinx_word_count 0
sphinx_words
...@@ -19,5 +19,11 @@ eval create table ts ( id bigint unsigned not null, w int not null, q varchar(25 ...@@ -19,5 +19,11 @@ eval create table ts ( id bigint unsigned not null, w int not null, q varchar(25
select * from ts; select * from ts;
select * from ts where q=''; select * from ts where q='';
select * from ts where q=';groupby=attr:gid'; select * from ts where q=';groupby=attr:gid';
explain select * from ts where q=';groupby=attr:gid';
SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='index_condition_pushdown=off';
explain select * from ts where q=';groupby=attr:gid';
SET optimizer_switch=@save_optimizer_switch;
drop table ts; drop table ts;
show status like "sphinx_%";
...@@ -34,11 +34,11 @@ return "No SphinxSE" unless $ENV{HA_SPHINX_SO} or ...@@ -34,11 +34,11 @@ return "No SphinxSE" unless $ENV{HA_SPHINX_SO} or
if ($ver eq "0000.0000.0000") if ($ver eq "0000.0000.0000")
{ {
$ver = sprintf "%04d.%04d", (/([0-9]+)\.([0-9]+)-(alpha|beta|gamma|RC)/); $ver = sprintf "%04d.%04d", (/([0-9]+)\.([0-9]+)-(alpha|beta|gamma|RC)/);
return "Sphinx 0.9.9 or later is needed" unless $ver ge '0001.0010'; return "Sphinx 0.9.9 or later is needed (found $ver) " unless $ver ge '0001.0010';
} }
else else
{ {
return "Sphinx 0.9.9 or later is needed" unless $ver ge '0000.0009.0009'; return "Sphinx 0.9.9 or later is needed (found $ver) " unless $ver ge '0000.0009.0009';
} }
} }
......
...@@ -175,6 +175,19 @@ ...@@ -175,6 +175,19 @@
#define HA_MRR_CANT_SORT (LL(1) << 40) #define HA_MRR_CANT_SORT (LL(1) << 40)
#define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (LL(1) << 41) #define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (LL(1) << 41)
/*
Table condition pushdown must be performed regardless of
'engine_condition_pushdown' setting.
This flag is aimed at storage engines that come with "special" predicates
that can only be evaluated inside the storage engine.
For example, when one does
select * from sphinx_table where query='{fulltext_query}'
then the "query=..." condition must be always pushed down into storage
engine.
*/
#define HA_MUST_USE_TABLE_CONDITION_PUSHDOWN (LL(1) << 42)
/* /*
Set of all binlog flags. Currently only contain the capabilities Set of all binlog flags. Currently only contain the capabilities
flags. flags.
......
...@@ -226,7 +226,7 @@ uint cached_open_tables(void) ...@@ -226,7 +226,7 @@ uint cached_open_tables(void)
#ifdef EXTRA_DEBUG #ifdef EXTRA_DEBUG
static void check_unused(void) static void check_unused(THD *thd)
{ {
uint count= 0, open_files= 0, idx= 0; uint count= 0, open_files= 0, idx= 0;
TABLE *cur_link, *start_link, *entry; TABLE *cur_link, *start_link, *entry;
...@@ -255,15 +255,20 @@ static void check_unused(void) ...@@ -255,15 +255,20 @@ static void check_unused(void)
I_P_List_iterator<TABLE, TABLE_share> it(share->free_tables); I_P_List_iterator<TABLE, TABLE_share> it(share->free_tables);
while ((entry= it++)) while ((entry= it++))
{ {
/* We must not have TABLEs in the free list that have their file closed. */ /*
We must not have TABLEs in the free list that have their file closed.
*/
DBUG_ASSERT(entry->db_stat && entry->file); DBUG_ASSERT(entry->db_stat && entry->file);
/* Merge children should be detached from a merge parent */ /* Merge children should be detached from a merge parent */
DBUG_ASSERT(! entry->file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN));
if (entry->in_use) if (entry->in_use)
{ {
DBUG_PRINT("error",("Used table is in share's list of unused tables")); /* purecov: inspected */ DBUG_PRINT("error",("Used table is in share's list of unused tables")); /* purecov: inspected */
} }
/* extra() may assume that in_use is set */
entry->in_use= thd;
DBUG_ASSERT(! entry->file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN));
entry->in_use= 0;
count--; count--;
open_files++; open_files++;
} }
...@@ -284,7 +289,7 @@ static void check_unused(void) ...@@ -284,7 +289,7 @@ static void check_unused(void)
} }
} }
#else #else
#define check_unused() #define check_unused(A)
#endif #endif
...@@ -473,7 +478,7 @@ static void table_def_remove_table(TABLE *table) ...@@ -473,7 +478,7 @@ static void table_def_remove_table(TABLE *table)
if (table == unused_tables) if (table == unused_tables)
unused_tables=0; unused_tables=0;
} }
check_unused(); check_unused(current_thd);
} }
table_cache_count--; table_cache_count--;
} }
...@@ -498,7 +503,7 @@ static void table_def_use_table(THD *thd, TABLE *table) ...@@ -498,7 +503,7 @@ static void table_def_use_table(THD *thd, TABLE *table)
} }
table->prev->next=table->next; /* Remove from unused list */ table->prev->next=table->next; /* Remove from unused list */
table->next->prev=table->prev; table->next->prev=table->prev;
check_unused(); check_unused(thd);
/* Add table to list of used tables for this share. */ /* Add table to list of used tables for this share. */
table->s->used_tables.push_front(table); table->s->used_tables.push_front(table);
table->in_use= thd; table->in_use= thd;
...@@ -515,6 +520,7 @@ static void table_def_use_table(THD *thd, TABLE *table) ...@@ -515,6 +520,7 @@ static void table_def_use_table(THD *thd, TABLE *table)
static void table_def_unuse_table(TABLE *table) static void table_def_unuse_table(TABLE *table)
{ {
THD *thd= table->in_use;
DBUG_ASSERT(table->in_use); DBUG_ASSERT(table->in_use);
/* We shouldn't put the table to 'unused' list if the share is old. */ /* We shouldn't put the table to 'unused' list if the share is old. */
...@@ -535,7 +541,7 @@ static void table_def_unuse_table(TABLE *table) ...@@ -535,7 +541,7 @@ static void table_def_unuse_table(TABLE *table)
} }
else else
unused_tables=table->next=table->prev=table; unused_tables=table->next=table->prev=table;
check_unused(); check_unused(thd);
} }
......
...@@ -8364,8 +8364,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -8364,8 +8364,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (tab->table) if (tab->table)
{ {
tab->table->file->pushed_cond= NULL; tab->table->file->pushed_cond= NULL;
if ((thd->variables.optimizer_switch & if (((thd->variables.optimizer_switch &
OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) && OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
(tab->table->file->ha_table_flags() &
HA_MUST_USE_TABLE_CONDITION_PUSHDOWN)) &&
!first_inner_tab) !first_inner_tab)
{ {
COND *push_cond= COND *push_cond=
...@@ -21270,8 +21272,11 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, ...@@ -21270,8 +21272,11 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
{ {
const COND *pushed_cond= tab->table->file->pushed_cond; const COND *pushed_cond= tab->table->file->pushed_cond;
if ((thd->variables.optimizer_switch & if (((thd->variables.optimizer_switch &
OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) && pushed_cond) OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
(tab->table->file->ha_table_flags() &
HA_MUST_USE_TABLE_CONDITION_PUSHDOWN)) &&
pushed_cond)
{ {
extra.append(STRING_WITH_LEN("; Using where with pushed " extra.append(STRING_WITH_LEN("; Using where with pushed "
"condition")); "condition"));
......
This diff is collapsed.
// //
// $Id: ha_sphinx.h 1428 2008-09-05 18:06:30Z xale $ // $Id: ha_sphinx.h 2921 2011-08-21 21:35:02Z tomat $
// //
#ifdef USE_PRAGMA_INTERFACE #ifdef USE_PRAGMA_INTERFACE
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#endif #endif
#if MYSQL_VERSION_ID>50100 #if MYSQL_VERSION_ID>=50515
#define TABLE_ARG TABLE_SHARE #define TABLE_ARG TABLE_SHARE
#elif MYSQL_VERSION_ID>50100
#define TABLE_ARG st_table_share
#else #else
#define TABLE_ARG st_table #define TABLE_ARG st_table
#endif #endif
...@@ -18,7 +20,6 @@ ...@@ -18,7 +20,6 @@
typedef uchar byte; typedef uchar byte;
#endif #endif
#include "handler.h"
/// forward decls /// forward decls
class THD; class THD;
...@@ -48,18 +49,19 @@ protected: ...@@ -48,18 +49,19 @@ protected:
public: public:
#if MYSQL_VERSION_ID<50100 #if MYSQL_VERSION_ID<50100
ha_sphinx ( TABLE_ARG * table_arg ); ha_sphinx ( TABLE_ARG * table_arg ); // NOLINT
#else #else
ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg ); ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg );
#endif #endif
~ha_sphinx () {} ~ha_sphinx ();
const char * table_type () const { return "SPHINX"; } ///< SE name for display purposes const char * table_type () const { return "SPHINX"; } ///< SE name for display purposes
const char * index_type ( uint ) { return "HASH"; } ///< index type name for display purposes const char * index_type ( uint ) { return "HASH"; } ///< index type name for display purposes
const char ** bas_ext () const; ///< my file extensions const char ** bas_ext () const; ///< my file extensions
#if MYSQL_VERSION_ID>50100 #if MYSQL_VERSION_ID>50100
ulonglong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info) ulonglong table_flags () const { return HA_CAN_INDEX_BLOBS |
HA_MUST_USE_TABLE_CONDITION_PUSHDOWN; } ///< bitmap of implemented flags (see handler.h for more info)
#else #else
ulong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info) ulong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info)
#endif #endif
...@@ -77,21 +79,22 @@ public: ...@@ -77,21 +79,22 @@ public:
virtual double scan_time () { return (double)( records+deleted )/20.0 + 10; } ///< called in test_quick_select to determine if indexes should be used virtual double scan_time () { return (double)( records+deleted )/20.0 + 10; } ///< called in test_quick_select to determine if indexes should be used
#endif #endif
virtual double read_time(uint index, uint ranges, ha_rows rows) virtual double read_time(uint index, uint ranges, ha_rows rows)
{ return (double)rows/20.0 + 1; } ///< index read time estimate { return ranges + (double)rows/20.0 + 1; } ///< index read time estimate
public: public:
int open ( const char * name, int mode, uint test_if_locked ); int open ( const char * name, int mode, uint test_if_locked );
int close (); int close ();
int write_row ( uchar * buf ); int write_row ( byte * buf );
int update_row ( const uchar * old_data, uchar * new_data ); int update_row ( const byte * old_data, byte * new_data );
int delete_row ( const uchar * buf ); int delete_row ( const byte * buf );
int extra ( enum ha_extra_function op );
int index_init ( uint keynr, bool sorted ); // 5.1.x int index_init ( uint keynr, bool sorted ); // 5.1.x
int index_init ( uint keynr ) { return index_init ( keynr, false ); } // 5.0.x int index_init ( uint keynr ) { return index_init ( keynr, false ); } // 5.0.x
int index_end (); int index_end ();
int index_read ( byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag ); int index_read ( byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag );
int index_read_idx ( byte * buf, uint idx, const byte * key, uint key_len, enum ha_rkey_function find_flag ); int index_read_idx ( byte * buf, uint idx, const byte * key, uint key_len, enum ha_rkey_function find_flag );
int index_next ( byte * buf ); int index_next ( byte * buf );
...@@ -123,7 +126,7 @@ public: ...@@ -123,7 +126,7 @@ public:
int rename_table ( const char * from, const char * to ); int rename_table ( const char * from, const char * to );
int create ( const char * name, TABLE * form, HA_CREATE_INFO * create_info ); int create ( const char * name, TABLE * form, HA_CREATE_INFO * create_info );
THR_LOCK_DATA **store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type ); THR_LOCK_DATA ** store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type );
public: public:
virtual const COND * cond_push ( const COND *cond ); virtual const COND * cond_push ( const COND *cond );
...@@ -140,12 +143,15 @@ private: ...@@ -140,12 +143,15 @@ private:
int * m_dUnboundFields; int * m_dUnboundFields;
private: private:
int ConnectToSearchd ( const char * sQueryHost, int iQueryPort ); int Connect ( const char * sQueryHost, ushort uPort );
int ConnectAPI ( const char * sQueryHost, int iQueryPort );
int HandleMysqlError ( struct st_mysql * pConn, int iErrCode );
uint32 UnpackDword (); uint32 UnpackDword ();
char * UnpackString (); char * UnpackString ();
bool UnpackSchema (); bool UnpackSchema ();
bool UnpackStats ( CSphSEStats * pStats ); bool UnpackStats ( CSphSEStats * pStats );
bool CheckResponcePtr ( int iLen );
CSphSEThreadData * GetTls (); CSphSEThreadData * GetTls ();
}; };
...@@ -155,6 +161,12 @@ private: ...@@ -155,6 +161,12 @@ private:
bool sphinx_show_status ( THD * thd ); bool sphinx_show_status ( THD * thd );
#endif #endif
int sphinx_showfunc_total_found ( THD *, SHOW_VAR *, char * );
int sphinx_showfunc_total ( THD *, SHOW_VAR *, char * );
int sphinx_showfunc_time ( THD *, SHOW_VAR *, char * );
int sphinx_showfunc_word_count ( THD *, SHOW_VAR *, char * );
int sphinx_showfunc_words ( THD *, SHOW_VAR *, char * );
// //
// $Id: ha_sphinx.h 1428 2008-09-05 18:06:30Z xale $ // $Id: ha_sphinx.h 2921 2011-08-21 21:35:02Z tomat $
// //
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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