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"));
......
// //
// $Id: ha_sphinx.cc 2058 2009-11-07 04:01:57Z shodan $ // $Id: ha_sphinx.cc 3133 2012-03-01 13:47:52Z shodan $
//
//
// Copyright (c) 2001-2012, Andrew Aksyonoff
// Copyright (c) 2008-2012, Sphinx Technologies Inc
// 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. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
// //
#ifdef USE_PRAGMA_IMPLEMENTATION #ifdef USE_PRAGMA_IMPLEMENTATION
...@@ -13,7 +24,11 @@ ...@@ -13,7 +24,11 @@
#include <mysql_version.h> #include <mysql_version.h>
#if MYSQL_VERSION_ID>50100 #if MYSQL_VERSION_ID>=50515
#include "sql_class.h"
#include "sql_array.h"
#elif MYSQL_VERSION_ID>50100
#include "mysql_priv.h"
#include <mysql/plugin.h> #include <mysql/plugin.h>
#else #else
#include "../mysql_priv.h" #include "../mysql_priv.h"
...@@ -21,15 +36,11 @@ ...@@ -21,15 +36,11 @@
#include <mysys_err.h> #include <mysys_err.h>
#include <my_sys.h> #include <my_sys.h>
#include "sql_array.h" #include <mysql.h> // include client for INSERT table (sort of redoing federated..)
#include "table.h"
#include "field.h"
#include "item.h"
#include <mysqld_error.h>
#include <my_net.h>
#ifndef __WIN__ #ifndef __WIN__
// UNIX-specific // UNIX-specific
#include <my_net.h>
#include <netdb.h> #include <netdb.h>
#include <sys/un.h> #include <sys/un.h>
...@@ -39,6 +50,8 @@ ...@@ -39,6 +50,8 @@
#else #else
// Windows-specific // Windows-specific
#include <io.h> #include <io.h>
#define strcasecmp stricmp
#define snprintf _snprintf
#define RECV_FLAGS 0 #define RECV_FLAGS 0
...@@ -68,10 +81,6 @@ ...@@ -68,10 +81,6 @@
#define UNALIGNED_RAM_ACCESS 1 #define UNALIGNED_RAM_ACCESS 1
#endif #endif
#if MYSQL_VERSION_ID<50100
#define thd_ha_data(X,Y) (X)->ha_data[sphinx_hton.slot]
#define ha_thd() current_thd
#endif // <50100
#if UNALIGNED_RAM_ACCESS #if UNALIGNED_RAM_ACCESS
...@@ -113,28 +122,48 @@ void sphUnalignedWrite ( void * pPtr, const T & tVal ) ...@@ -113,28 +122,48 @@ void sphUnalignedWrite ( void * pPtr, const T & tVal )
#endif #endif
#if MYSQL_VERSION_ID>=50515
#define sphinx_hash_init my_hash_init
#define sphinx_hash_free my_hash_free
#define sphinx_hash_search my_hash_search
#define sphinx_hash_delete my_hash_delete
#else
#define sphinx_hash_init hash_init
#define sphinx_hash_free hash_free
#define sphinx_hash_search hash_search
#define sphinx_hash_delete hash_delete
#endif
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// FIXME! make this all dynamic // FIXME! make this all dynamic
#define SPHINXSE_MAX_FILTERS 32 #define SPHINXSE_MAX_FILTERS 32
#define SPHINXSE_DEFAULT_HOST "127.0.0.1" #define SPHINXAPI_DEFAULT_HOST "127.0.0.1"
#define SPHINXSE_DEFAULT_PORT 9312 #define SPHINXAPI_DEFAULT_PORT 9312
#define SPHINXSE_DEFAULT_INDEX "*" #define SPHINXAPI_DEFAULT_INDEX "*"
#define SPHINXQL_DEFAULT_PORT 9306
#define SPHINXSE_SYSTEM_COLUMNS 3 #define SPHINXSE_SYSTEM_COLUMNS 3
#define SPHINXSE_MAX_ALLOC (16*1024*1024) #define SPHINXSE_MAX_ALLOC (16*1024*1024)
#define SPHINXSE_MAX_KEYWORDSTATS 4096 #define SPHINXSE_MAX_KEYWORDSTATS 4096
// FIXME! all the following is cut-n-paste from sphinx.h and searchd.cpp #define SPHINXSE_VERSION "2.0.4-release"
#define SPHINX_VERSION "0.9.9"
// FIXME? the following is cut-n-paste from sphinx.h and searchd.cpp
// cut-n-paste is somewhat simpler that adding dependencies however..
enum enum
{ {
SPHINX_SEARCHD_PROTO = 1, SPHINX_SEARCHD_PROTO = 1,
SEARCHD_COMMAND_SEARCH = 0, SEARCHD_COMMAND_SEARCH = 0,
VER_COMMAND_SEARCH = 0x116, VER_COMMAND_SEARCH = 0x119,
}; };
/// search query sorting orders /// search query sorting orders
...@@ -174,6 +203,8 @@ enum ESphRankMode ...@@ -174,6 +203,8 @@ enum ESphRankMode
SPH_RANK_PROXIMITY = 4, ///< phrase proximity SPH_RANK_PROXIMITY = 4, ///< phrase proximity
SPH_RANK_MATCHANY = 5, ///< emulate old match-any weighting SPH_RANK_MATCHANY = 5, ///< emulate old match-any weighting
SPH_RANK_FIELDMASK = 6, ///< sets bits where there were matches SPH_RANK_FIELDMASK = 6, ///< sets bits where there were matches
SPH_RANK_SPH04 = 7, ///< codename SPH04, phrase proximity + bm25 + head/exact boost
SPH_RANK_EXPR = 8, ///< expression based ranker
SPH_RANK_TOTAL, SPH_RANK_TOTAL,
SPH_RANK_DEFAULT = SPH_RANK_PROXIMITY_BM25 SPH_RANK_DEFAULT = SPH_RANK_PROXIMITY_BM25
...@@ -199,8 +230,10 @@ enum ...@@ -199,8 +230,10 @@ enum
SPH_ATTR_BOOL = 4, ///< this attr is a boolean bit field SPH_ATTR_BOOL = 4, ///< this attr is a boolean bit field
SPH_ATTR_FLOAT = 5, SPH_ATTR_FLOAT = 5,
SPH_ATTR_BIGINT = 6, SPH_ATTR_BIGINT = 6,
SPH_ATTR_STRING = 7, ///< string (binary; in-memory)
SPH_ATTR_MULTI = 0x40000000UL ///< this attr has multiple values (0 or more) SPH_ATTR_UINT32SET = 0x40000001UL, ///< this attr is multiple int32 values (0 or more)
SPH_ATTR_UINT64SET = 0x40000002UL ///< this attr is multiple int64 values (0 or more)
}; };
/// known answers /// known answers
...@@ -250,23 +283,24 @@ inline void SPH_DEBUG ( const char *, ... ) {} ...@@ -250,23 +283,24 @@ inline void SPH_DEBUG ( const char *, ... ) {}
#endif #endif
#define SafeDelete(_arg) { if ( _arg ) delete ( _arg ); (_arg) = NULL; } #define SafeDelete(_arg) { delete ( _arg ); (_arg) = NULL; }
#define SafeDeleteArray(_arg) { if ( _arg ) delete [] ( _arg ); (_arg) = NULL; } #define SafeDeleteArray(_arg) { if ( _arg ) { delete [] ( _arg ); (_arg) = NULL; } }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// a structure that will be shared among all open Sphinx SE handlers /// per-table structure that will be shared among all open Sphinx SE handlers
struct CSphSEShare struct CSphSEShare
{ {
pthread_mutex_t m_tMutex; pthread_mutex_t m_tMutex;
THR_LOCK m_tLock; THR_LOCK m_tLock;
char * m_sTable; char * m_sTable;
char * m_sScheme; char * m_sScheme; ///< our connection string
char * m_sHost; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY char * m_sHost; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
char * m_sSocket; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY char * m_sSocket; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
char * m_sIndex; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY char * m_sIndex; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
ushort m_iPort; ushort m_iPort;
bool m_bSphinxQL; ///< is this read-only SphinxAPI table, or write-only SphinxQL table?
uint m_iTableNameLen; uint m_iTableNameLen;
uint m_iUseCount; uint m_iUseCount;
CHARSET_INFO * m_pTableQueryCharset; CHARSET_INFO * m_pTableQueryCharset;
...@@ -282,6 +316,7 @@ struct CSphSEShare ...@@ -282,6 +316,7 @@ struct CSphSEShare
, m_sSocket ( NULL ) , m_sSocket ( NULL )
, m_sIndex ( NULL ) , m_sIndex ( NULL )
, m_iPort ( 0 ) , m_iPort ( 0 )
, m_bSphinxQL ( false )
, m_iTableNameLen ( 0 ) , m_iTableNameLen ( 0 )
, m_iUseCount ( 1 ) , m_iUseCount ( 1 )
, m_pTableQueryCharset ( NULL ) , m_pTableQueryCharset ( NULL )
...@@ -375,14 +410,14 @@ struct CSphSEStats ...@@ -375,14 +410,14 @@ struct CSphSEStats
m_iMatchesFound = 0; m_iMatchesFound = 0;
m_iQueryMsec = 0; m_iQueryMsec = 0;
m_iWords = 0; m_iWords = 0;
SafeDeleteArray ( m_dWords );
m_bLastError = false; m_bLastError = false;
m_sLastMessage[0] = '\0'; m_sLastMessage[0] = '\0';
SafeDeleteArray ( m_dWords );
} }
~CSphSEStats() ~CSphSEStats()
{ {
Reset (); SafeDeleteArray ( m_dWords );
} }
}; };
...@@ -399,10 +434,20 @@ struct CSphSEThreadData ...@@ -399,10 +434,20 @@ struct CSphSEThreadData
CHARSET_INFO * m_pQueryCharset; CHARSET_INFO * m_pQueryCharset;
bool m_bReplace; ///< are we doing an INSERT or REPLACE
bool m_bCondId; ///< got a value from condition pushdown
longlong m_iCondId; ///< value acquired from id=value condition pushdown
bool m_bCondDone; ///< index_read() is now over
CSphSEThreadData () CSphSEThreadData ()
: m_bStats ( false ) : m_bStats ( false )
, m_bQuery ( false ) , m_bQuery ( false )
, m_pQueryCharset ( NULL ) , m_pQueryCharset ( NULL )
, m_bReplace ( false )
, m_bCondId ( false )
, m_iCondId ( 0 )
, m_bCondDone ( false )
{} {}
}; };
...@@ -472,13 +517,14 @@ struct CSphSEQuery ...@@ -472,13 +517,14 @@ struct CSphSEQuery
int m_iLimit; int m_iLimit;
bool m_bQuery; bool m_bQuery;
char * m_sQuery; const char * m_sQuery;
uint32 * m_pWeights; uint32 * m_pWeights;
int m_iWeights; int m_iWeights;
ESphMatchMode m_eMode; ESphMatchMode m_eMode;
ESphRankMode m_eRanker; ESphRankMode m_eRanker;
const char * m_sRankExpr;
ESphSortOrder m_eSort; ESphSortOrder m_eSort;
char * m_sSortBy; const char * m_sSortBy;
int m_iMaxMatches; int m_iMaxMatches;
int m_iMaxQueryTime; int m_iMaxQueryTime;
uint32 m_iMinID; uint32 m_iMinID;
...@@ -488,12 +534,12 @@ struct CSphSEQuery ...@@ -488,12 +534,12 @@ struct CSphSEQuery
CSphSEFilter m_dFilters[SPHINXSE_MAX_FILTERS]; CSphSEFilter m_dFilters[SPHINXSE_MAX_FILTERS];
ESphGroupBy m_eGroupFunc; ESphGroupBy m_eGroupFunc;
char * m_sGroupBy; const char * m_sGroupBy;
char * m_sGroupSortBy; const char * m_sGroupSortBy;
int m_iCutoff; int m_iCutoff;
int m_iRetryCount; int m_iRetryCount;
int m_iRetryDelay; int m_iRetryDelay;
char * m_sGroupDistinct; ///< points to query buffer; do NOT delete const char * m_sGroupDistinct; ///< points to query buffer; do NOT delete
int m_iIndexWeights; int m_iIndexWeights;
char * m_sIndexWeight[SPHINXSE_MAX_FILTERS]; ///< points to query buffer; do NOT delete char * m_sIndexWeight[SPHINXSE_MAX_FILTERS]; ///< points to query buffer; do NOT delete
int m_iIndexWeight[SPHINXSE_MAX_FILTERS]; int m_iIndexWeight[SPHINXSE_MAX_FILTERS];
...@@ -502,12 +548,13 @@ struct CSphSEQuery ...@@ -502,12 +548,13 @@ struct CSphSEQuery
int m_iFieldWeight[SPHINXSE_MAX_FILTERS]; int m_iFieldWeight[SPHINXSE_MAX_FILTERS];
bool m_bGeoAnchor; bool m_bGeoAnchor;
char * m_sGeoLatAttr; const char * m_sGeoLatAttr;
char * m_sGeoLongAttr; const char * m_sGeoLongAttr;
float m_fGeoLatitude; float m_fGeoLatitude;
float m_fGeoLongitude; float m_fGeoLongitude;
char * m_sComment; const char * m_sComment;
const char * m_sSelect;
struct Override_t struct Override_t
{ {
...@@ -544,10 +591,10 @@ struct CSphSEQuery ...@@ -544,10 +591,10 @@ struct CSphSEQuery
bool ParseField ( char * sField ); bool ParseField ( char * sField );
void SendBytes ( const void * pBytes, int iBytes ); void SendBytes ( const void * pBytes, int iBytes );
void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(short int) ); } void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(v) ); }
void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(int) ); } void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(v) ); }
void SendDword ( uint v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(uint) ); } void SendDword ( uint v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(v) ); }
void SendUint64 ( ulonglong v ) { SendDword ( uint(v>>32) ); SendDword ( uint(v&0xFFFFFFFFUL) ); } void SendUint64 ( ulonglong v ) { SendDword ( (uint)(v>>32) ); SendDword ( (uint)(v&0xFFFFFFFFUL) ); }
void SendString ( const char * v ) { int iLen = strlen(v); SendDword(iLen); SendBytes ( v, iLen ); } void SendString ( const char * v ) { int iLen = strlen(v); SendDword(iLen); SendBytes ( v, iLen ); }
void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); } void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); }
}; };
...@@ -580,7 +627,7 @@ bool sphinx_show_status ( THD * thd ); ...@@ -580,7 +627,7 @@ bool sphinx_show_status ( THD * thd );
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
static const char sphinx_hton_name[] = "SPHINX"; static const char sphinx_hton_name[] = "SPHINX";
static const char sphinx_hton_comment[] = "Sphinx storage engine " SPHINX_VERSION; static const char sphinx_hton_comment[] = "Sphinx storage engine " SPHINXSE_VERSION;
#if MYSQL_VERSION_ID<50100 #if MYSQL_VERSION_ID<50100
handlerton sphinx_hton = handlerton sphinx_hton =
...@@ -649,20 +696,19 @@ static int sphinx_init_func ( void * p ) ...@@ -649,20 +696,19 @@ static int sphinx_init_func ( void * p )
if ( !sphinx_init ) if ( !sphinx_init )
{ {
sphinx_init = 1; sphinx_init = 1;
pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ); void ( pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ) );
my_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0, sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0,
sphinx_get_key, 0, 0 ); sphinx_get_key, 0, 0 );
#if MYSQL_VERSION_ID > 50100 #if MYSQL_VERSION_ID > 50100
handlerton * hton = (handlerton*) p; handlerton * hton = (handlerton*) p;
hton->state = SHOW_OPTION_YES; hton->state = SHOW_OPTION_YES;
hton->db_type = DB_TYPE_AUTOASSIGN; hton->db_type = DB_TYPE_FIRST_DYNAMIC;
hton->create = sphinx_create_handler; hton->create = sphinx_create_handler;
hton->close_connection = sphinx_close_connection; hton->close_connection = sphinx_close_connection;
hton->show_status = sphinx_show_status; hton->show_status = sphinx_show_status;
hton->panic = sphinx_panic; hton->panic = sphinx_panic;
hton->flags = HTON_CAN_RECREATE; hton->flags = HTON_CAN_RECREATE;
sphinx_hton_ptr = hton;
#endif #endif
} }
SPH_RET(0); SPH_RET(0);
...@@ -695,17 +741,18 @@ static int sphinx_done_func ( void * ) ...@@ -695,17 +741,18 @@ static int sphinx_done_func ( void * )
{ {
SPH_ENTER_FUNC(); SPH_ENTER_FUNC();
int error = 0;
if ( sphinx_init ) if ( sphinx_init )
{ {
sphinx_init = 0; sphinx_init = 0;
#ifdef NOT_USED
if ( sphinx_open_tables.records ) if ( sphinx_open_tables.records )
error = 1; error = 1;
my_hash_free ( &sphinx_open_tables ); #endif
sphinx_hash_free ( &sphinx_open_tables );
pthread_mutex_destroy ( &sphinx_mutex ); pthread_mutex_destroy ( &sphinx_mutex );
} }
SPH_RET(error); SPH_RET(0);
} }
...@@ -749,15 +796,22 @@ bool sphinx_show_status ( THD * thd ) ...@@ -749,15 +796,22 @@ bool sphinx_show_status ( THD * thd )
char buf1[IO_SIZE]; char buf1[IO_SIZE];
uint buf1len; uint buf1len;
char buf2[IO_SIZE]; char buf2[IO_SIZE];
uint buf2len= 0; uint buf2len = 0;
String words; String words;
buf1[0] = '\0'; buf1[0] = '\0';
buf2[0] = '\0'; buf2[0] = '\0';
#if MYSQL_VERSION_ID>50100 #if MYSQL_VERSION_ID>50100
// 5.1.x style stats
CSphSEThreadData * pTls = (CSphSEThreadData*) ( *thd_ha_data ( thd, hton ) ); CSphSEThreadData * pTls = (CSphSEThreadData*) ( *thd_ha_data ( thd, hton ) );
#define LOC_STATS(_key,_keylen,_val,_vallen) \
stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name), _key, _keylen, _val, _vallen );
#else #else
// 5.0.x style stats
if ( have_sphinx_db!=SHOW_OPTION_YES ) if ( have_sphinx_db!=SHOW_OPTION_YES )
{ {
my_message ( ER_NOT_SUPPORTED_YET, my_message ( ER_NOT_SUPPORTED_YET,
...@@ -766,8 +820,25 @@ bool sphinx_show_status ( THD * thd ) ...@@ -766,8 +820,25 @@ bool sphinx_show_status ( THD * thd )
SPH_RET(TRUE); SPH_RET(TRUE);
} }
CSphSEThreadData * pTls = (CSphSEThreadData*) thd->ha_data[sphinx_hton.slot]; CSphSEThreadData * pTls = (CSphSEThreadData*) thd->ha_data[sphinx_hton.slot];
field_list.push_back ( new Item_empty_string ( "Type", 10 ) );
field_list.push_back ( new Item_empty_string ( "Name", FN_REFLEN ) );
field_list.push_back ( new Item_empty_string ( "Status", 10 ) );
if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
SPH_RET(TRUE);
#define LOC_STATS(_key,_keylen,_val,_vallen) \
protocol->prepare_for_resend (); \
protocol->store ( "SPHINX", 6, system_charset_info ); \
protocol->store ( _key, _keylen, system_charset_info ); \
protocol->store ( _val, _vallen, system_charset_info ); \
if ( protocol->write() ) \
SPH_RET(TRUE);
#endif #endif
// show query stats
if ( pTls && pTls->m_bStats ) if ( pTls && pTls->m_bStats )
{ {
const CSphSEStats * pStats = &pTls->m_tStats; const CSphSEStats * pStats = &pTls->m_tStats;
...@@ -775,23 +846,7 @@ bool sphinx_show_status ( THD * thd ) ...@@ -775,23 +846,7 @@ bool sphinx_show_status ( THD * thd )
"total: %d, total found: %d, time: %d, words: %d", "total: %d, total found: %d, time: %d, words: %d",
pStats->m_iMatchesTotal, pStats->m_iMatchesFound, pStats->m_iQueryMsec, pStats->m_iWords ); pStats->m_iMatchesTotal, pStats->m_iMatchesFound, pStats->m_iQueryMsec, pStats->m_iWords );
#if MYSQL_VERSION_ID>50100 LOC_STATS ( "stats", 5, buf1, buf1len );
stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name),
STRING_WITH_LEN("stats"), buf1, buf1len );
#else
field_list.push_back ( new Item_empty_string ( "Type",10 ) );
field_list.push_back ( new Item_empty_string ( "Name",FN_REFLEN ) );
field_list.push_back ( new Item_empty_string ( "Status",10 ) );
if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
SPH_RET(TRUE);
protocol->prepare_for_resend ();
protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
protocol->store ( STRING_WITH_LEN("stats"), system_charset_info );
protocol->store ( buf1, buf1len, system_charset_info );
if ( protocol->write() )
SPH_RET(TRUE);
#endif
if ( pStats->m_iWords ) if ( pStats->m_iWords )
{ {
...@@ -815,58 +870,30 @@ bool sphinx_show_status ( THD * thd ) ...@@ -815,58 +870,30 @@ bool sphinx_show_status ( THD * thd )
iWord = sBuf3.length(); iWord = sBuf3.length();
} }
#if MYSQL_VERSION_ID>50100 LOC_STATS ( "words", 5, sWord, iWord );
stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name), }
STRING_WITH_LEN("words"), sWord, iWord );
#else
protocol->prepare_for_resend ();
protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
protocol->store ( STRING_WITH_LEN("words"), system_charset_info );
protocol->store ( sWord, iWord, system_charset_info );
if ( protocol->write() )
SPH_RET(TRUE);
#endif
} }
// send last error or warning // show last error or warning (either in addition to stats, or on their own)
if ( pStats->m_sLastMessage && pStats->m_sLastMessage[0] ) if ( pTls && pTls->m_tStats.m_sLastMessage && pTls->m_tStats.m_sLastMessage[0] )
{ {
const char * sMessageType = pStats->m_bLastError ? "error" : "warning"; const char * sMessageType = pTls->m_tStats.m_bLastError ? "error" : "warning";
#if MYSQL_VERSION_ID>50100 LOC_STATS (
stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name), sMessageType, strlen ( sMessageType ),
sMessageType, strlen(sMessageType), pStats->m_sLastMessage, strlen(pStats->m_sLastMessage) ); pTls->m_tStats.m_sLastMessage, strlen ( pTls->m_tStats.m_sLastMessage ) );
#else
protocol->prepare_for_resend ();
protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
protocol->store ( sMessageType, strlen(sMessageType), system_charset_info );
protocol->store ( pStats->m_sLastMessage, strlen(pStats->m_sLastMessage), system_charset_info );
if ( protocol->write() )
SPH_RET(TRUE);
#endif
}
} else } else
{ {
#if MYSQL_VERSION_ID < 50100 // well, nothing to show just yet
field_list.push_back ( new Item_empty_string ( "Type", 10 ) ); #if MYSQL_VERSION_ID < 50100
field_list.push_back ( new Item_empty_string ( "Name", FN_REFLEN ) ); LOC_STATS ( "stats", 5, "no query has been executed yet", sizeof("no query has been executed yet")-1 );
field_list.push_back ( new Item_empty_string ( "Status", 10 ) ); #endif
if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
SPH_RET(TRUE);
protocol->prepare_for_resend ();
protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
protocol->store ( STRING_WITH_LEN("stats"), system_charset_info );
protocol->store ( STRING_WITH_LEN("no query has been executed yet"), system_charset_info );
if ( protocol->write() )
SPH_RET(TRUE);
#endif
} }
#if MYSQL_VERSION_ID < 50100 #if MYSQL_VERSION_ID < 50100
send_eof(thd); send_eof(thd);
#endif #endif
SPH_RET(FALSE); SPH_RET(FALSE);
} }
...@@ -933,10 +960,9 @@ static void sphLogError ( const char * sFmt, ... ) ...@@ -933,10 +960,9 @@ static void sphLogError ( const char * sFmt, ... )
// the following scheme variants are recognized // the following scheme variants are recognized
// //
// sphinx://host/index // sphinx://host[:port]/index
// sphinx://host:port/index // sphinxql://host[:port]/index
// unix://unix/domain/socket:index // unix://unix/domain/socket[:index]
// unix://unix/domain/socket
static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate ) static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
{ {
SPH_ENTER_FUNC(); SPH_ENTER_FUNC();
...@@ -973,43 +999,54 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate ) ...@@ -973,43 +999,54 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
} }
} }
// defaults
bool bOk = true;
bool bQL = false;
char * sScheme = NULL; char * sScheme = NULL;
char * sHost = (char*) SPHINXSE_DEFAULT_HOST; char * sHost = (char*) SPHINXAPI_DEFAULT_HOST;
char * sIndex = (char*) SPHINXSE_DEFAULT_INDEX; char * sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
int iPort = SPHINXSE_DEFAULT_PORT; int iPort = SPHINXAPI_DEFAULT_PORT;
bool bOk = true; // parse connection string, if any
while ( table->s->connect_string.length!=0 ) while ( table->s->connect_string.length!=0 )
{ {
bOk = false;
sScheme = sphDup ( table->s->connect_string.str, table->s->connect_string.length ); sScheme = sphDup ( table->s->connect_string.str, table->s->connect_string.length );
sHost = strstr ( sScheme, "://" ); sHost = strstr ( sScheme, "://" );
if ( !sHost ) if ( !sHost )
{
bOk = false;
break; break;
}
sHost[0] = '\0'; sHost[0] = '\0';
sHost += 2; sHost += 3;
/////////////////////////////
// sphinxapi via unix socket
/////////////////////////////
if ( !strcmp ( sScheme, "unix" ) ) if ( !strcmp ( sScheme, "unix" ) )
{ {
// unix-domain socket sHost--; // reuse last slash
iPort = 0; iPort = 0;
if (!( sIndex = strrchr ( sHost, ':' ) )) if (!( sIndex = strrchr ( sHost, ':' ) ))
sIndex = (char*) SPHINXSE_DEFAULT_INDEX; sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
else else
{ {
*sIndex++ = '\0'; *sIndex++ = '\0';
if ( !*sIndex ) if ( !*sIndex )
sIndex = (char*) SPHINXSE_DEFAULT_INDEX; sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
} }
bOk = true; bOk = true;
break; break;
} }
if( strcmp ( sScheme, "sphinx" )!=0 && strcmp ( sScheme, "inet" )!=0 )
break;
// tcp /////////////////////
sHost++; // sphinxapi via tcp
/////////////////////
if ( !strcmp ( sScheme, "sphinx" ) )
{
char * sPort = strchr ( sHost, ':' ); char * sPort = strchr ( sHost, ':' );
if ( sPort ) if ( sPort )
{ {
...@@ -1020,11 +1057,11 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate ) ...@@ -1020,11 +1057,11 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
if ( sIndex ) if ( sIndex )
*sIndex++ = '\0'; *sIndex++ = '\0';
else else
sIndex = (char*) SPHINXSE_DEFAULT_INDEX; sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
iPort = atoi(sPort); iPort = atoi(sPort);
if ( !iPort ) if ( !iPort )
iPort = SPHINXSE_DEFAULT_PORT; iPort = SPHINXAPI_DEFAULT_PORT;
} }
} else } else
{ {
...@@ -1032,13 +1069,54 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate ) ...@@ -1032,13 +1069,54 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
if ( sIndex ) if ( sIndex )
*sIndex++ = '\0'; *sIndex++ = '\0';
else else
sIndex = (char*) SPHINXSE_DEFAULT_INDEX; sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
} }
bOk = true; bOk = true;
break; break;
} }
////////////
// sphinxql
////////////
if ( !strcmp ( sScheme, "sphinxql" ) )
{
bQL = true;
iPort = SPHINXQL_DEFAULT_PORT;
// handle port
char * sPort = strchr ( sHost, ':' );
sIndex = sHost; // starting point for index name search
if ( sPort )
{
*sPort++ = '\0';
sIndex = sPort;
iPort = atoi(sPort);
if ( !iPort )
{
bOk = false; // invalid port; can report ER_FOREIGN_DATA_STRING_INVALID
break;
}
}
// find index
sIndex = strchr ( sIndex, '/' );
if ( sIndex )
*sIndex++ = '\0';
// final checks
// host and index names are required
bOk = ( sHost && *sHost && sIndex && *sIndex );
break;
}
// unknown case
bOk = false;
break;
}
if ( !bOk ) if ( !bOk )
{ {
my_error ( bCreate ? ER_FOREIGN_DATA_STRING_INVALID_CANT_CREATE : ER_FOREIGN_DATA_STRING_INVALID, my_error ( bCreate ? ER_FOREIGN_DATA_STRING_INVALID_CANT_CREATE : ER_FOREIGN_DATA_STRING_INVALID,
...@@ -1052,6 +1130,7 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate ) ...@@ -1052,6 +1130,7 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
share->m_sHost = sHost; share->m_sHost = sHost;
share->m_sIndex = sIndex; share->m_sIndex = sIndex;
share->m_iPort = (ushort)iPort; share->m_iPort = (ushort)iPort;
share->m_bSphinxQL = bQL;
} }
} }
if ( !bOk && !share ) if ( !bOk && !share )
...@@ -1074,12 +1153,12 @@ static CSphSEShare * get_share ( const char * table_name, TABLE * table ) ...@@ -1074,12 +1153,12 @@ static CSphSEShare * get_share ( const char * table_name, TABLE * table )
{ {
// check if we already have this share // check if we already have this share
#if MYSQL_VERSION_ID>=50120 #if MYSQL_VERSION_ID>=50120
pShare = (CSphSEShare*) my_hash_search ( &sphinx_open_tables, (const uchar *) table_name, strlen(table_name) ); pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, (const uchar *) table_name, strlen(table_name) );
#else #else
#ifdef __WIN__ #ifdef __WIN__
pShare = (CSphSEShare*) my_hash_search ( &sphinx_open_tables, (const byte *) table_name, strlen(table_name) ); pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, (const byte *) table_name, strlen(table_name) );
#else #else
pShare = (CSphSEShare*) my_hash_search ( &sphinx_open_tables, table_name, strlen(table_name) ); pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, table_name, strlen(table_name) );
#endif // win #endif // win
#endif // pre-5.1.20 #endif // pre-5.1.20
...@@ -1095,13 +1174,15 @@ static CSphSEShare * get_share ( const char * table_name, TABLE * table ) ...@@ -1095,13 +1174,15 @@ static CSphSEShare * get_share ( const char * table_name, TABLE * table )
break; break;
// try to setup it // try to setup it
pShare->m_pTableQueryCharset = table->field[2]->charset();
if ( !ParseUrl ( pShare, table, false ) ) if ( !ParseUrl ( pShare, table, false ) )
{ {
SafeDelete ( pShare ); SafeDelete ( pShare );
break; break;
} }
if ( !pShare->m_bSphinxQL )
pShare->m_pTableQueryCharset = table->field[2]->charset();
// try to hash it // try to hash it
pShare->m_iTableNameLen = strlen(table_name); pShare->m_iTableNameLen = strlen(table_name);
pShare->m_sTable = sphDup ( table_name ); pShare->m_sTable = sphDup ( table_name );
...@@ -1129,7 +1210,7 @@ static int free_share ( CSphSEShare * pShare ) ...@@ -1129,7 +1210,7 @@ static int free_share ( CSphSEShare * pShare )
if ( !--pShare->m_iUseCount ) if ( !--pShare->m_iUseCount )
{ {
my_hash_delete ( &sphinx_open_tables, (byte *)pShare ); sphinx_hash_delete ( &sphinx_open_tables, (byte *)pShare );
SafeDelete ( pShare ); SafeDelete ( pShare );
} }
...@@ -1141,6 +1222,7 @@ static int free_share ( CSphSEShare * pShare ) ...@@ -1141,6 +1222,7 @@ static int free_share ( CSphSEShare * pShare )
#if MYSQL_VERSION_ID>50100 #if MYSQL_VERSION_ID>50100
static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table, MEM_ROOT * mem_root ) static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table, MEM_ROOT * mem_root )
{ {
sphinx_hton_ptr = hton;
return new ( mem_root ) ha_sphinx ( hton, table ); return new ( mem_root ) ha_sphinx ( hton, table );
} }
#endif #endif
...@@ -1152,37 +1234,39 @@ static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table, ...@@ -1152,37 +1234,39 @@ static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table,
CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex ) CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex )
: m_sHost ( "" ) : m_sHost ( "" )
, m_iPort ( 0 ) , m_iPort ( 0 )
, m_sIndex ( sIndex ? sIndex : (char*) "*" ) , m_sIndex ( sIndex ? sIndex : "*" )
, m_iOffset ( 0 ) , m_iOffset ( 0 )
, m_iLimit ( 20 ) , m_iLimit ( 20 )
, m_bQuery ( false ) , m_bQuery ( false )
, m_sQuery ( (char*) "" ) , m_sQuery ( "" )
, m_pWeights ( NULL ) , m_pWeights ( NULL )
, m_iWeights ( 0 ) , m_iWeights ( 0 )
, m_eMode ( SPH_MATCH_ALL ) , m_eMode ( SPH_MATCH_ALL )
, m_eRanker ( SPH_RANK_PROXIMITY_BM25 ) , m_eRanker ( SPH_RANK_PROXIMITY_BM25 )
, m_sRankExpr ( NULL )
, m_eSort ( SPH_SORT_RELEVANCE ) , m_eSort ( SPH_SORT_RELEVANCE )
, m_sSortBy ( (char*) "" ) , m_sSortBy ( "" )
, m_iMaxMatches ( 1000 ) , m_iMaxMatches ( 1000 )
, m_iMaxQueryTime ( 0 ) , m_iMaxQueryTime ( 0 )
, m_iMinID ( 0 ) , m_iMinID ( 0 )
, m_iMaxID ( 0 ) , m_iMaxID ( 0 )
, m_iFilters ( 0 ) , m_iFilters ( 0 )
, m_eGroupFunc ( SPH_GROUPBY_DAY ) , m_eGroupFunc ( SPH_GROUPBY_DAY )
, m_sGroupBy ( (char*) "" ) , m_sGroupBy ( "" )
, m_sGroupSortBy ( (char*) "@group desc" ) , m_sGroupSortBy ( "@group desc" )
, m_iCutoff ( 0 ) , m_iCutoff ( 0 )
, m_iRetryCount ( 0 ) , m_iRetryCount ( 0 )
, m_iRetryDelay ( 0 ) , m_iRetryDelay ( 0 )
, m_sGroupDistinct ( (char*) "" ) , m_sGroupDistinct ( "" )
, m_iIndexWeights ( 0 ) , m_iIndexWeights ( 0 )
, m_iFieldWeights ( 0 ) , m_iFieldWeights ( 0 )
, m_bGeoAnchor ( false ) , m_bGeoAnchor ( false )
, m_sGeoLatAttr ( (char*) "" ) , m_sGeoLatAttr ( "" )
, m_sGeoLongAttr ( (char*) "" ) , m_sGeoLongAttr ( "" )
, m_fGeoLatitude ( 0.0f ) , m_fGeoLatitude ( 0.0f )
, m_fGeoLongitude ( 0.0f ) , m_fGeoLongitude ( 0.0f )
, m_sComment ( (char*) "" ) , m_sComment ( "" )
, m_sSelect ( "" )
, m_pBuf ( NULL ) , m_pBuf ( NULL )
, m_pCur ( NULL ) , m_pCur ( NULL )
...@@ -1191,8 +1275,8 @@ CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex ...@@ -1191,8 +1275,8 @@ CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex
{ {
m_sQueryBuffer = new char [ iLength+2 ]; m_sQueryBuffer = new char [ iLength+2 ];
memcpy ( m_sQueryBuffer, sQuery, iLength ); memcpy ( m_sQueryBuffer, sQuery, iLength );
m_sQueryBuffer[iLength]= ';'; m_sQueryBuffer[iLength] = ';';
m_sQueryBuffer[iLength+1]= '\0'; m_sQueryBuffer[iLength+1] = '\0';
} }
...@@ -1248,22 +1332,20 @@ int CSphSEQuery::ParseArray ( T ** ppValues, const char * sValue ) ...@@ -1248,22 +1332,20 @@ int CSphSEQuery::ParseArray ( T ** ppValues, const char * sValue )
if ( !bPrevDigit ) if ( !bPrevDigit )
uValue = 0; uValue = 0;
uValue = uValue*10 + ( (*pValue)-'0' ); uValue = uValue*10 + ( (*pValue)-'0' );
} } else if ( bPrevDigit )
else if ( bPrevDigit )
{ {
assert ( iIndex<iValues ); assert ( iIndex<iValues );
pValues [ iIndex++ ] = uValue * iSign; pValues [ iIndex++ ] = uValue * iSign;
iSign = 1; iSign = 1;
} } else if ( *pValue=='-' )
else if ( *pValue=='-' )
iSign = -1; iSign = -1;
bPrevDigit = bDigit;
bPrevDigit = bDigit;
if ( !*pValue ) if ( !*pValue )
break; break;
} }
SPH_RET(iValues); SPH_RET ( iValues );
} }
...@@ -1273,7 +1355,7 @@ static char * chop ( char * s ) ...@@ -1273,7 +1355,7 @@ static char * chop ( char * s )
s++; s++;
char * p = s + strlen(s); char * p = s + strlen(s);
while ( p>s && isspace(p[-1]) ) while ( p>s && isspace ( p[-1] ) )
p--; p--;
*p = '\0'; *p = '\0';
...@@ -1311,11 +1393,13 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1311,11 +1393,13 @@ bool CSphSEQuery::ParseField ( char * sField )
m_sQuery = sField; m_sQuery = sField;
m_bQuery = true; m_bQuery = true;
// unescape // unescape only 1st one
char *s = sField, *d = sField; char *s = sField, *d = sField;
int iSlashes = 0;
while ( *s ) while ( *s )
{ {
if ( *s!='\\' ) *d++ = *s; iSlashes = ( *s=='\\' ) ? iSlashes+1 : 0;
if ( ( iSlashes%2 )==0 ) *d++ = *s;
s++; s++;
} }
*d = '\0'; *d = '\0';
...@@ -1347,20 +1431,20 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1347,20 +1431,20 @@ bool CSphSEQuery::ParseField ( char * sField )
else if ( !strcmp ( sName, "distinct" ) ) m_sGroupDistinct = sValue; else if ( !strcmp ( sName, "distinct" ) ) m_sGroupDistinct = sValue;
else if ( !strcmp ( sName, "cutoff" ) ) m_iCutoff = iValue; else if ( !strcmp ( sName, "cutoff" ) ) m_iCutoff = iValue;
else if ( !strcmp ( sName, "comment" ) ) m_sComment = sValue; else if ( !strcmp ( sName, "comment" ) ) m_sComment = sValue;
else if ( !strcmp ( sName, "select" ) ) m_sSelect = sValue;
else if ( !strcmp ( sName, "mode" ) ) else if ( !strcmp ( sName, "mode" ) )
{ {
m_eMode = SPH_MATCH_ALL; m_eMode = SPH_MATCH_ALL;
if ( !strcmp ( sValue, "any") ) m_eMode = SPH_MATCH_ANY; if ( !strcmp ( sValue, "any" ) ) m_eMode = SPH_MATCH_ANY;
else if ( !strcmp ( sValue, "phrase" ) ) m_eMode = SPH_MATCH_PHRASE; else if ( !strcmp ( sValue, "phrase" ) ) m_eMode = SPH_MATCH_PHRASE;
else if ( !strcmp ( sValue, "boolean") ) m_eMode = SPH_MATCH_BOOLEAN; else if ( !strcmp ( sValue, "boolean" ) ) m_eMode = SPH_MATCH_BOOLEAN;
else if ( !strcmp ( sValue, "ext") ) m_eMode = SPH_MATCH_EXTENDED; else if ( !strcmp ( sValue, "ext" ) ) m_eMode = SPH_MATCH_EXTENDED;
else if ( !strcmp ( sValue, "extended") ) m_eMode = SPH_MATCH_EXTENDED; else if ( !strcmp ( sValue, "extended" ) ) m_eMode = SPH_MATCH_EXTENDED;
else if ( !strcmp ( sValue, "ext2") ) m_eMode = SPH_MATCH_EXTENDED2; else if ( !strcmp ( sValue, "ext2" ) ) m_eMode = SPH_MATCH_EXTENDED2;
else if ( !strcmp ( sValue, "extended2") ) m_eMode = SPH_MATCH_EXTENDED2; else if ( !strcmp ( sValue, "extended2" ) ) m_eMode = SPH_MATCH_EXTENDED2;
else if ( !strcmp ( sValue, "all") ) m_eMode = SPH_MATCH_ALL; else if ( !strcmp ( sValue, "all" ) ) m_eMode = SPH_MATCH_ALL;
else if ( !strcmp ( sValue, "fullscan") ) m_eMode = SPH_MATCH_FULLSCAN; else if ( !strcmp ( sValue, "fullscan" ) ) m_eMode = SPH_MATCH_FULLSCAN;
else else
{ {
snprintf ( m_sParseError, sizeof(m_sParseError), "unknown matching mode '%s'", sValue ); snprintf ( m_sParseError, sizeof(m_sParseError), "unknown matching mode '%s'", sValue );
...@@ -1368,16 +1452,20 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1368,16 +1452,20 @@ bool CSphSEQuery::ParseField ( char * sField )
} }
} else if ( !strcmp ( sName, "ranker" ) ) } else if ( !strcmp ( sName, "ranker" ) )
{ {
m_eRanker = SPH_RANK_PROXIMITY_BM25; m_eRanker = SPH_RANK_PROXIMITY_BM25;
if ( !strcmp ( sValue, "proximity_bm25") ) m_eRanker = SPH_RANK_PROXIMITY_BM25; if ( !strcmp ( sValue, "proximity_bm25" ) ) m_eRanker = SPH_RANK_PROXIMITY_BM25;
else if ( !strcmp ( sValue, "bm25" ) ) m_eRanker = SPH_RANK_BM25; else if ( !strcmp ( sValue, "bm25" ) ) m_eRanker = SPH_RANK_BM25;
else if ( !strcmp ( sValue, "none" ) ) m_eRanker = SPH_RANK_NONE; else if ( !strcmp ( sValue, "none" ) ) m_eRanker = SPH_RANK_NONE;
else if ( !strcmp ( sValue, "wordcount" ) ) m_eRanker = SPH_RANK_WORDCOUNT; else if ( !strcmp ( sValue, "wordcount" ) ) m_eRanker = SPH_RANK_WORDCOUNT;
else if ( !strcmp ( sValue, "proximity" ) ) m_eRanker = SPH_RANK_PROXIMITY; else if ( !strcmp ( sValue, "proximity" ) ) m_eRanker = SPH_RANK_PROXIMITY;
else if ( !strcmp ( sValue, "matchany" ) ) m_eRanker = SPH_RANK_MATCHANY; else if ( !strcmp ( sValue, "matchany" ) ) m_eRanker = SPH_RANK_MATCHANY;
else if ( !strcmp ( sValue, "fieldmask" ) ) m_eRanker = SPH_RANK_FIELDMASK; else if ( !strcmp ( sValue, "fieldmask" ) ) m_eRanker = SPH_RANK_FIELDMASK;
else else if ( !strcmp ( sValue, "sph04" ) ) m_eRanker = SPH_RANK_SPH04;
else if ( !strncmp ( sValue, "expr:", 5 ) )
{
m_eRanker = SPH_RANK_EXPR;
m_sRankExpr = sValue+5;
} else
{ {
snprintf ( m_sParseError, sizeof(m_sParseError), "unknown ranking mode '%s'", sValue ); snprintf ( m_sParseError, sizeof(m_sParseError), "unknown ranking mode '%s'", sValue );
SPH_RET(false); SPH_RET(false);
...@@ -1401,10 +1489,10 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1401,10 +1489,10 @@ bool CSphSEQuery::ParseField ( char * sField )
int i; int i;
const int nModes = sizeof(dSortModes)/sizeof(dSortModes[0]); const int nModes = sizeof(dSortModes)/sizeof(dSortModes[0]);
for ( i=0; i<nModes; i++ ) for ( i=0; i<nModes; i++ )
if ( !strncmp ( sValue, dSortModes[i].m_sName, strlen(dSortModes[i].m_sName) ) ) if ( !strncmp ( sValue, dSortModes[i].m_sName, strlen ( dSortModes[i].m_sName ) ) )
{ {
m_eSort = dSortModes[i].m_eSort; m_eSort = dSortModes[i].m_eSort;
m_sSortBy = sValue + strlen(dSortModes[i].m_sName); m_sSortBy = sValue + strlen ( dSortModes[i].m_sName );
break; break;
} }
if ( i==nModes ) if ( i==nModes )
...@@ -1431,10 +1519,10 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1431,10 +1519,10 @@ bool CSphSEQuery::ParseField ( char * sField )
int i; int i;
const int nModes = sizeof(dGroupModes)/sizeof(dGroupModes[0]); const int nModes = sizeof(dGroupModes)/sizeof(dGroupModes[0]);
for ( i=0; i<nModes; i++ ) for ( i=0; i<nModes; i++ )
if ( !strncmp ( sValue, dGroupModes[i].m_sName, strlen(dGroupModes[i].m_sName) ) ) if ( !strncmp ( sValue, dGroupModes[i].m_sName, strlen ( dGroupModes[i].m_sName ) ) )
{ {
m_eGroupFunc = dGroupModes[i].m_eFunc; m_eGroupFunc = dGroupModes[i].m_eFunc;
m_sGroupBy = sValue + strlen(dGroupModes[i].m_sName); m_sGroupBy = sValue + strlen ( dGroupModes[i].m_sName );
break; break;
} }
if ( i==nModes ) if ( i==nModes )
...@@ -1486,7 +1574,7 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1486,7 +1574,7 @@ bool CSphSEQuery::ParseField ( char * sField )
{ {
CSphSEFilter & tFilter = m_dFilters [ m_iFilters ]; CSphSEFilter & tFilter = m_dFilters [ m_iFilters ];
tFilter.m_eType = SPH_FILTER_VALUES; tFilter.m_eType = SPH_FILTER_VALUES;
tFilter.m_bExclude = ( strcmp ( sName, "!filter")==0 ); tFilter.m_bExclude = ( strcmp ( sName, "!filter" )==0 );
// get the attr name // get the attr name
while ( (*sValue) && !myisattr(*sValue) ) while ( (*sValue) && !myisattr(*sValue) )
...@@ -1554,7 +1642,8 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1554,7 +1642,8 @@ bool CSphSEQuery::ParseField ( char * sField )
pWeights[*pCount] = atoi(sVal); pWeights[*pCount] = atoi(sVal);
(*pCount)++; (*pCount)++;
if ( !*p ) break; if ( !*p )
break;
if ( *p!=',' ) if ( *p!=',' )
{ {
snprintf ( m_sParseError, sizeof(m_sParseError), "%s: comma expected near '%s'", sName, p ); snprintf ( m_sParseError, sizeof(m_sParseError), "%s: comma expected near '%s'", sName, p );
...@@ -1582,8 +1671,8 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1582,8 +1671,8 @@ bool CSphSEQuery::ParseField ( char * sField )
m_sGeoLatAttr = chop(sLat); m_sGeoLatAttr = chop(sLat);
m_sGeoLongAttr = chop(sLong); m_sGeoLongAttr = chop(sLong);
m_fGeoLatitude = (float)atof(sLatVal); m_fGeoLatitude = (float)atof ( sLatVal );
m_fGeoLongitude = (float)atof(sLongVal); m_fGeoLongitude = (float)atof ( sLongVal );
m_bGeoAnchor = true; m_bGeoAnchor = true;
break; break;
} }
...@@ -1592,8 +1681,7 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1592,8 +1681,7 @@ bool CSphSEQuery::ParseField ( char * sField )
snprintf ( m_sParseError, sizeof(m_sParseError), "geoanchor: parse error, not enough comma-separated arguments" ); snprintf ( m_sParseError, sizeof(m_sParseError), "geoanchor: parse error, not enough comma-separated arguments" );
SPH_RET(false); SPH_RET(false);
} }
} } else if ( !strcmp ( sName, "override" ) ) // name,type,id:value,id:value,...
else if ( !strcmp ( sName, "override" ) ) // name,type,id:value,id:value,...
{ {
char * sName = NULL; char * sName = NULL;
int iType = 0; int iType = 0;
...@@ -1606,10 +1694,12 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1606,10 +1694,12 @@ bool CSphSEQuery::ParseField ( char * sField )
sName = sRest; sName = sRest;
if ( !*sName ) if ( !*sName )
break; break;
if (!( sRest = strchr ( sRest, ',' ) ))
if (!( sRest = strchr ( sRest, ',' ) )) break; *sRest++ = '\0'; break;
*sRest++ = '\0';
char * sType = sRest; char * sType = sRest;
if (!( sRest = strchr ( sRest, ',' ) )) break; if (!( sRest = strchr ( sRest, ',' ) ))
break;
static const struct static const struct
{ {
...@@ -1625,7 +1715,7 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1625,7 +1715,7 @@ bool CSphSEQuery::ParseField ( char * sField )
{ "bigint", SPH_ATTR_BIGINT } { "bigint", SPH_ATTR_BIGINT }
}; };
for ( uint i=0; i<sizeof(dAttrTypes)/sizeof(*dAttrTypes); i++ ) for ( uint i=0; i<sizeof(dAttrTypes)/sizeof(*dAttrTypes); i++ )
if ( !strncmp( sType, dAttrTypes[i].m_sName, sRest - sType ) ) if ( !strncmp ( sType, dAttrTypes[i].m_sName, sRest - sType ) )
{ {
iType = dAttrTypes[i].m_iType; iType = dAttrTypes[i].m_iType;
break; break;
...@@ -1649,7 +1739,8 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1649,7 +1739,8 @@ bool CSphSEQuery::ParseField ( char * sField )
if (!( sRest - sId )) break; if (!( sRest - sId )) break;
char * sValue = sRest; char * sValue = sRest;
if (( sRest = strchr ( sRest, ',' ) )) *sRest++ = '\0'; if ( ( sRest = strchr ( sRest, ',' ) )!=NULL )
*sRest++ = '\0';
if ( !*sValue ) if ( !*sValue )
break; break;
...@@ -1658,14 +1749,14 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1658,14 +1749,14 @@ bool CSphSEQuery::ParseField ( char * sField )
pOverride = new CSphSEQuery::Override_t; pOverride = new CSphSEQuery::Override_t;
pOverride->m_sName = chop(sName); pOverride->m_sName = chop(sName);
pOverride->m_iType = iType; pOverride->m_iType = iType;
m_dOverrides.append(pOverride); m_dOverrides.append ( pOverride );
} }
ulonglong uId = strtoull ( sId, NULL, 10 ); ulonglong uId = strtoull ( sId, NULL, 10 );
CSphSEQuery::Override_t::Value_t tValue; CSphSEQuery::Override_t::Value_t tValue;
if ( iType == SPH_ATTR_FLOAT ) if ( iType==SPH_ATTR_FLOAT )
tValue.m_fValue = (float)atof(sValue); tValue.m_fValue = (float)atof(sValue);
else if ( iType == SPH_ATTR_BIGINT ) else if ( iType==SPH_ATTR_BIGINT )
tValue.m_iValue64 = strtoll ( sValue, NULL, 10 ); tValue.m_iValue64 = strtoll ( sValue, NULL, 10 );
else else
tValue.m_uValue = (uint32)strtoul ( sValue, NULL, 10 ); tValue.m_uValue = (uint32)strtoul ( sValue, NULL, 10 );
...@@ -1680,8 +1771,7 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1680,8 +1771,7 @@ bool CSphSEQuery::ParseField ( char * sField )
SPH_RET(false); SPH_RET(false);
} }
SPH_RET(true); SPH_RET(true);
} } else
else
{ {
snprintf ( m_sParseError, sizeof(m_sParseError), "unknown parameter '%s'", sName ); snprintf ( m_sParseError, sizeof(m_sParseError), "unknown parameter '%s'", sName );
SPH_RET(false); SPH_RET(false);
...@@ -1702,7 +1792,7 @@ bool CSphSEQuery::Parse () ...@@ -1702,7 +1792,7 @@ bool CSphSEQuery::Parse ()
char * pCur = m_sQueryBuffer; char * pCur = m_sQueryBuffer;
char * pNext = pCur; char * pNext = pCur;
while (( pNext = strchr ( pNext, ';' ) )) while ( ( pNext = strchr ( pNext, ';' ) )!=NULL )
{ {
// handle escaped semicolons // handle escaped semicolons
if ( pNext>m_sQueryBuffer && pNext[-1]=='\\' && pNext[1]!='\0' ) if ( pNext>m_sQueryBuffer && pNext[-1]=='\\' && pNext[1]!='\0' )
...@@ -1718,6 +1808,8 @@ bool CSphSEQuery::Parse () ...@@ -1718,6 +1808,8 @@ bool CSphSEQuery::Parse ()
pCur = pNext; pCur = pNext;
} }
SPH_DEBUG ( "q [[ %s ]]", m_sQuery );
SPH_RET(true); SPH_RET(true);
} }
...@@ -1744,14 +1836,17 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) ...@@ -1744,14 +1836,17 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
// calc request length // calc request length
int iReqSize = 124 + 4*m_iWeights int iReqSize = 128 + 4*m_iWeights
+ strlen ( m_sSortBy ) + strlen ( m_sSortBy )
+ strlen ( m_sQuery ) + strlen ( m_sQuery )
+ strlen ( m_sIndex ) + strlen ( m_sIndex )
+ strlen ( m_sGroupBy ) + strlen ( m_sGroupBy )
+ strlen ( m_sGroupSortBy ) + strlen ( m_sGroupSortBy )
+ strlen ( m_sGroupDistinct ) + strlen ( m_sGroupDistinct )
+ strlen ( m_sComment ); + strlen ( m_sComment )
+ strlen ( m_sSelect );
if ( m_eRanker==SPH_RANK_EXPR )
iReqSize += 4 + strlen(m_sRankExpr);
for ( int i=0; i<m_iFilters; i++ ) for ( int i=0; i<m_iFilters; i++ )
{ {
const CSphSEFilter & tFilter = m_dFilters[i]; const CSphSEFilter & tFilter = m_dFilters[i];
...@@ -1774,7 +1869,7 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) ...@@ -1774,7 +1869,7 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
for ( int i=0; i<m_dOverrides.elements(); i++ ) for ( int i=0; i<m_dOverrides.elements(); i++ )
{ {
CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i); CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i);
const uint32 uSize = pOverride->m_iType == SPH_ATTR_BIGINT ? 16 : 12; // id64 + value const uint32 uSize = pOverride->m_iType==SPH_ATTR_BIGINT ? 16 : 12; // id64 + value
iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.elements(); iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.elements();
} }
// select // select
...@@ -1796,12 +1891,15 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) ...@@ -1796,12 +1891,15 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
SendWord ( SEARCHD_COMMAND_SEARCH ); // command id SendWord ( SEARCHD_COMMAND_SEARCH ); // command id
SendWord ( VER_COMMAND_SEARCH ); // command version SendWord ( VER_COMMAND_SEARCH ); // command version
SendInt ( iReqSize-8 ); // packet body length SendInt ( iReqSize-8 ); // packet body length
SendInt ( 0 ); // its a client
SendInt ( 1 ); // number of queries SendInt ( 1 ); // number of queries
SendInt ( m_iOffset ); SendInt ( m_iOffset );
SendInt ( m_iLimit ); SendInt ( m_iLimit );
SendInt ( m_eMode ); SendInt ( m_eMode );
SendInt ( m_eRanker ); // 1.16+ SendInt ( m_eRanker ); // 1.16+
if ( m_eRanker==SPH_RANK_EXPR )
SendString ( m_sRankExpr );
SendInt ( m_eSort ); SendInt ( m_eSort );
SendString ( m_sSortBy ); // sort attr SendString ( m_sSortBy ); // sort attr
SendString ( m_sQuery ); // query SendString ( m_sQuery ); // query
...@@ -1884,9 +1982,9 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) ...@@ -1884,9 +1982,9 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
for ( int j=0; j<pOverride->m_dIds.elements(); j++ ) for ( int j=0; j<pOverride->m_dIds.elements(); j++ )
{ {
SendUint64 ( pOverride->m_dIds.at(j) ); SendUint64 ( pOverride->m_dIds.at(j) );
if ( pOverride->m_iType == SPH_ATTR_FLOAT ) if ( pOverride->m_iType==SPH_ATTR_FLOAT )
SendFloat ( pOverride->m_dValues.at(j).m_fValue ); SendFloat ( pOverride->m_dValues.at(j).m_fValue );
else if ( pOverride->m_iType == SPH_ATTR_BIGINT ) else if ( pOverride->m_iType==SPH_ATTR_BIGINT )
SendUint64 ( pOverride->m_dValues.at(j).m_iValue64 ); SendUint64 ( pOverride->m_dValues.at(j).m_iValue64 );
else else
SendDword ( pOverride->m_dValues.at(j).m_uValue ); SendDword ( pOverride->m_dValues.at(j).m_uValue );
...@@ -1894,14 +1992,14 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) ...@@ -1894,14 +1992,14 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
} }
// select // select
SendString ( "" ); SendString ( m_sSelect );
// detect buffer overruns and underruns, and report internal error // detect buffer overruns and underruns, and report internal error
if ( m_bBufOverrun || m_iBufLeft!=0 || m_pCur-m_pBuf!=iReqSize ) if ( m_bBufOverrun || m_iBufLeft!=0 || m_pCur-m_pBuf!=iReqSize )
SPH_RET(-1); SPH_RET(-1);
// all fine // all fine
SPH_RET(iReqSize); SPH_RET ( iReqSize );
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -1938,6 +2036,18 @@ ha_sphinx::ha_sphinx ( handlerton * hton, TABLE_ARG * table ) ...@@ -1938,6 +2036,18 @@ ha_sphinx::ha_sphinx ( handlerton * hton, TABLE_ARG * table )
SPH_VOID_RET(); SPH_VOID_RET();
} }
ha_sphinx::~ha_sphinx()
{
SafeDeleteArray ( m_dAttrs );
SafeDeleteArray ( m_dUnboundFields );
if ( m_dFields )
{
for (uint32 i=0; i< m_iFields; i++ )
SafeDeleteArray ( m_dFields[i] );
delete [] m_dFields;
}
}
// If frm_error() is called then we will use this to to find out what file extentions // If frm_error() is called then we will use this to to find out what file extentions
// exist for the storage engine. This is also used by the default rename_table and // exist for the storage engine. This is also used by the default rename_table and
...@@ -1964,16 +2074,24 @@ int ha_sphinx::open ( const char * name, int, uint ) ...@@ -1964,16 +2074,24 @@ int ha_sphinx::open ( const char * name, int, uint )
thr_lock_data_init ( &m_pShare->m_tLock, &m_tLock, NULL ); thr_lock_data_init ( &m_pShare->m_tLock, &m_tLock, NULL );
*thd_ha_data ( table->in_use, ht ) = NULL; #if MYSQL_VERSION_ID>50100
void **tmp= thd_ha_data(table->in_use, ht);
if (*tmp)
{
CSphSEThreadData* pTls = (CSphSEThreadData*) *tmp;
SafeDelete(pTls);
*tmp= NULL;
}
#else
table->in_use->ha_data [ sphinx_hton.slot ] = NULL;
#endif
SPH_RET(0); SPH_RET(0);
} }
int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort ) int ha_sphinx::Connect ( const char * sHost, ushort uPort )
{ {
SPH_ENTER_METHOD();
struct sockaddr_in sin; struct sockaddr_in sin;
#ifndef __WIN__ #ifndef __WIN__
struct sockaddr_un saun; struct sockaddr_un saun;
...@@ -1984,13 +2102,8 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort ) ...@@ -1984,13 +2102,8 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
struct sockaddr * pSockaddr = NULL; struct sockaddr * pSockaddr = NULL;
in_addr_t ip_addr; in_addr_t ip_addr;
int version;
uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO );
const char * sHost = ( sQueryHost && *sQueryHost ) ? sQueryHost : m_pShare->m_sHost; if ( uPort )
ushort iPort = iQueryPort ? (ushort)iQueryPort : m_pShare->m_iPort;
if ( iPort )
{ {
iDomain = AF_INET; iDomain = AF_INET;
iSockaddrSize = sizeof(sin); iSockaddrSize = sizeof(sin);
...@@ -1998,27 +2111,38 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort ) ...@@ -1998,27 +2111,38 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
memset ( &sin, 0, sizeof(sin) ); memset ( &sin, 0, sizeof(sin) );
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = htons(iPort); sin.sin_port = htons(uPort);
// prepare host address // prepare host address
if ( (int)( ip_addr=inet_addr(sHost) ) != (int)INADDR_NONE ) if ( (int)( ip_addr = inet_addr(sHost) )!=(int)INADDR_NONE )
{ {
memcpy ( &sin.sin_addr, &ip_addr, sizeof(ip_addr) ); memcpy ( &sin.sin_addr, &ip_addr, sizeof(ip_addr) );
} else } else
{ {
int err_code; int tmp_errno;
struct addrinfo hints; bool bError = false;
struct addrinfo *addr_info_list;
memset(&hints, 0, sizeof (struct addrinfo));
hints.ai_flags= AI_PASSIVE;
hints.ai_socktype= SOCK_STREAM;
hints.ai_family= AF_UNSPEC;
err_code= getaddrinfo(sHost, NULL, &hints, #if MYSQL_VERSION_ID>=50515
&addr_info_list); struct addrinfo *hp = NULL;
tmp_errno = getaddrinfo ( sHost, NULL, NULL, &hp );
if ( !tmp_errno || !hp || !hp->ai_addr )
{
bError = true;
if ( hp )
freeaddrinfo ( hp );
}
#else
struct hostent tmp_hostent, *hp;
char buff2 [ GETHOSTBYNAME_BUFF_SIZE ];
hp = my_gethostbyname_r ( sHost, &tmp_hostent, buff2, sizeof(buff2), &tmp_errno );
if ( !hp )
{
my_gethostbyname_r_free();
bError = true;
}
#endif
if ( err_code ) if ( bError )
{ {
char sError[256]; char sError[256];
my_snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", sHost ); my_snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", sHost );
...@@ -2027,10 +2151,13 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort ) ...@@ -2027,10 +2151,13 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
SPH_RET(-1); SPH_RET(-1);
} }
memcpy ( &sin.sin_addr, addr_info_list->ai_addr, #if MYSQL_VERSION_ID>=50515
Min ( sizeof(sin.sin_addr), (size_t)addr_info_list->ai_addrlen ) ); memcpy ( &sin.sin_addr, hp->ai_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->ai_addrlen ) );
freeaddrinfo ( hp );
freeaddrinfo(addr_info_list); #else
memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) );
my_gethostbyname_r_free();
#endif
} }
} else } else
{ {
...@@ -2061,30 +2188,49 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort ) ...@@ -2061,30 +2188,49 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
{ {
sphSockClose ( iSocket ); sphSockClose ( iSocket );
my_snprintf ( sError, sizeof(sError), "failed to connect to searchd (host=%s, errno=%d, port=%d)", my_snprintf ( sError, sizeof(sError), "failed to connect to searchd (host=%s, errno=%d, port=%d)",
sHost, errno, iPort ); sHost, errno, (int)uPort );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError ); my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1); SPH_RET(-1);
} }
return iSocket;
}
int ha_sphinx::ConnectAPI ( const char * sQueryHost, int iQueryPort )
{
SPH_ENTER_METHOD();
const char * sHost = ( sQueryHost && *sQueryHost ) ? sQueryHost : m_pShare->m_sHost;
ushort uPort = iQueryPort ? (ushort)iQueryPort : m_pShare->m_iPort;
int iSocket = Connect ( sHost, uPort );
if ( iSocket<0 )
SPH_RET ( iSocket );
char sError[512];
int version;
if ( ::recv ( iSocket, (char *)&version, sizeof(version), 0 )!=sizeof(version) ) if ( ::recv ( iSocket, (char *)&version, sizeof(version), 0 )!=sizeof(version) )
{ {
sphSockClose ( iSocket ); sphSockClose ( iSocket );
my_snprintf ( sError, sizeof(sError), "failed to receive searchd version (host=%s, port=%d)", my_snprintf ( sError, sizeof(sError), "failed to receive searchd version (host=%s, port=%d)",
sHost, iPort ); sHost, (int)uPort );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError ); my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1); SPH_RET(-1);
} }
uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO );
if ( ::send ( iSocket, (char*)&uClientVersion, sizeof(uClientVersion), 0 )!=sizeof(uClientVersion) ) if ( ::send ( iSocket, (char*)&uClientVersion, sizeof(uClientVersion), 0 )!=sizeof(uClientVersion) )
{ {
sphSockClose ( iSocket ); sphSockClose ( iSocket );
my_snprintf ( sError, sizeof(sError), "failed to send client version (host=%s, port=%d)", my_snprintf ( sError, sizeof(sError), "failed to send client version (host=%s, port=%d)",
sHost, iPort ); sHost, (int)uPort );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError ); my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1); SPH_RET(-1);
} }
SPH_RET(iSocket); SPH_RET ( iSocket );
} }
...@@ -2099,25 +2245,182 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort ) ...@@ -2099,25 +2245,182 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
int ha_sphinx::close() int ha_sphinx::close()
{ {
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
SPH_RET ( free_share(m_pShare) ); SPH_RET ( free_share ( m_pShare ) );
} }
int ha_sphinx::write_row ( uchar * ) int ha_sphinx::HandleMysqlError ( MYSQL * pConn, int iErrCode )
{
CSphSEThreadData * pTls = GetTls ();
if ( pTls )
{
strncpy ( pTls->m_tStats.m_sLastMessage, mysql_error ( pConn ), sizeof ( pTls->m_tStats.m_sLastMessage ) );
pTls->m_tStats.m_bLastError = true;
}
mysql_close ( pConn );
my_error ( iErrCode, MYF(0), pTls->m_tStats.m_sLastMessage );
return -1;
}
int ha_sphinx::extra ( enum ha_extra_function op )
{
CSphSEThreadData * pTls = GetTls();
if ( pTls )
{
if ( op==HA_EXTRA_WRITE_CAN_REPLACE )
pTls->m_bReplace = true;
else if ( op==HA_EXTRA_WRITE_CANNOT_REPLACE )
pTls->m_bReplace = false;
}
return 0;
}
int ha_sphinx::write_row ( byte * )
{ {
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
if ( !m_pShare || !m_pShare->m_bSphinxQL )
SPH_RET ( HA_ERR_WRONG_COMMAND ); SPH_RET ( HA_ERR_WRONG_COMMAND );
// SphinxQL inserts only, pretty much similar to abandoned federated
char sQueryBuf[1024];
char sValueBuf[1024];
String sQuery ( sQueryBuf, sizeof(sQueryBuf), &my_charset_bin );
String sValue ( sValueBuf, sizeof(sQueryBuf), &my_charset_bin );
sQuery.length ( 0 );
sValue.length ( 0 );
CSphSEThreadData * pTls = GetTls ();
sQuery.append ( pTls && pTls->m_bReplace ? "REPLACE INTO " : "INSERT INTO " );
sQuery.append ( m_pShare->m_sIndex );
sQuery.append ( " (" );
for ( Field ** ppField = table->field; *ppField; ppField++ )
{
sQuery.append ( (*ppField)->field_name );
if ( ppField[1] )
sQuery.append ( ", " );
}
sQuery.append ( ") VALUES (" );
for ( Field ** ppField = table->field; *ppField; ppField++ )
{
if ( (*ppField)->is_null() )
{
sQuery.append ( "''" );
} else
{
if ( (*ppField)->type()==MYSQL_TYPE_TIMESTAMP )
{
Item_field * pWrap = new Item_field ( *ppField ); // autofreed by query arena, I assume
Item_func_unix_timestamp * pConv = new Item_func_unix_timestamp ( pWrap );
pConv->quick_fix_field();
unsigned int uTs = (unsigned int) pConv->val_int();
snprintf ( sValueBuf, sizeof(sValueBuf), "'%u'", uTs );
sQuery.append ( sValueBuf );
} else
{
(*ppField)->val_str ( &sValue );
sQuery.append ( "'" );
sValue.print ( &sQuery );
sQuery.append ( "'" );
sValue.length(0);
}
}
if ( ppField[1] )
sQuery.append ( ", " );
}
sQuery.append ( ")" );
// FIXME? pretty inefficient to reconnect every time under high load,
// but this was intentionally written for a low load scenario..
MYSQL * pConn = mysql_init ( NULL );
if ( !pConn )
SPH_RET ( ER_OUT_OF_RESOURCES );
unsigned int uTimeout = 1;
mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) )
SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) );
if ( mysql_real_query ( pConn, sQuery.ptr(), sQuery.length() ) )
SPH_RET ( HandleMysqlError ( pConn, ER_QUERY_ON_FOREIGN_DATA_SOURCE ) );
// all ok!
mysql_close ( pConn );
SPH_RET(0);
}
static inline bool IsIntegerFieldType ( enum_field_types eType )
{
return eType==MYSQL_TYPE_LONG || eType==MYSQL_TYPE_LONGLONG;
} }
int ha_sphinx::update_row ( const uchar *, uchar * ) static inline bool IsIDField ( Field * pField )
{
enum_field_types eType = pField->type();
if ( eType==MYSQL_TYPE_LONGLONG )
return true;
if ( eType==MYSQL_TYPE_LONG && ((Field_num*)pField)->unsigned_flag )
return true;
return false;
}
int ha_sphinx::delete_row ( const byte * )
{ {
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
if ( !m_pShare || !m_pShare->m_bSphinxQL )
SPH_RET ( HA_ERR_WRONG_COMMAND ); SPH_RET ( HA_ERR_WRONG_COMMAND );
char sQueryBuf[1024];
String sQuery ( sQueryBuf, sizeof(sQueryBuf), &my_charset_bin );
sQuery.length ( 0 );
sQuery.append ( "DELETE FROM " );
sQuery.append ( m_pShare->m_sIndex );
sQuery.append ( " WHERE id=" );
char sValue[32];
snprintf ( sValue, sizeof(sValue), "%lld", table->field[0]->val_int() );
sQuery.append ( sValue );
// FIXME? pretty inefficient to reconnect every time under high load,
// but this was intentionally written for a low load scenario..
MYSQL * pConn = mysql_init ( NULL );
if ( !pConn )
SPH_RET ( ER_OUT_OF_RESOURCES );
unsigned int uTimeout = 1;
mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) )
SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) );
if ( mysql_real_query ( pConn, sQuery.ptr(), sQuery.length() ) )
SPH_RET ( HandleMysqlError ( pConn, ER_QUERY_ON_FOREIGN_DATA_SOURCE ) );
// all ok!
mysql_close ( pConn );
SPH_RET(0);
} }
int ha_sphinx::delete_row ( const uchar * ) int ha_sphinx::update_row ( const byte *, byte * )
{ {
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
SPH_RET ( HA_ERR_WRONG_COMMAND ); SPH_RET ( HA_ERR_WRONG_COMMAND );
...@@ -2130,6 +2433,11 @@ int ha_sphinx::index_init ( uint keynr, bool ) ...@@ -2130,6 +2433,11 @@ int ha_sphinx::index_init ( uint keynr, bool )
{ {
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
active_index = keynr; active_index = keynr;
CSphSEThreadData * pTls = GetTls();
if ( pTls )
pTls->m_bCondDone = false;
SPH_RET(0); SPH_RET(0);
} }
...@@ -2141,17 +2449,28 @@ int ha_sphinx::index_end() ...@@ -2141,17 +2449,28 @@ int ha_sphinx::index_end()
} }
uint32 ha_sphinx::UnpackDword () bool ha_sphinx::CheckResponcePtr ( int iLen )
{ {
if ( m_pCur+sizeof(uint32)>m_pResponseEnd ) if ( m_pCur+iLen>m_pResponseEnd )
{ {
m_pCur = m_pResponseEnd; m_pCur = m_pResponseEnd;
m_bUnpackError = true; m_bUnpackError = true;
return false;
}
return true;
}
uint32 ha_sphinx::UnpackDword ()
{
if ( !CheckResponcePtr ( sizeof(uint32) ) ) // NOLINT
{
return 0; return 0;
} }
uint32 uRes = ntohl ( sphUnalignedRead ( *(uint32*)m_pCur ) ); uint32 uRes = ntohl ( sphUnalignedRead ( *(uint32*)m_pCur ) );
m_pCur += sizeof(uint32); m_pCur += sizeof(uint32); // NOLINT
return uRes; return uRes;
} }
...@@ -2162,10 +2481,8 @@ char * ha_sphinx::UnpackString () ...@@ -2162,10 +2481,8 @@ char * ha_sphinx::UnpackString ()
if ( !iLen ) if ( !iLen )
return NULL; return NULL;
if ( m_pCur+iLen>m_pResponseEnd ) if ( !CheckResponcePtr ( iLen ) )
{ {
m_pCur = m_pResponseEnd;
m_bUnpackError = true;
return NULL; return NULL;
} }
...@@ -2275,7 +2592,7 @@ bool ha_sphinx::UnpackSchema () ...@@ -2275,7 +2592,7 @@ bool ha_sphinx::UnpackSchema ()
m_iMatchesTotal = UnpackDword (); m_iMatchesTotal = UnpackDword ();
m_bId64 = UnpackDword (); m_bId64 = UnpackDword ();
if ( m_bId64 && m_pShare->m_eTableFieldType[0] != MYSQL_TYPE_LONGLONG ) if ( m_bId64 && m_pShare->m_eTableFieldType[0]!=MYSQL_TYPE_LONGLONG )
{ {
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: 1st column must be bigint to accept 64-bit DOCIDs" ); my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: 1st column must be bigint to accept 64-bit DOCIDs" );
SPH_RET(false); SPH_RET(false);
...@@ -2304,7 +2621,7 @@ bool ha_sphinx::UnpackSchema () ...@@ -2304,7 +2621,7 @@ bool ha_sphinx::UnpackSchema ()
if ( m_bUnpackError ) if ( m_bUnpackError )
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: UnpackSchema() failed (unpack error)" ); my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: UnpackSchema() failed (unpack error)" );
SPH_RET(!m_bUnpackError); SPH_RET ( !m_bUnpackError );
} }
...@@ -2313,19 +2630,22 @@ bool ha_sphinx::UnpackStats ( CSphSEStats * pStats ) ...@@ -2313,19 +2630,22 @@ bool ha_sphinx::UnpackStats ( CSphSEStats * pStats )
assert ( pStats ); assert ( pStats );
char * pCurSave = m_pCur; char * pCurSave = m_pCur;
for ( uint i=0; i<m_iMatchesTotal && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) for ( uint i=0; i<m_iMatchesTotal && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) // NOLINT
{ {
m_pCur += m_bId64 ? 12 : 8; // skip id+weight m_pCur += m_bId64 ? 12 : 8; // skip id+weight
for ( uint32 i=0; i<m_iAttrs && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) for ( uint32 i=0; i<m_iAttrs && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) // NOLINT
{ {
if ( m_dAttrs[i].m_uType & SPH_ATTR_MULTI ) if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET || m_dAttrs[i].m_uType==SPH_ATTR_UINT64SET )
{ {
// skip MVA list // skip MVA list
uint32 uCount = UnpackDword (); uint32 uCount = UnpackDword ();
m_pCur += uCount*4; m_pCur += uCount*4;
} } else if ( m_dAttrs[i].m_uType==SPH_ATTR_STRING )
else // skip normal value {
m_pCur += m_dAttrs[i].m_uType == SPH_ATTR_BIGINT ? 8 : 4; uint32 iLen = UnpackDword();
m_pCur += iLen;
} else // skip normal value
m_pCur += m_dAttrs[i].m_uType==SPH_ATTR_BIGINT ? 8 : 4;
} }
} }
...@@ -2337,9 +2657,10 @@ bool ha_sphinx::UnpackStats ( CSphSEStats * pStats ) ...@@ -2337,9 +2657,10 @@ bool ha_sphinx::UnpackStats ( CSphSEStats * pStats )
if ( m_bUnpackError ) if ( m_bUnpackError )
return false; return false;
SafeDeleteArray ( pStats->m_dWords );
if ( pStats->m_iWords<0 || pStats->m_iWords>=SPHINXSE_MAX_KEYWORDSTATS ) if ( pStats->m_iWords<0 || pStats->m_iWords>=SPHINXSE_MAX_KEYWORDSTATS )
return false; return false;
SafeDeleteArray ( pStats->m_dWords );
pStats->m_dWords = new CSphSEWordStats [ pStats->m_iWords ]; pStats->m_dWords = new CSphSEWordStats [ pStats->m_iWords ];
if ( !pStats->m_dWords ) if ( !pStats->m_dWords )
return false; return false;
...@@ -2373,25 +2694,45 @@ const COND * ha_sphinx::cond_push ( const COND * cond ) ...@@ -2373,25 +2694,45 @@ const COND * ha_sphinx::cond_push ( const COND * cond )
if ( condf->functype()!=Item_func::EQ_FUNC || condf->argument_count()!=2 ) if ( condf->functype()!=Item_func::EQ_FUNC || condf->argument_count()!=2 )
break; break;
// get my tls
CSphSEThreadData * pTls = GetTls ();
if ( !pTls )
break;
Item ** args = condf->arguments(); Item ** args = condf->arguments();
if ( args[0]->type()!=COND::FIELD_ITEM || args[1]->type()!=COND::STRING_ITEM ) if ( !m_pShare->m_bSphinxQL )
{
// on non-QL tables, intercept query=value condition for SELECT
if (!( args[0]->type()==COND::FIELD_ITEM && args[1]->type()==COND::STRING_ITEM ))
break; break;
Item_field * pField = (Item_field *) args[0]; Item_field * pField = (Item_field *) args[0];
if ( pField->field->field_index!=2 ) // FIXME! magic key index if ( pField->field->field_index!=2 ) // FIXME! magic key index
break; break;
// get my tls
CSphSEThreadData * pTls = GetTls ();
if ( !pTls )
break;
// copy the query, and let know that we intercepted this condition // copy the query, and let know that we intercepted this condition
Item_string * pString = (Item_string *) args[1]; Item_string * pString = (Item_string *) args[1];
pTls->m_bQuery = true; pTls->m_bQuery = true;
strncpy ( pTls->m_sQuery, pString->str_value.c_ptr(), sizeof(pTls->m_sQuery) ); strncpy ( pTls->m_sQuery, pString->str_value.c_ptr(), sizeof(pTls->m_sQuery) );
pTls->m_sQuery[sizeof(pTls->m_sQuery)-1] = '\0'; pTls->m_sQuery[sizeof(pTls->m_sQuery)-1] = '\0';
pTls->m_pQueryCharset = pString->str_value.charset(); pTls->m_pQueryCharset = pString->str_value.charset();
} else
{
if (!( args[0]->type()==COND::FIELD_ITEM && args[1]->type()==COND::INT_ITEM ))
break;
// on QL tables, intercept id=value condition for DELETE
Item_field * pField = (Item_field *) args[0];
if ( pField->field->field_index!=0 ) // FIXME! magic key index
break;
Item_int * pVal = (Item_int *) args[1];
pTls->m_iCondId = pVal->val_int();
pTls->m_bCondId = true;
}
// we intercepted this condition
return NULL; return NULL;
} }
...@@ -2404,9 +2745,8 @@ const COND * ha_sphinx::cond_push ( const COND * cond ) ...@@ -2404,9 +2745,8 @@ const COND * ha_sphinx::cond_push ( const COND * cond )
void ha_sphinx::cond_pop () void ha_sphinx::cond_pop ()
{ {
CSphSEThreadData * pTls = GetTls (); CSphSEThreadData * pTls = GetTls ();
if ( pTls && pTls->m_bQuery ) if ( pTls )
pTls->m_bQuery = false; pTls->m_bQuery = false;
return;
} }
...@@ -2415,7 +2755,11 @@ CSphSEThreadData * ha_sphinx::GetTls() ...@@ -2415,7 +2755,11 @@ CSphSEThreadData * ha_sphinx::GetTls()
{ {
// where do we store that pointer in today's version? // where do we store that pointer in today's version?
CSphSEThreadData ** ppTls; CSphSEThreadData ** ppTls;
ppTls = (CSphSEThreadData**) thd_ha_data ( ha_thd(), ht ); #if MYSQL_VERSION_ID>50100
ppTls = (CSphSEThreadData**) thd_ha_data ( table->in_use, ht );
#else
ppTls = (CSphSEThreadData**) &current_thd->ha_data[sphinx_hton.slot];
#endif // >50100
// allocate if needed // allocate if needed
if ( !*ppTls ) if ( !*ppTls )
...@@ -2443,6 +2787,38 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_ ...@@ -2443,6 +2787,38 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_
} }
pTls->m_tStats.Reset (); pTls->m_tStats.Reset ();
// sphinxql table, just return the key once
if ( m_pShare->m_bSphinxQL )
{
// over and out
if ( pTls->m_bCondDone )
SPH_RET ( HA_ERR_END_OF_FILE );
// return a value from pushdown, if any
if ( pTls->m_bCondId )
{
table->field[0]->store ( pTls->m_iCondId, 1 );
pTls->m_bCondDone = true;
SPH_RET(0);
}
// return a value from key
longlong iRef = 0;
if ( key_len==4 )
iRef = uint4korr ( key );
else if ( key_len==8 )
iRef = uint8korr ( key );
else
{
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: unexpected key length" );
SPH_RET ( HA_ERR_END_OF_FILE );
}
table->field[0]->store ( iRef, 1 );
pTls->m_bCondDone = true;
SPH_RET(0);
}
// parse query // parse query
if ( pTls->m_bQuery ) if ( pTls->m_bQuery )
{ {
...@@ -2465,7 +2841,7 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_ ...@@ -2465,7 +2841,7 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_
} }
// do connect // do connect
int iSocket = ConnectToSearchd ( q.m_sHost, q.m_iPort ); int iSocket = ConnectAPI ( q.m_sHost, q.m_iPort );
if ( iSocket<0 ) if ( iSocket<0 )
SPH_RET ( HA_ERR_END_OF_FILE ); SPH_RET ( HA_ERR_END_OF_FILE );
...@@ -2623,16 +2999,21 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint ) ...@@ -2623,16 +2999,21 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
for ( uint32 i=0; i<m_iAttrs; i++ ) for ( uint32 i=0; i<m_iAttrs; i++ )
{ {
longlong iValue64= 0; longlong iValue64 = 0;
uint32 uValue = UnpackDword (); uint32 uValue = UnpackDword ();
if ( m_dAttrs[i].m_uType == SPH_ATTR_BIGINT ) if ( m_dAttrs[i].m_uType==SPH_ATTR_BIGINT )
iValue64 = ( (longlong)uValue<<32 ) | UnpackDword(); iValue64 = ( (longlong)uValue<<32 ) | UnpackDword();
if ( m_dAttrs[i].m_iField<0 ) if ( m_dAttrs[i].m_iField<0 )
{ {
// skip MVA // skip MVA or String
if ( m_dAttrs[i].m_uType & SPH_ATTR_MULTI ) if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET || m_dAttrs[i].m_uType==SPH_ATTR_UINT64SET )
{
for ( ; uValue>0 && !m_bUnpackError; uValue-- ) for ( ; uValue>0 && !m_bUnpackError; uValue-- )
UnpackDword(); UnpackDword();
} else if ( m_dAttrs[i].m_uType==SPH_ATTR_STRING && CheckResponcePtr ( uValue ) )
{
m_pCur += uValue;
}
continue; continue;
} }
...@@ -2660,7 +3041,18 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint ) ...@@ -2660,7 +3041,18 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
af->store ( iValue64, 0 ); af->store ( iValue64, 0 );
break; break;
case ( SPH_ATTR_MULTI | SPH_ATTR_INTEGER ): case SPH_ATTR_STRING:
if ( !uValue )
af->store ( "", 0, &my_charset_bin );
else if ( CheckResponcePtr ( uValue ) )
{
af->store ( m_pCur, uValue, &my_charset_bin );
m_pCur += uValue;
}
break;
case SPH_ATTR_UINT64SET:
case SPH_ATTR_UINT32SET :
if ( uValue<=0 ) if ( uValue<=0 )
{ {
// shortcut, empty MVA set // shortcut, empty MVA set
...@@ -2672,17 +3064,34 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint ) ...@@ -2672,17 +3064,34 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
char sBuf[1024]; // FIXME! magic size char sBuf[1024]; // FIXME! magic size
char * pCur = sBuf; char * pCur = sBuf;
if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET )
{
for ( ; uValue>0 && !m_bUnpackError; uValue-- ) for ( ; uValue>0 && !m_bUnpackError; uValue-- )
{ {
uint32 uEntry = UnpackDword (); uint32 uEntry = UnpackDword ();
if ( pCur < sBuf+sizeof(sBuf)-16 ) // 10 chars per 32bit value plus some safety bytes if ( pCur < sBuf+sizeof(sBuf)-16 ) // 10 chars per 32bit value plus some safety bytes
{ {
sprintf ( pCur, "%u", uEntry ); snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%u", uEntry );
while ( *pCur ) pCur++; while ( *pCur ) pCur++;
if ( uValue>1 ) if ( uValue>1 )
*pCur++ = ','; // non-trailing commas *pCur++ = ','; // non-trailing commas
} }
} }
} else
{
for ( ; uValue>0 && !m_bUnpackError; uValue-=2 )
{
uint32 uEntryLo = UnpackDword ();
uint32 uEntryHi = UnpackDword();
if ( pCur < sBuf+sizeof(sBuf)-24 ) // 20 chars per 64bit value plus some safety bytes
{
snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%u%u", uEntryHi, uEntryLo );
while ( *pCur ) pCur++;
if ( uValue>2 )
*pCur++ = ','; // non-trailing commas
}
}
}
af->store ( sBuf, pCur-sBuf, &my_charset_bin ); af->store ( sBuf, pCur-sBuf, &my_charset_bin );
} }
...@@ -2720,7 +3129,7 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint ) ...@@ -2720,7 +3129,7 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
m_iCurrentPos++; m_iCurrentPos++;
#if MYSQL_VERSION_ID > 50100 #if MYSQL_VERSION_ID > 50100
dbug_tmp_restore_column_map(table->write_set, org_bitmap); dbug_tmp_restore_column_map ( table->write_set, org_bitmap );
#endif #endif
SPH_RET(0); SPH_RET(0);
...@@ -2860,7 +3269,7 @@ THR_LOCK_DATA ** ha_sphinx::store_lock ( THD *, THR_LOCK_DATA ** to, ...@@ -2860,7 +3269,7 @@ THR_LOCK_DATA ** ha_sphinx::store_lock ( THD *, THR_LOCK_DATA ** to,
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
if ( lock_type!=TL_IGNORE && m_tLock.type==TL_UNLOCK ) if ( lock_type!=TL_IGNORE && m_tLock.type==TL_UNLOCK )
m_tLock.type=lock_type; m_tLock.type = lock_type;
*to++ = &m_tLock; *to++ = &m_tLock;
SPH_RET(to); SPH_RET(to);
...@@ -2900,12 +3309,6 @@ ha_rows ha_sphinx::records_in_range ( uint, key_range *, key_range * ) ...@@ -2900,12 +3309,6 @@ ha_rows ha_sphinx::records_in_range ( uint, key_range *, key_range * )
} }
static inline bool IsIntegerFieldType ( enum_field_types eType )
{
return eType==MYSQL_TYPE_LONG || eType==MYSQL_TYPE_LONGLONG;
}
// create() is called to create a database. The variable name will have the name // create() is called to create a database. The variable name will have the name
// of the table. When create() is called you do not need to worry about opening // of the table. When create() is called you do not need to worry about opening
// the table. Also, the FRM file will have already been created so adjusting // the table. Also, the FRM file will have already been created so adjusting
...@@ -2919,10 +3322,12 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * ) ...@@ -2919,10 +3322,12 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
SPH_ENTER_METHOD(); SPH_ENTER_METHOD();
char sError[256]; char sError[256];
if ( !ParseUrl ( NULL, table, true ) ) CSphSEShare tInfo;
if ( !ParseUrl ( &tInfo, table, true ) )
SPH_RET(-1); SPH_RET(-1);
for ( ;; ) // check SphinxAPI table
for ( ; !tInfo.m_bSphinxQL; )
{ {
// check system fields (count and types) // check system fields (count and types)
if ( table->s->fields<SPHINXSE_SYSTEM_COLUMNS ) if ( table->s->fields<SPHINXSE_SYSTEM_COLUMNS )
...@@ -2932,7 +3337,7 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * ) ...@@ -2932,7 +3337,7 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
break; break;
} }
if ( !IsIntegerFieldType ( table->field[0]->type() ) || !((Field_num *)table->field[0])->unsigned_flag ) if ( !IsIDField ( table->field[0] ) )
{ {
my_snprintf ( sError, sizeof(sError), "%s: 1st column (docid) MUST be unsigned integer or bigint", name ); my_snprintf ( sError, sizeof(sError), "%s: 1st column (docid) MUST be unsigned integer or bigint", name );
break; break;
...@@ -2983,6 +3388,54 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * ) ...@@ -2983,6 +3388,54 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
sError[0] = '\0'; sError[0] = '\0';
break; break;
} }
// check SphinxQL table
for ( ; tInfo.m_bSphinxQL; )
{
sError[0] = '\0';
// check that 1st column is id, is of int type, and has an index
if ( strcmp ( table->field[0]->field_name, "id" ) )
{
my_snprintf ( sError, sizeof(sError), "%s: 1st column must be called 'id'", name );
break;
}
if ( !IsIDField ( table->field[0] ) )
{
my_snprintf ( sError, sizeof(sError), "%s: 'id' column must be INT UNSIGNED or BIGINT", name );
break;
}
// check index
if (
table->s->keys!=1 ||
table->key_info[0].key_parts!=1 ||
strcasecmp ( table->key_info[0].key_part[0].field->field_name, "id" ) )
{
my_snprintf ( sError, sizeof(sError), "%s: 'id' column must be indexed", name );
break;
}
// check column types
for ( int i=1; i<(int)table->s->fields; i++ )
{
enum_field_types eType = table->field[i]->type();
if ( eType!=MYSQL_TYPE_TIMESTAMP && !IsIntegerFieldType(eType) && eType!=MYSQL_TYPE_VARCHAR && eType!=MYSQL_TYPE_FLOAT )
{
my_snprintf ( sError, sizeof(sError), "%s: column %d(%s) is of unsupported type (use int/bigint/timestamp/varchar/float)",
name, i+1, table->field[i]->field_name );
break;
}
}
if ( sError[0] )
break;
// all good
break;
}
// report and bail
if ( sError[0] ) if ( sError[0] )
{ {
my_error ( ER_CANT_CREATE_TABLE, MYF(0), sError, -1 ); my_error ( ER_CANT_CREATE_TABLE, MYF(0), sError, -1 );
...@@ -2992,46 +3445,99 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * ) ...@@ -2992,46 +3445,99 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
SPH_RET(0); SPH_RET(0);
} }
//// show functions // show functions
#if MYSQL_VERSION_ID<50100 #if MYSQL_VERSION_ID<50100
#define SHOW_VAR_FUNC_BUFF_SIZE 1024 #define SHOW_VAR_FUNC_BUFF_SIZE 1024
#endif #endif
static int sphinx_showfunc ( THD * thd, SHOW_VAR * out, char * sBuffer ) CSphSEStats * sphinx_get_stats ( THD * thd, SHOW_VAR * out )
{ {
#if MYSQL_VERSION_ID>50100
if ( sphinx_hton_ptr )
{
CSphSEThreadData *pTls = (CSphSEThreadData *) *thd_ha_data ( thd, sphinx_hton_ptr ); CSphSEThreadData *pTls = (CSphSEThreadData *) *thd_ha_data ( thd, sphinx_hton_ptr );
CSphSEStats * pStats = ( pTls && pTls->m_bStats ) ? &pTls->m_tStats : 0;
SHOW_VAR *array = (SHOW_VAR*)thd_alloc(thd, sizeof(SHOW_VAR)*7);
out->type = SHOW_ARRAY;
out->value = (char*)array;
if (pStats)
{
array[0].name = "total";
array[0].type = SHOW_INT;
array[0].value = (char *) &pStats->m_iMatchesTotal;
array[1].name = "total_found";
array[1].type = SHOW_INT;
array[1].value = (char *) &pStats->m_iMatchesFound;
array[2].name = "time";
array[2].type = SHOW_INT;
array[2].value = (char *) &pStats->m_iQueryMsec;
array[3].name = "word_count";
array[3].type = SHOW_INT;
array[3].value = (char *) &pStats->m_iWords;
array[4].name = "error";
array[4].type = SHOW_CHAR;
array[4].value = (char *) &pStats->m_sLastMessage;
array[5].name = "words";
array[5].type = SHOW_CHAR;
array[5].value = sBuffer;
sBuffer[0] = 0;
if ( pStats->m_iWords ) if ( pTls && pTls->m_bStats )
return &pTls->m_tStats;
}
#else
CSphSEThreadData *pTls = (CSphSEThreadData *) thd->ha_data[sphinx_hton.slot];
if ( pTls && pTls->m_bStats )
return &pTls->m_tStats;
#endif
out->type = SHOW_CHAR;
out->value = (char*) "";
return 0;
}
int sphinx_showfunc_total ( THD * thd, SHOW_VAR * out, char * )
{
CSphSEStats * pStats = sphinx_get_stats ( thd, out );
if ( pStats )
{
out->type = SHOW_INT;
out->value = (char *) &pStats->m_iMatchesTotal;
}
return 0;
}
int sphinx_showfunc_total_found ( THD * thd, SHOW_VAR * out, char * )
{
CSphSEStats * pStats = sphinx_get_stats ( thd, out );
if ( pStats )
{
out->type = SHOW_INT;
out->value = (char *) &pStats->m_iMatchesFound;
}
return 0;
}
int sphinx_showfunc_time ( THD * thd, SHOW_VAR * out, char * )
{
CSphSEStats * pStats = sphinx_get_stats ( thd, out );
if ( pStats )
{
out->type = SHOW_INT;
out->value = (char *) &pStats->m_iQueryMsec;
}
return 0;
}
int sphinx_showfunc_word_count ( THD * thd, SHOW_VAR * out, char * )
{
CSphSEStats * pStats = sphinx_get_stats ( thd, out );
if ( pStats )
{
out->type = SHOW_INT;
out->value = (char *) &pStats->m_iWords;
}
return 0;
}
int sphinx_showfunc_words ( THD * thd, SHOW_VAR * out, char * sBuffer )
{
#if MYSQL_VERSION_ID>50100
if ( sphinx_hton_ptr )
{
CSphSEThreadData * pTls = (CSphSEThreadData *) *thd_ha_data ( thd, sphinx_hton_ptr );
#else
{
CSphSEThreadData * pTls = (CSphSEThreadData *) thd->ha_data[sphinx_hton.slot];
#endif
if ( pTls && pTls->m_bStats )
{
CSphSEStats * pStats = &pTls->m_tStats;
if ( pStats && pStats->m_iWords )
{ {
uint uBuffLen = 0; uint uBuffLen = 0;
out->type = SHOW_CHAR;
out->value = sBuffer;
// the following is partially based on code in sphinx_show_status() // the following is partially based on code in sphinx_show_status()
sBuffer[0] = 0;
for ( int i=0; i<pStats->m_iWords; i++ ) for ( int i=0; i<pStats->m_iWords; i++ )
{ {
CSphSEWordStats & tWord = pStats->m_dWords[i]; CSphSEWordStats & tWord = pStats->m_dWords[i];
...@@ -3056,12 +3562,25 @@ static int sphinx_showfunc ( THD * thd, SHOW_VAR * out, char * sBuffer ) ...@@ -3056,12 +3562,25 @@ static int sphinx_showfunc ( THD * thd, SHOW_VAR * out, char * sBuffer )
memcpy ( sBuffer, sConvert.c_ptr(), sConvert.length() + 1 ); memcpy ( sBuffer, sConvert.c_ptr(), sConvert.length() + 1 );
} }
} }
return 0;
}
}
} }
array[6].name = 0; // terminate the array out->type = SHOW_CHAR;
out->value = (char*) "";
return 0;
}
int sphinx_showfunc_error ( THD * thd, SHOW_VAR * out, char * )
{
CSphSEStats * pStats = sphinx_get_stats ( thd, out );
if ( pStats && pStats->m_bLastError )
{
out->type = SHOW_CHAR;
out->value = pStats->m_sLastMessage;
} }
else
array[0].name = 0;
return 0; return 0;
} }
...@@ -3073,10 +3592,16 @@ struct st_mysql_storage_engine sphinx_storage_engine = ...@@ -3073,10 +3592,16 @@ struct st_mysql_storage_engine sphinx_storage_engine =
struct st_mysql_show_var sphinx_status_vars[] = struct st_mysql_show_var sphinx_status_vars[] =
{ {
{"sphinx", (char *)sphinx_showfunc, SHOW_FUNC}, {"sphinx_total", (char *)sphinx_showfunc_total, SHOW_FUNC},
{"sphinx_total_found", (char *)sphinx_showfunc_total_found, SHOW_FUNC},
{"sphinx_time", (char *)sphinx_showfunc_time, SHOW_FUNC},
{"sphinx_word_count", (char *)sphinx_showfunc_word_count, SHOW_FUNC},
{"sphinx_words", (char *)sphinx_showfunc_words, SHOW_FUNC},
{"sphinx_error", (char *)sphinx_showfunc_error, SHOW_FUNC},
{0, 0, (enum_mysql_show_type)0} {0, 0, (enum_mysql_show_type)0}
}; };
maria_declare_plugin(sphinx) maria_declare_plugin(sphinx)
{ {
MYSQL_STORAGE_ENGINE_PLUGIN, MYSQL_STORAGE_ENGINE_PLUGIN,
...@@ -3098,5 +3623,5 @@ maria_declare_plugin_end; ...@@ -3098,5 +3623,5 @@ maria_declare_plugin_end;
#endif // >50100 #endif // >50100
// //
// $Id: ha_sphinx.cc 2058 2009-11-07 04:01:57Z shodan $ // $Id: ha_sphinx.cc 3133 2012-03-01 13:47:52Z shodan $
// //
// //
// $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 @@ class ha_sphinx : public handler ...@@ -48,18 +49,19 @@ class ha_sphinx : public handler
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
...@@ -78,15 +80,16 @@ class ha_sphinx : public handler ...@@ -78,15 +80,16 @@ class ha_sphinx : public handler
#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
...@@ -123,7 +126,7 @@ class ha_sphinx : public handler ...@@ -123,7 +126,7 @@ class ha_sphinx : public handler
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 @@ class ha_sphinx : public handler ...@@ -140,12 +143,15 @@ class ha_sphinx : public handler
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 @@ class ha_sphinx : public handler ...@@ -155,6 +161,12 @@ class ha_sphinx : public handler
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 $
// //
// //
// $Id: snippets_udf.cc 2058 2009-11-07 04:01:57Z shodan $ // $Id: snippets_udf.cc 3087 2012-01-30 23:07:35Z shodan $
// //
// //
// Copyright (c) 2001-2008, Andrew Aksyonoff. All rights reserved. // Copyright (c) 2001-2012, Andrew Aksyonoff
// Copyright (c) 2008-2012, Sphinx Technologies Inc
// All rights reserved
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have // it under the terms of the GNU General Public License. You should have
...@@ -11,29 +13,25 @@ ...@@ -11,29 +13,25 @@
// did not, you can find it at http://www.gnu.org/ // did not, you can find it at http://www.gnu.org/
// //
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/un.h>
#include <netdb.h>
#include <mysql_version.h> #include <mysql_version.h>
#if MYSQL_VERSION_ID>50100 #if MYSQL_VERSION_ID>50100
#include "mysql_priv.h"
#include <mysql/plugin.h> #include <mysql/plugin.h>
#else #else
#include "../mysql_priv.h" #include "../mysql_priv.h"
#endif #endif
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/un.h>
#include <netdb.h>
#include <mysys_err.h> #include <mysys_err.h>
#include <my_sys.h> #include <my_sys.h>
#include <mysqld_error.h>
#include <my_net.h>
#include <mysql_com.h>
#if MYSQL_VERSION_ID>=50120 #if MYSQL_VERSION_ID>=50120
typedef uchar byte; typedef uchar byte;
#endif #endif
...@@ -120,7 +118,7 @@ static bool sphSend ( int iFd, const char * pBuffer, int iSize, bool bReportErro ...@@ -120,7 +118,7 @@ static bool sphSend ( int iFd, const char * pBuffer, int iSize, bool bReportErro
assert ( iSize > 0 ); assert ( iSize > 0 );
const int iResult = send ( iFd, pBuffer, iSize, 0 ); const int iResult = send ( iFd, pBuffer, iSize, 0 );
if ( iResult != iSize ) if ( iResult!=iSize )
{ {
if ( bReportErrors ) sphShowErrno("send"); if ( bReportErrors ) sphShowErrno("send");
return false; return false;
...@@ -140,14 +138,12 @@ static bool sphRecv ( int iFd, char * pBuffer, int iSize, bool bReportErrors = f ...@@ -140,14 +138,12 @@ static bool sphRecv ( int iFd, char * pBuffer, int iSize, bool bReportErrors = f
{ {
iSize -= iResult; iSize -= iResult;
pBuffer += iSize; pBuffer += iSize;
} } else if ( iResult==0 )
else if ( iResult == 0 )
{ {
if ( bReportErrors ) if ( bReportErrors )
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), "recv() failed: disconnected" ); my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), "recv() failed: disconnected" );
return false; return false;
} } else
else
{ {
if ( bReportErrors ) sphShowErrno("recv"); if ( bReportErrors ) sphShowErrno("recv");
return false; return false;
...@@ -160,11 +156,9 @@ enum ...@@ -160,11 +156,9 @@ enum
{ {
SPHINX_SEARCHD_PROTO = 1, SPHINX_SEARCHD_PROTO = 1,
SEARCHD_COMMAND_SEARCH = 0,
SEARCHD_COMMAND_EXCERPT = 1, SEARCHD_COMMAND_EXCERPT = 1,
VER_COMMAND_SEARCH = 0x116, VER_COMMAND_EXCERPT = 0x103,
VER_COMMAND_EXCERPT = 0x100,
}; };
/// known answers /// known answers
...@@ -191,7 +185,7 @@ class CSphBuffer ...@@ -191,7 +185,7 @@ class CSphBuffer
char * m_pCurrent; char * m_pCurrent;
public: public:
CSphBuffer ( const int iSize ) explicit CSphBuffer ( const int iSize )
: m_bOverrun ( false ) : m_bOverrun ( false )
, m_iSize ( iSize ) , m_iSize ( iSize )
, m_iLeft ( iSize ) , m_iLeft ( iSize )
...@@ -203,22 +197,22 @@ class CSphBuffer ...@@ -203,22 +197,22 @@ class CSphBuffer
~CSphBuffer () ~CSphBuffer ()
{ {
SafeDelete ( m_pBuffer ); SafeDeleteArray ( m_pBuffer );
} }
const char * Ptr() const { return m_pBuffer; } const char * Ptr() const { return m_pBuffer; }
bool Finalize() bool Finalize()
{ {
return !( m_bOverrun || m_iLeft != 0 || m_pCurrent - m_pBuffer != m_iSize ); return !( m_bOverrun || m_iLeft!=0 || ( m_pCurrent - m_pBuffer )!=m_iSize );
} }
void SendBytes ( const void * pBytes, int iBytes ); void SendBytes ( const void * pBytes, int iBytes );
void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(v) ); } void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(v) ); } // NOLINT
void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(v) ); } void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(v) ); }
void SendDword ( DWORD v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(v) ); } void SendDword ( DWORD v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(v) ); }
void SendUint64 ( ulonglong v ) { SendDword ( uint(v>>32) ); SendDword ( uint(v&0xFFFFFFFFUL) ); } void SendUint64 ( ulonglong v ) { SendDword ( uint ( v>>32 ) ); SendDword ( uint ( v&0xFFFFFFFFUL ) ); }
void SendString ( const char * v ) { SendString ( v, strlen(v) ); } void SendString ( const char * v ) { SendString ( v, strlen(v) ); }
void SendString ( const char * v, int iLen ) { SendDword(iLen); SendBytes ( v, iLen ); } void SendString ( const char * v, int iLen ) { SendDword(iLen); SendBytes ( v, iLen ); }
void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); } void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); }
...@@ -252,9 +246,9 @@ struct CSphUrl ...@@ -252,9 +246,9 @@ struct CSphUrl
CSphUrl() CSphUrl()
: m_sBuffer ( NULL ) : m_sBuffer ( NULL )
, m_sFormatted ( NULL ) , m_sFormatted ( NULL )
, m_sScheme ( (char*) SPHINXSE_DEFAULT_SCHEME ) , m_sScheme ( SPHINXSE_DEFAULT_SCHEME )
, m_sHost ( (char*) SPHINXSE_DEFAULT_HOST ) , m_sHost ( SPHINXSE_DEFAULT_HOST )
, m_sIndex ( (char*) SPHINXSE_DEFAULT_INDEX ) , m_sIndex ( SPHINXSE_DEFAULT_INDEX )
, m_iPort ( SPHINXSE_DEFAULT_PORT ) , m_iPort ( SPHINXSE_DEFAULT_PORT )
{} {}
...@@ -310,17 +304,17 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen ) ...@@ -310,17 +304,17 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen )
// unix-domain socket // unix-domain socket
m_iPort = 0; m_iPort = 0;
if (!( m_sIndex = strrchr ( m_sHost, ':' ) )) if (!( m_sIndex = strrchr ( m_sHost, ':' ) ))
m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX; m_sIndex = SPHINXSE_DEFAULT_INDEX;
else else
{ {
*m_sIndex++ = '\0'; *m_sIndex++ = '\0';
if ( !*m_sIndex ) if ( !*m_sIndex )
m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX; m_sIndex = SPHINXSE_DEFAULT_INDEX;
} }
bOk = true; bOk = true;
break; break;
} }
if( strcmp ( m_sScheme, "sphinx" ) != 0 && strcmp ( m_sScheme, "inet" ) != 0 ) if ( strcmp ( m_sScheme, "sphinx" )!=0 && strcmp ( m_sScheme, "inet" )!=0 )
break; break;
// inet // inet
...@@ -335,7 +329,7 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen ) ...@@ -335,7 +329,7 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen )
if ( m_sIndex ) if ( m_sIndex )
*m_sIndex++ = '\0'; *m_sIndex++ = '\0';
else else
m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX; m_sIndex = SPHINXSE_DEFAULT_INDEX;
m_iPort = atoi(sPort); m_iPort = atoi(sPort);
if ( !m_iPort ) if ( !m_iPort )
...@@ -347,7 +341,7 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen ) ...@@ -347,7 +341,7 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen )
if ( m_sIndex ) if ( m_sIndex )
*m_sIndex++ = '\0'; *m_sIndex++ = '\0';
else else
m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX; m_sIndex = SPHINXSE_DEFAULT_INDEX;
} }
bOk = true; bOk = true;
...@@ -378,10 +372,10 @@ int CSphUrl::Connect() ...@@ -378,10 +372,10 @@ int CSphUrl::Connect()
memset ( &sin, 0, sizeof(sin) ); memset ( &sin, 0, sizeof(sin) );
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = htons(m_iPort); sin.sin_port = htons ( m_iPort );
// resolve address // resolve address
if ( (int)( ip_addr=inet_addr(m_sHost) ) != (int)INADDR_NONE ) if ( (int)( ip_addr = inet_addr ( m_sHost ) )!=(int)INADDR_NONE )
memcpy ( &sin.sin_addr, &ip_addr, sizeof(ip_addr) ); memcpy ( &sin.sin_addr, &ip_addr, sizeof(ip_addr) );
else else
{ {
...@@ -389,8 +383,7 @@ int CSphUrl::Connect() ...@@ -389,8 +383,7 @@ int CSphUrl::Connect()
struct hostent tmp_hostent, *hp; struct hostent tmp_hostent, *hp;
char buff2 [ GETHOSTBYNAME_BUFF_SIZE ]; char buff2 [ GETHOSTBYNAME_BUFF_SIZE ];
hp = my_gethostbyname_r ( m_sHost, &tmp_hostent, hp = my_gethostbyname_r ( m_sHost, &tmp_hostent, buff2, sizeof(buff2), &tmp_errno );
buff2, sizeof(buff2), &tmp_errno );
if ( !hp ) if ( !hp )
{ {
my_gethostbyname_r_free(); my_gethostbyname_r_free();
...@@ -405,8 +398,7 @@ int CSphUrl::Connect() ...@@ -405,8 +398,7 @@ int CSphUrl::Connect()
memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) ); memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) );
my_gethostbyname_r_free(); my_gethostbyname_r_free();
} }
} } else
else
{ {
#ifndef __WIN__ #ifndef __WIN__
iDomain = AF_UNIX; iDomain = AF_UNIX;
...@@ -426,17 +418,17 @@ int CSphUrl::Connect() ...@@ -426,17 +418,17 @@ int CSphUrl::Connect()
uint uServerVersion; uint uServerVersion;
uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO ); uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO );
int iSocket = -1; int iSocket = -1;
const char * pError = NULL; char * pError = NULL;
do do
{ {
iSocket = socket ( iDomain, SOCK_STREAM, 0 ); iSocket = socket ( iDomain, SOCK_STREAM, 0 );
if ( iSocket == -1 ) if ( iSocket==-1 )
{ {
pError = "Failed to create client socket"; pError = "Failed to create client socket";
break; break;
} }
if ( connect ( iSocket, pSockaddr, iSockaddrSize ) == -1) if ( connect ( iSocket, pSockaddr, iSockaddrSize )==-1 )
{ {
pError = "Failed to connect to searchd"; pError = "Failed to connect to searchd";
break; break;
...@@ -464,7 +456,7 @@ int CSphUrl::Connect() ...@@ -464,7 +456,7 @@ int CSphUrl::Connect()
snprintf ( sError, sizeof(sError), "%s [%d] %s", Format(), errno, strerror(errno) ); snprintf ( sError, sizeof(sError), "%s [%d] %s", Format(), errno, strerror(errno) );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError ); my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
if ( iSocket != -1 ) if ( iSocket!=-1 )
close ( iSocket ); close ( iSocket );
return -1; return -1;
...@@ -483,7 +475,7 @@ struct CSphResponse ...@@ -483,7 +475,7 @@ struct CSphResponse
, m_pBody ( NULL ) , m_pBody ( NULL )
{} {}
CSphResponse ( DWORD uSize ) explicit CSphResponse ( DWORD uSize )
: m_pBody ( NULL ) : m_pBody ( NULL )
{ {
m_pBuffer = new char[uSize]; m_pBuffer = new char[uSize];
...@@ -508,10 +500,10 @@ CSphResponse::Read ( int iSocket, int iClientVersion ) ...@@ -508,10 +500,10 @@ CSphResponse::Read ( int iSocket, int iClientVersion )
int iVersion = ntohs ( sphUnalignedRead ( *(short int *) &sHeader[2] ) ); int iVersion = ntohs ( sphUnalignedRead ( *(short int *) &sHeader[2] ) );
DWORD uLength = ntohl ( sphUnalignedRead ( *(DWORD *) &sHeader[4] ) ); DWORD uLength = ntohl ( sphUnalignedRead ( *(DWORD *) &sHeader[4] ) );
if ( iVersion < iClientVersion ) // fixme: warn if ( iVersion<iClientVersion )
{} return NULL;
if ( uLength <= SPHINXSE_MAX_ALLOC ) if ( uLength<=SPHINXSE_MAX_ALLOC )
{ {
CSphResponse * pResponse = new CSphResponse ( uLength ); CSphResponse * pResponse = new CSphResponse ( uLength );
if ( !sphRecv ( iSocket, pResponse->m_pBuffer, uLength ) ) if ( !sphRecv ( iSocket, pResponse->m_pBuffer, uLength ) )
...@@ -521,16 +513,17 @@ CSphResponse::Read ( int iSocket, int iClientVersion ) ...@@ -521,16 +513,17 @@ CSphResponse::Read ( int iSocket, int iClientVersion )
} }
pResponse->m_pBody = pResponse->m_pBuffer; pResponse->m_pBody = pResponse->m_pBuffer;
if ( iStatus != SEARCHD_OK ) if ( iStatus!=SEARCHD_OK )
{ {
DWORD uSize = ntohl ( *(DWORD *)pResponse->m_pBuffer ); DWORD uSize = ntohl ( *(DWORD *)pResponse->m_pBuffer );
if ( iStatus == SEARCHD_WARNING ) if ( iStatus==SEARCHD_WARNING )
{
pResponse->m_pBody += uSize; // fixme: report the warning somehow pResponse->m_pBody += uSize; // fixme: report the warning somehow
else } else
{ {
char * sMessage = sphDup ( pResponse->m_pBuffer + sizeof(DWORD), uSize ); char * sMessage = sphDup ( pResponse->m_pBuffer + sizeof(DWORD), uSize );
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), sMessage ); my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), sMessage );
SafeDelete ( sMessage ); SafeDeleteArray ( sMessage );
SafeDelete ( pResponse ); SafeDelete ( pResponse );
return NULL; return NULL;
} }
...@@ -560,8 +553,13 @@ struct CSphSnippets ...@@ -560,8 +553,13 @@ struct CSphSnippets
int m_iBeforeMatch; int m_iBeforeMatch;
int m_iAfterMatch; int m_iAfterMatch;
int m_iChunkSeparator; int m_iChunkSeparator;
int m_iStripMode;
int m_iPassageBoundary;
int m_iLimit; int m_iLimit;
int m_iLimitWords;
int m_iLimitPassages;
int m_iAround; int m_iAround;
int m_iPassageId;
int m_iFlags; int m_iFlags;
CSphSnippets() CSphSnippets()
...@@ -569,9 +567,14 @@ struct CSphSnippets ...@@ -569,9 +567,14 @@ struct CSphSnippets
, m_iBeforeMatch(0) , m_iBeforeMatch(0)
, m_iAfterMatch(0) , m_iAfterMatch(0)
, m_iChunkSeparator(0) , m_iChunkSeparator(0)
, m_iStripMode(0)
, m_iPassageBoundary(0)
// defaults // defaults
, m_iLimit(256) , m_iLimit(256)
, m_iLimitWords(0)
, m_iLimitPassages(0)
, m_iAround(5) , m_iAround(5)
, m_iPassageId(1)
, m_iFlags(1) , m_iFlags(1)
{ {
} }
...@@ -582,10 +585,10 @@ struct CSphSnippets ...@@ -582,10 +585,10 @@ struct CSphSnippets
} }
}; };
#define KEYWORD(NAME) else if ( strncmp ( NAME, pArgs->attributes[i], pArgs->attribute_lengths[i] ) == 0 ) #define KEYWORD(NAME) else if ( strncmp ( NAME, pArgs->attributes[i], pArgs->attribute_lengths[i] )==0 )
#define CHECK_TYPE(TYPE) \ #define CHECK_TYPE(TYPE) \
if ( pArgs->arg_type[i] != TYPE ) \ if ( pArgs->arg_type[i]!=TYPE ) \
{ \ { \
snprintf ( sMessage, MAX_MESSAGE_LENGTH, \ snprintf ( sMessage, MAX_MESSAGE_LENGTH, \
"%.*s argument must be a string", \ "%.*s argument must be a string", \
...@@ -594,7 +597,7 @@ struct CSphSnippets ...@@ -594,7 +597,7 @@ struct CSphSnippets
bFail = true; \ bFail = true; \
break; \ break; \
} \ } \
if ( TYPE == STRING_RESULT && !pArgs->args[i] ) \ if ( TYPE==STRING_RESULT && !pArgs->args[i] ) \
{ \ { \
snprintf ( sMessage, MAX_MESSAGE_LENGTH, \ snprintf ( sMessage, MAX_MESSAGE_LENGTH, \
"%.*s argument must be constant (and not NULL)", \ "%.*s argument must be constant (and not NULL)", \
...@@ -621,7 +624,7 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag ...@@ -621,7 +624,7 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag
{ {
if ( i < 3 ) if ( i < 3 )
{ {
if ( pArgs->arg_type[i] != STRING_RESULT ) if ( pArgs->arg_type[i]!=STRING_RESULT )
{ {
strncpy ( sMessage, "first three arguments must be of string type", MAX_MESSAGE_LENGTH ); strncpy ( sMessage, "first three arguments must be of string type", MAX_MESSAGE_LENGTH );
bFail = true; bFail = true;
...@@ -641,12 +644,24 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag ...@@ -641,12 +644,24 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag
KEYWORD("before_match") { STRING; pOpts->m_iBeforeMatch = i; } KEYWORD("before_match") { STRING; pOpts->m_iBeforeMatch = i; }
KEYWORD("after_match") { STRING; pOpts->m_iAfterMatch = i; } KEYWORD("after_match") { STRING; pOpts->m_iAfterMatch = i; }
KEYWORD("chunk_separator") { STRING; pOpts->m_iChunkSeparator = i; } KEYWORD("chunk_separator") { STRING; pOpts->m_iChunkSeparator = i; }
KEYWORD("html_strip_mode") { STRING; pOpts->m_iStripMode = i; }
KEYWORD("passage_boundary") { STRING; pOpts->m_iPassageBoundary = i; }
KEYWORD("limit") { INT; pOpts->m_iLimit = iValue; } KEYWORD("limit") { INT; pOpts->m_iLimit = iValue; }
KEYWORD("limit_words") { INT; pOpts->m_iLimitWords = iValue; }
KEYWORD("limit_passages") { INT; pOpts->m_iLimitPassages = iValue; }
KEYWORD("around") { INT; pOpts->m_iAround = iValue; } KEYWORD("around") { INT; pOpts->m_iAround = iValue; }
KEYWORD("start_passage_id") { INT; pOpts->m_iPassageId = iValue; }
KEYWORD("exact_phrase") { INT; if ( iValue ) pOpts->m_iFlags |= 2; } KEYWORD("exact_phrase") { INT; if ( iValue ) pOpts->m_iFlags |= 2; }
KEYWORD("single_passage") { INT; if ( iValue ) pOpts->m_iFlags |= 4; } KEYWORD("single_passage") { INT; if ( iValue ) pOpts->m_iFlags |= 4; }
KEYWORD("use_boundaries") { INT; if ( iValue ) pOpts->m_iFlags |= 8; } KEYWORD("use_boundaries") { INT; if ( iValue ) pOpts->m_iFlags |= 8; }
KEYWORD("weight_order") { INT; if ( iValue ) pOpts->m_iFlags |= 16; } KEYWORD("weight_order") { INT; if ( iValue ) pOpts->m_iFlags |= 16; }
KEYWORD("query_mode") { INT; if ( iValue ) pOpts->m_iFlags |= 32; }
KEYWORD("force_all_words") { INT; if ( iValue ) pOpts->m_iFlags |= 64; }
KEYWORD("load_files") { INT; if ( iValue ) pOpts->m_iFlags |= 128; }
KEYWORD("allow_empty") { INT; if ( iValue ) pOpts->m_iFlags |= 256; }
KEYWORD("emit_zones") { INT; if ( iValue ) pOpts->m_iFlags |= 512; }
else else
{ {
snprintf ( sMessage, MAX_MESSAGE_LENGTH, "unrecognized argument: %.*s", snprintf ( sMessage, MAX_MESSAGE_LENGTH, "unrecognized argument: %.*s",
...@@ -691,15 +706,14 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi ...@@ -691,15 +706,14 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
return sResult; return sResult;
} }
const int iSize = const int iSize = 68 +
8 + // header pArgs->lengths[1] + // index
8 + pArgs->lengths[2] + // words
4 + pArgs->lengths[1] + // index ARG_LEN ( pOpts->m_iBeforeMatch, 3 ) +
4 + pArgs->lengths[2] + // words ARG_LEN ( pOpts->m_iAfterMatch, 4 ) +
4 + ARG_LEN ( pOpts->m_iBeforeMatch, 3 ) + ARG_LEN ( pOpts->m_iChunkSeparator, 5 ) +
4 + ARG_LEN ( pOpts->m_iAfterMatch, 4 ) + ARG_LEN ( pOpts->m_iStripMode, 5 ) +
4 + ARG_LEN ( pOpts->m_iChunkSeparator, 5 ) + ARG_LEN ( pOpts->m_iPassageBoundary, 0 ) +
12 +
4 + pArgs->lengths[0]; // document 4 + pArgs->lengths[0]; // document
CSphBuffer tBuffer(iSize); CSphBuffer tBuffer(iSize);
...@@ -721,6 +735,13 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi ...@@ -721,6 +735,13 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
tBuffer.SendInt ( pOpts->m_iLimit ); tBuffer.SendInt ( pOpts->m_iLimit );
tBuffer.SendInt ( pOpts->m_iAround ); tBuffer.SendInt ( pOpts->m_iAround );
tBuffer.SendInt ( pOpts->m_iLimitPassages );
tBuffer.SendInt ( pOpts->m_iLimitWords );
tBuffer.SendInt ( pOpts->m_iPassageId );
SEND_STRING ( pOpts->m_iStripMode, "index" );
SEND_STRING ( pOpts->m_iPassageBoundary, "" );
// single document // single document
tBuffer.SendInt ( 1 ); tBuffer.SendInt ( 1 );
tBuffer.SendString ( ARG(0) ); tBuffer.SendString ( ARG(0) );
...@@ -735,20 +756,20 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi ...@@ -735,20 +756,20 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
} }
iSocket = pOpts->m_tUrl.Connect(); iSocket = pOpts->m_tUrl.Connect();
if ( iSocket == -1 ) break; if ( iSocket==-1 ) break;
if ( !sphSend ( iSocket, tBuffer.Ptr(), iSize, sphReportErrors ) ) break; if ( !sphSend ( iSocket, tBuffer.Ptr(), iSize, sphReportErrors ) ) break;
CSphResponse * pResponse = CSphResponse::Read ( iSocket, 0x100 ); CSphResponse * pResponse = CSphResponse::Read ( iSocket, VER_COMMAND_EXCERPT );
if ( !pResponse ) break; if ( !pResponse ) break;
close ( iSocket ); close ( iSocket );
pOpts->m_pResponse = pResponse; pOpts->m_pResponse = pResponse;
*pLength = ntohl( *(DWORD *)pResponse->m_pBody ); *pLength = ntohl ( *(DWORD *)pResponse->m_pBody );
return pResponse->m_pBody + sizeof(DWORD); return pResponse->m_pBody + sizeof(DWORD);
} }
while(0); while(0);
if ( iSocket != -1 ) if ( iSocket!=-1 )
close ( iSocket ); close ( iSocket );
*pError = 1; *pError = 1;
...@@ -766,5 +787,5 @@ void sphinx_snippets_deinit ( UDF_INIT * pUDF ) ...@@ -766,5 +787,5 @@ void sphinx_snippets_deinit ( UDF_INIT * pUDF )
} }
// //
// $Id: snippets_udf.cc 2058 2009-11-07 04:01:57Z shodan $ // $Id: snippets_udf.cc 3087 2012-01-30 23:07:35Z shodan $
// //
diff -B -N -r -u mysql-5.0.22/config/ac-macros/ha_sphinx.m4 mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4
--- mysql-5.0.22/config/ac-macros/ha_sphinx.m4 1970-01-01 01:00:00.000000000 +0100
+++ mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4 2006-06-06 19:49:38.000000000 +0200
@@ -0,0 +1,30 @@
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_CHECK_EXAMPLEDB
+dnl Sets HAVE_SPHINX_DB if --with-sphinx-storage-engine is used
+dnl ---------------------------------------------------------------------------
+AC_DEFUN([MYSQL_CHECK_SPHINXDB], [
+ AC_ARG_WITH([sphinx-storage-engine],
+ [
+ --with-sphinx-storage-engine
+ Enable the Sphinx Storage Engine],
+ [sphinxdb="$withval"],
+ [sphinxdb=no])
+ AC_MSG_CHECKING([for example storage engine])
+
+ case "$sphinxdb" in
+ yes )
+ AC_DEFINE([HAVE_SPHINX_DB], [1], [Builds Sphinx Engine])
+ AC_MSG_RESULT([yes])
+ [sphinxdb=yes]
+ ;;
+ * )
+ AC_MSG_RESULT([no])
+ [sphinxdb=no]
+ ;;
+ esac
+
+])
+dnl ---------------------------------------------------------------------------
+dnl END OF MYSQL_CHECK_EXAMPLE SECTION
+dnl ---------------------------------------------------------------------------
+
diff -B -N -r -u mysql-5.0.22/configure.in mysql-5.0.22.sx/configure.in
--- mysql-5.0.22/configure.in 2006-05-25 10:56:45.000000000 +0200
+++ mysql-5.0.22.sx/configure.in 2006-06-06 19:49:38.000000000 +0200
@@ -41,6 +41,7 @@
sinclude(config/ac-macros/ha_berkeley.m4)
sinclude(config/ac-macros/ha_blackhole.m4)
sinclude(config/ac-macros/ha_example.m4)
+sinclude(config/ac-macros/ha_sphinx.m4)
sinclude(config/ac-macros/ha_federated.m4)
sinclude(config/ac-macros/ha_innodb.m4)
sinclude(config/ac-macros/ha_ndbcluster.m4)
@@ -2450,6 +2451,7 @@
MYSQL_CHECK_BDB
MYSQL_CHECK_INNODB
MYSQL_CHECK_EXAMPLEDB
+MYSQL_CHECK_SPHINXDB
MYSQL_CHECK_ARCHIVEDB
MYSQL_CHECK_CSVDB
MYSQL_CHECK_BLACKHOLEDB
diff -B -N -r -u mysql-5.0.22/libmysqld/Makefile.am mysql-5.0.22.sx/libmysqld/Makefile.am
--- mysql-5.0.22/libmysqld/Makefile.am 2006-05-25 10:56:55.000000000 +0200
+++ mysql-5.0.22.sx/libmysqld/Makefile.am 2006-06-06 19:49:38.000000000 +0200
@@ -27,7 +27,7 @@
-DSHAREDIR="\"$(MYSQLSHAREdir)\""
INCLUDES= @bdb_includes@ \
-I$(top_builddir)/include -I$(top_srcdir)/include \
- -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples \
+ -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples -I$(top_srcdir)/sql/sphinx \
-I$(top_srcdir)/regex \
$(openssl_includes) $(yassl_includes) @ZLIB_INCLUDES@
@@ -38,6 +38,7 @@
libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \
my_time.c
sqlexamplessources = ha_example.cc ha_tina.cc
+sqlsphinxsources = ha_sphinx.cc
noinst_HEADERS = embedded_priv.h emb_qcache.h
@@ -65,7 +66,7 @@
parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
ha_blackhole.cc ha_archive.cc my_user.c
-libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources)
+libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) $(sqlsphinxsources)
libmysqld_a_SOURCES=
# automake misses these
@@ -133,12 +134,16 @@
rm -f $$f; \
@LN_CP_F@ $(top_srcdir)/sql/examples/$$f $$f; \
done; \
+ for f in $(sqlsphinxsources); do \
+ rm -f $$f; \
+ @LN_CP_F@ $(top_srcdir)/sql/sphinx/$$f $$f; \
+ done; \
rm -f client_settings.h; \
@LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h
clean-local:
- rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) | sed "s;\.lo;.c;g"` \
+ rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) $(sqlsphinxsources) | sed "s;\.lo;.c;g"` \
$(top_srcdir)/linked_libmysqld_sources; \
rm -f client_settings.h
diff -B -N -r -u mysql-5.0.22/sql/handler.cc mysql-5.0.22.sx/sql/handler.cc
--- mysql-5.0.22/sql/handler.cc 2006-05-25 10:56:42.000000000 +0200
+++ mysql-5.0.22.sx/sql/handler.cc 2006-06-06 19:49:38.000000000 +0200
@@ -78,6 +78,15 @@
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+extern handlerton sphinx_hton;
+#else
+handlerton sphinx_hton = { "SPHINX", SHOW_OPTION_NO, "SPHINX storage engine",
+ DB_TYPE_SPHINX_DB, NULL, 0, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ HTON_NO_FLAGS };
+#endif
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
extern handlerton innobase_hton;
@@ -147,6 +156,7 @@
&example_hton,
&archive_hton,
&tina_hton,
+ &sphinx_hton,
&ndbcluster_hton,
&federated_hton,
&myisammrg_hton,
@@ -345,6 +355,12 @@
return new (alloc) ha_tina(table);
return NULL;
#endif
+#ifdef HAVE_SPHINX_DB
+ case DB_TYPE_SPHINX_DB:
+ if (have_sphinx_db == SHOW_OPTION_YES)
+ return new (alloc) ha_sphinx(table);
+ return NULL;
+#endif
#ifdef HAVE_NDBCLUSTER_DB
case DB_TYPE_NDBCLUSTER:
if (have_ndbcluster == SHOW_OPTION_YES)
diff -B -N -r -u mysql-5.0.22/sql/handler.h mysql-5.0.22.sx/sql/handler.h
--- mysql-5.0.22/sql/handler.h 2006-05-25 10:56:55.000000000 +0200
+++ mysql-5.0.22.sx/sql/handler.h 2006-06-06 19:49:38.000000000 +0200
@@ -183,8 +183,9 @@
DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
- DB_TYPE_FEDERATED_DB,
+ DB_TYPE_FEDERATED_DB,
DB_TYPE_BLACKHOLE_DB,
+ DB_TYPE_SPHINX_DB,
DB_TYPE_DEFAULT // Must be last
};
diff -B -N -r -u mysql-5.0.22/sql/Makefile.am mysql-5.0.22.sx/sql/Makefile.am
--- mysql-5.0.22/sql/Makefile.am 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/Makefile.am 2006-06-06 19:49:38.000000000 +0200
@@ -66,6 +66,7 @@
sql_array.h sql_cursor.h \
examples/ha_example.h ha_archive.h \
examples/ha_tina.h ha_blackhole.h \
+ sphinx/ha_sphinx.h \
ha_federated.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -102,6 +103,7 @@
sp_cache.cc parse_file.cc sql_trigger.cc \
examples/ha_example.cc ha_archive.cc \
examples/ha_tina.cc ha_blackhole.cc \
+ sphinx/ha_sphinx.cc \
ha_federated.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
diff -B -N -r -u mysql-5.0.22/sql/mysqld.cc mysql-5.0.22.sx/sql/mysqld.cc
--- mysql-5.0.22/sql/mysqld.cc 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/mysqld.cc 2006-06-06 19:49:38.000000000 +0200
@@ -6420,6 +6420,11 @@
#else
have_csv_db= SHOW_OPTION_NO;
#endif
+#ifdef HAVE_SPHINX_DB
+ have_sphinx_db= SHOW_OPTION_YES;
+#else
+ have_sphinx_db= SHOW_OPTION_NO;
+#endif
#ifdef HAVE_NDBCLUSTER_DB
have_ndbcluster=SHOW_OPTION_DISABLED;
#else
@@ -7457,6 +7462,7 @@
#undef have_example_db
#undef have_archive_db
#undef have_csv_db
+#undef have_sphinx_db
#undef have_federated_db
#undef have_partition_db
#undef have_blackhole_db
@@ -7467,6 +7473,7 @@
SHOW_COMP_OPTION have_example_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_archive_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
+SHOW_COMP_OPTION have_sphinx_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_federated_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_blackhole_db= SHOW_OPTION_NO;
diff -B -N -r -u mysql-5.0.22/sql/mysql_priv.h mysql-5.0.22.sx/sql/mysql_priv.h
--- mysql-5.0.22/sql/mysql_priv.h 2006-05-25 10:56:43.000000000 +0200
+++ mysql-5.0.22.sx/sql/mysql_priv.h 2006-06-06 19:49:38.000000000 +0200
@@ -1279,6 +1279,12 @@
#else
extern SHOW_COMP_OPTION have_csv_db;
#endif
+#ifdef HAVE_SPHINX_DB
+extern handlerton sphinx_hton;
+#define have_sphinx_db sphinx_hton.state
+#else
+extern SHOW_COMP_OPTION have_sphinx_db;
+#endif
#ifdef HAVE_FEDERATED_DB
extern handlerton federated_hton;
#define have_federated_db federated_hton.state
diff -B -N -r -u mysql-5.0.22/sql/set_var.cc mysql-5.0.22.sx/sql/set_var.cc
--- mysql-5.0.22/sql/set_var.cc 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/set_var.cc 2006-06-06 19:49:38.000000000 +0200
@@ -809,6 +809,7 @@
{"have_compress", (char*) &have_compress, SHOW_HAVE},
{"have_crypt", (char*) &have_crypt, SHOW_HAVE},
{"have_csv", (char*) &have_csv_db, SHOW_HAVE},
+ {"have_sphinx", (char*) &have_sphinx_db, SHOW_HAVE},
{"have_example_engine", (char*) &have_example_db, SHOW_HAVE},
{"have_federated_engine", (char*) &have_federated_db, SHOW_HAVE},
{"have_geometry", (char*) &have_geometry, SHOW_HAVE},
diff -B -N -r -u mysql-5.0.22/sql/sql_lex.h mysql-5.0.22.sx/sql/sql_lex.h
--- mysql-5.0.22/sql/sql_lex.h 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/sql_lex.h 2006-06-06 19:49:38.000000000 +0200
@@ -58,6 +58,7 @@
SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_NDBCLUSTER_STATUS, SQLCOM_SHOW_MUTEX_STATUS,
+ SQLCOM_SHOW_SPHINX_STATUS,
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
diff -B -N -r -u mysql-5.0.22/sql/sql_parse.cc mysql-5.0.22.sx/sql/sql_parse.cc
--- mysql-5.0.22/sql/sql_parse.cc 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/sql_parse.cc 2006-06-06 19:49:38.000000000 +0200
@@ -25,6 +25,9 @@
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+#endif
#ifdef HAVE_NDBCLUSTER_DB
#include "ha_ndbcluster.h"
@@ -2722,6 +2725,15 @@
break;
}
#endif
+#ifdef HAVE_SPHINX_DB
+ case SQLCOM_SHOW_SPHINX_STATUS:
+ {
+ if (check_global_access(thd, SUPER_ACL))
+ goto error;
+ res = sphinx_show_status(thd);
+ break;
+ }
+#endif
#ifdef HAVE_REPLICATION
case SQLCOM_LOAD_MASTER_TABLE:
{
diff -B -N -r -u mysql-5.0.22/sql/sql_yacc.yy mysql-5.0.22.sx/sql/sql_yacc.yy
--- mysql-5.0.22/sql/sql_yacc.yy 2006-05-25 10:56:43.000000000 +0200
+++ mysql-5.0.22.sx/sql/sql_yacc.yy 2006-06-06 19:49:38.000000000 +0200
@@ -6584,6 +6584,9 @@
case DB_TYPE_INNODB:
Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
break;
+ case DB_TYPE_SPHINX_DB:
+ Lex->sql_command = SQLCOM_SHOW_SPHINX_STATUS;
+ break;
default:
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
YYABORT;
diff -B -N -r -u mysql-5.0.22/config/ac-macros/ha_sphinx.m4 mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4
--- mysql-5.0.22/config/ac-macros/ha_sphinx.m4 1970-01-01 01:00:00.000000000 +0100
+++ mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4 2006-06-06 19:49:38.000000000 +0200
@@ -0,0 +1,30 @@
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_CHECK_EXAMPLEDB
+dnl Sets HAVE_SPHINX_DB if --with-sphinx-storage-engine is used
+dnl ---------------------------------------------------------------------------
+AC_DEFUN([MYSQL_CHECK_SPHINXDB], [
+ AC_ARG_WITH([sphinx-storage-engine],
+ [
+ --with-sphinx-storage-engine
+ Enable the Sphinx Storage Engine],
+ [sphinxdb="$withval"],
+ [sphinxdb=no])
+ AC_MSG_CHECKING([for example storage engine])
+
+ case "$sphinxdb" in
+ yes )
+ AC_DEFINE([HAVE_SPHINX_DB], [1], [Builds Sphinx Engine])
+ AC_MSG_RESULT([yes])
+ [sphinxdb=yes]
+ ;;
+ * )
+ AC_MSG_RESULT([no])
+ [sphinxdb=no]
+ ;;
+ esac
+
+])
+dnl ---------------------------------------------------------------------------
+dnl END OF MYSQL_CHECK_EXAMPLE SECTION
+dnl ---------------------------------------------------------------------------
+
diff -B -N -r -u mysql-5.0.22/configure.in mysql-5.0.22.sx/configure.in
--- mysql-5.0.22/configure.in 2006-05-25 10:56:45.000000000 +0200
+++ mysql-5.0.22.sx/configure.in 2006-06-06 19:49:38.000000000 +0200
@@ -41,6 +41,7 @@
sinclude(config/ac-macros/ha_berkeley.m4)
sinclude(config/ac-macros/ha_blackhole.m4)
sinclude(config/ac-macros/ha_example.m4)
+sinclude(config/ac-macros/ha_sphinx.m4)
sinclude(config/ac-macros/ha_federated.m4)
sinclude(config/ac-macros/ha_innodb.m4)
sinclude(config/ac-macros/ha_ndbcluster.m4)
@@ -2450,6 +2451,7 @@
MYSQL_CHECK_BDB
MYSQL_CHECK_INNODB
MYSQL_CHECK_EXAMPLEDB
+MYSQL_CHECK_SPHINXDB
MYSQL_CHECK_ARCHIVEDB
MYSQL_CHECK_CSVDB
MYSQL_CHECK_BLACKHOLEDB
diff -B -N -r -u mysql-5.0.22/libmysqld/Makefile.am mysql-5.0.22.sx/libmysqld/Makefile.am
--- mysql-5.0.22/libmysqld/Makefile.am 2006-05-25 10:56:55.000000000 +0200
+++ mysql-5.0.22.sx/libmysqld/Makefile.am 2006-06-06 19:49:38.000000000 +0200
@@ -27,7 +27,7 @@
-DSHAREDIR="\"$(MYSQLSHAREdir)\""
INCLUDES= @bdb_includes@ \
-I$(top_builddir)/include -I$(top_srcdir)/include \
- -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples \
+ -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples -I$(top_srcdir)/sql/sphinx \
-I$(top_srcdir)/regex \
$(openssl_includes) $(yassl_includes) @ZLIB_INCLUDES@
@@ -38,6 +38,7 @@
libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \
my_time.c
sqlexamplessources = ha_example.cc ha_tina.cc
+sqlsphinxsources = ha_sphinx.cc
noinst_HEADERS = embedded_priv.h emb_qcache.h
@@ -65,7 +66,7 @@
parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
ha_blackhole.cc ha_archive.cc my_user.c
-libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources)
+libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) $(sqlsphinxsources)
libmysqld_a_SOURCES=
# automake misses these
@@ -133,12 +134,16 @@
rm -f $$f; \
@LN_CP_F@ $(top_srcdir)/sql/examples/$$f $$f; \
done; \
+ for f in $(sqlsphinxsources); do \
+ rm -f $$f; \
+ @LN_CP_F@ $(top_srcdir)/sql/sphinx/$$f $$f; \
+ done; \
rm -f client_settings.h; \
@LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h
clean-local:
- rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) | sed "s;\.lo;.c;g"` \
+ rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) $(sqlsphinxsources) | sed "s;\.lo;.c;g"` \
$(top_srcdir)/linked_libmysqld_sources; \
rm -f client_settings.h
diff -B -N -r -u mysql-5.0.22/sql/handler.cc mysql-5.0.22.sx/sql/handler.cc
--- mysql-5.0.22/sql/handler.cc 2006-05-25 10:56:42.000000000 +0200
+++ mysql-5.0.22.sx/sql/handler.cc 2006-06-06 19:49:38.000000000 +0200
@@ -78,6 +78,15 @@
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+extern handlerton sphinx_hton;
+#else
+handlerton sphinx_hton = { "SPHINX", SHOW_OPTION_NO, "SPHINX storage engine",
+ DB_TYPE_SPHINX_DB, NULL, 0, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ HTON_NO_FLAGS };
+#endif
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
extern handlerton innobase_hton;
@@ -147,6 +156,7 @@
&example_hton,
&archive_hton,
&tina_hton,
+ &sphinx_hton,
&ndbcluster_hton,
&federated_hton,
&myisammrg_hton,
@@ -345,6 +355,12 @@
return new (alloc) ha_tina(table);
return NULL;
#endif
+#ifdef HAVE_SPHINX_DB
+ case DB_TYPE_SPHINX_DB:
+ if (have_sphinx_db == SHOW_OPTION_YES)
+ return new (alloc) ha_sphinx(table);
+ return NULL;
+#endif
#ifdef HAVE_NDBCLUSTER_DB
case DB_TYPE_NDBCLUSTER:
if (have_ndbcluster == SHOW_OPTION_YES)
diff -B -N -r -u mysql-5.0.22/sql/handler.h mysql-5.0.22.sx/sql/handler.h
--- mysql-5.0.22/sql/handler.h 2006-05-25 10:56:55.000000000 +0200
+++ mysql-5.0.22.sx/sql/handler.h 2006-06-06 19:49:38.000000000 +0200
@@ -183,8 +183,9 @@
DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
- DB_TYPE_FEDERATED_DB,
+ DB_TYPE_FEDERATED_DB,
DB_TYPE_BLACKHOLE_DB,
+ DB_TYPE_SPHINX_DB,
DB_TYPE_DEFAULT // Must be last
};
diff -B -N -r -u mysql-5.0.22/sql/Makefile.am mysql-5.0.22.sx/sql/Makefile.am
--- mysql-5.0.22/sql/Makefile.am 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/Makefile.am 2006-06-06 19:49:38.000000000 +0200
@@ -66,6 +66,7 @@
sql_array.h sql_cursor.h \
examples/ha_example.h ha_archive.h \
examples/ha_tina.h ha_blackhole.h \
+ sphinx/ha_sphinx.h \
ha_federated.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -102,6 +103,7 @@
sp_cache.cc parse_file.cc sql_trigger.cc \
examples/ha_example.cc ha_archive.cc \
examples/ha_tina.cc ha_blackhole.cc \
+ sphinx/ha_sphinx.cc \
ha_federated.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
diff -B -N -r -u mysql-5.0.22/sql/mysqld.cc mysql-5.0.22.sx/sql/mysqld.cc
--- mysql-5.0.22/sql/mysqld.cc 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/mysqld.cc 2006-06-06 19:49:38.000000000 +0200
@@ -6420,6 +6420,11 @@
#else
have_csv_db= SHOW_OPTION_NO;
#endif
+#ifdef HAVE_SPHINX_DB
+ have_sphinx_db= SHOW_OPTION_YES;
+#else
+ have_sphinx_db= SHOW_OPTION_NO;
+#endif
#ifdef HAVE_NDBCLUSTER_DB
have_ndbcluster=SHOW_OPTION_DISABLED;
#else
@@ -7457,6 +7462,7 @@
#undef have_example_db
#undef have_archive_db
#undef have_csv_db
+#undef have_sphinx_db
#undef have_federated_db
#undef have_partition_db
#undef have_blackhole_db
@@ -7467,6 +7473,7 @@
SHOW_COMP_OPTION have_example_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_archive_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
+SHOW_COMP_OPTION have_sphinx_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_federated_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_blackhole_db= SHOW_OPTION_NO;
diff -B -N -r -u mysql-5.0.22/sql/mysql_priv.h mysql-5.0.22.sx/sql/mysql_priv.h
--- mysql-5.0.22/sql/mysql_priv.h 2006-05-25 10:56:43.000000000 +0200
+++ mysql-5.0.22.sx/sql/mysql_priv.h 2006-06-06 19:49:38.000000000 +0200
@@ -1279,6 +1279,12 @@
#else
extern SHOW_COMP_OPTION have_csv_db;
#endif
+#ifdef HAVE_SPHINX_DB
+extern handlerton sphinx_hton;
+#define have_sphinx_db sphinx_hton.state
+#else
+extern SHOW_COMP_OPTION have_sphinx_db;
+#endif
#ifdef HAVE_FEDERATED_DB
extern handlerton federated_hton;
#define have_federated_db federated_hton.state
diff -B -N -r -u mysql-5.0.22/sql/set_var.cc mysql-5.0.22.sx/sql/set_var.cc
--- mysql-5.0.22/sql/set_var.cc 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/set_var.cc 2006-06-06 19:49:38.000000000 +0200
@@ -864,6 +864,7 @@
{"have_compress", (char*) &have_compress, SHOW_HAVE},
{"have_crypt", (char*) &have_crypt, SHOW_HAVE},
{"have_csv", (char*) &have_csv_db, SHOW_HAVE},
+ {"have_sphinx", (char*) &have_sphinx_db, SHOW_HAVE},
{"have_dynamic_loading", (char*) &have_dlopen, SHOW_HAVE},
{"have_example_engine", (char*) &have_example_db, SHOW_HAVE},
{"have_federated_engine", (char*) &have_federated_db, SHOW_HAVE},
diff -B -N -r -u mysql-5.0.22/sql/sql_lex.h mysql-5.0.22.sx/sql/sql_lex.h
--- mysql-5.0.22/sql/sql_lex.h 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/sql_lex.h 2006-06-06 19:49:38.000000000 +0200
@@ -58,6 +58,7 @@
SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_NDBCLUSTER_STATUS, SQLCOM_SHOW_MUTEX_STATUS,
+ SQLCOM_SHOW_SPHINX_STATUS,
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
diff -B -N -r -u mysql-5.0.22/sql/sql_parse.cc mysql-5.0.22.sx/sql/sql_parse.cc
--- mysql-5.0.22/sql/sql_parse.cc 2006-05-25 10:56:41.000000000 +0200
+++ mysql-5.0.22.sx/sql/sql_parse.cc 2006-06-06 19:49:38.000000000 +0200
@@ -25,6 +25,9 @@
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+#endif
#ifdef HAVE_NDBCLUSTER_DB
#include "ha_ndbcluster.h"
@@ -2722,6 +2725,15 @@
break;
}
#endif
+#ifdef HAVE_SPHINX_DB
+ case SQLCOM_SHOW_SPHINX_STATUS:
+ {
+ if (check_global_access(thd, SUPER_ACL))
+ goto error;
+ res = sphinx_show_status(thd);
+ break;
+ }
+#endif
#ifdef HAVE_REPLICATION
case SQLCOM_LOAD_MASTER_TABLE:
{
diff -B -N -r -u mysql-5.0.22/sql/sql_yacc.yy mysql-5.0.22.sx/sql/sql_yacc.yy
--- mysql-5.0.22/sql/sql_yacc.yy 2006-05-25 10:56:43.000000000 +0200
+++ mysql-5.0.22.sx/sql/sql_yacc.yy 2006-06-06 19:49:38.000000000 +0200
@@ -6584,6 +6584,9 @@
case DB_TYPE_INNODB:
Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
break;
+ case DB_TYPE_SPHINX_DB:
+ Lex->sql_command = SQLCOM_SHOW_SPHINX_STATUS;
+ break;
default:
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
YYABORT;
--- mysql-5.0.67/config/ac-macros/ha_sphinx.m4 1970-01-01 10:00:00.000000000 +1000
+++ mysql-5.0.67-sphinx/config/ac-macros/ha_sphinx.m4 2009-02-14 09:15:48.000000000 +1000
@@ -0,0 +1,30 @@
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_CHECK_EXAMPLEDB
+dnl Sets HAVE_SPHINX_DB if --with-sphinx-storage-engine is used
+dnl ---------------------------------------------------------------------------
+AC_DEFUN([MYSQL_CHECK_SPHINXDB], [
+ AC_ARG_WITH([sphinx-storage-engine],
+ [
+ --with-sphinx-storage-engine
+ Enable the Sphinx Storage Engine],
+ [sphinxdb="$withval"],
+ [sphinxdb=no])
+ AC_MSG_CHECKING([for example storage engine])
+
+ case "$sphinxdb" in
+ yes )
+ AC_DEFINE([HAVE_SPHINX_DB], [1], [Builds Sphinx Engine])
+ AC_MSG_RESULT([yes])
+ [sphinxdb=yes]
+ ;;
+ * )
+ AC_MSG_RESULT([no])
+ [sphinxdb=no]
+ ;;
+ esac
+
+])
+dnl ---------------------------------------------------------------------------
+dnl END OF MYSQL_CHECK_EXAMPLE SECTION
+dnl ---------------------------------------------------------------------------
+
--- mysql-5.0.67/configure.in 2008-08-04 23:19:07.000000000 +1100
+++ mysql-5.0.67-sphinx/configure.in 2009-02-14 09:15:48.000000000 +1000
@@ -58,6 +58,7 @@
sinclude(config/ac-macros/ha_berkeley.m4)
sinclude(config/ac-macros/ha_blackhole.m4)
sinclude(config/ac-macros/ha_example.m4)
+sinclude(config/ac-macros/ha_sphinx.m4)
sinclude(config/ac-macros/ha_federated.m4)
sinclude(config/ac-macros/ha_innodb.m4)
sinclude(config/ac-macros/ha_ndbcluster.m4)
@@ -2625,6 +2626,7 @@
MYSQL_CHECK_BDB
MYSQL_CHECK_INNODB
MYSQL_CHECK_EXAMPLEDB
+MYSQL_CHECK_SPHINXDB
MYSQL_CHECK_ARCHIVEDB
MYSQL_CHECK_CSVDB
MYSQL_CHECK_BLACKHOLEDB
--- mysql-5.0.67/libmysqld/Makefile.am 2008-08-04 23:19:18.000000000 +1100
+++ mysql-5.0.67-sphinx/libmysqld/Makefile.am 2009-02-14 09:15:48.000000000 +1000
@@ -29,6 +29,7 @@
-I$(top_builddir)/include -I$(top_srcdir)/include \
-I$(top_builddir)/sql -I$(top_srcdir)/sql \
-I$(top_srcdir)/sql/examples \
+ -I$(top_srcdir)/sql/sphinx \
-I$(top_srcdir)/regex \
$(openssl_includes) @ZLIB_INCLUDES@
@@ -39,6 +40,7 @@
libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \
my_time.c
sqlexamplessources = ha_example.cc ha_tina.cc
+sqlsphinxsources = ha_sphinx.cc
noinst_HEADERS = embedded_priv.h emb_qcache.h
@@ -67,7 +69,7 @@
parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
ha_blackhole.cc ha_archive.cc my_user.c
-libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources)
+libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) $(sqlsphinxsources)
libmysqld_a_SOURCES=
# automake misses these
@@ -147,12 +149,16 @@
rm -f $$f; \
@LN_CP_F@ $(top_srcdir)/sql/examples/$$f $$f; \
done; \
+ for f in $(sqlsphinxsources); do \
+ rm -f $$f; \
+ @LN_CP_F@ $(top_srcdir)/sql/sphinx/$$f $$f; \
+ done; \
rm -f client_settings.h; \
@LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h
clean-local:
- rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) | sed "s;\.lo;.c;g"` \
+ rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) $(sqlsphinxsources) | sed "s;\.lo;.c;g"` \
$(top_srcdir)/linked_libmysqld_sources; \
rm -f client_settings.h
--- mysql-5.0.67/sql/handler.cc 2008-08-04 23:20:04.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/handler.cc 2009-02-14 09:15:48.000000000 +1000
@@ -77,6 +77,15 @@
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+extern handlerton sphinx_hton;
+#else
+handlerton sphinx_hton = { "SPHINX", SHOW_OPTION_NO, "SPHINX storage engine",
+ DB_TYPE_SPHINX_DB, NULL, 0, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ HTON_NO_FLAGS };
+#endif
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
extern handlerton innobase_hton;
@@ -141,6 +150,7 @@
&example_hton,
&archive_hton,
&tina_hton,
+ &sphinx_hton,
&ndbcluster_hton,
&federated_hton,
&myisammrg_hton,
@@ -341,6 +351,12 @@
return new (alloc) ha_tina(table);
return NULL;
#endif
+#ifdef HAVE_SPHINX_DB
+ case DB_TYPE_SPHINX_DB:
+ if (have_sphinx_db == SHOW_OPTION_YES)
+ return new (alloc) ha_sphinx(table);
+ return NULL;
+#endif
#ifdef HAVE_NDBCLUSTER_DB
case DB_TYPE_NDBCLUSTER:
if (have_ndbcluster == SHOW_OPTION_YES)
--- mysql-5.0.67/sql/handler.h 2008-08-04 23:20:04.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/handler.h 2009-02-14 09:15:48.000000000 +1000
@@ -186,8 +186,9 @@
DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
- DB_TYPE_FEDERATED_DB,
+ DB_TYPE_FEDERATED_DB,
DB_TYPE_BLACKHOLE_DB,
+ DB_TYPE_SPHINX_DB,
DB_TYPE_DEFAULT // Must be last
};
--- mysql-5.0.67/sql/Makefile.am 2008-08-04 23:20:02.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/Makefile.am 2009-02-14 09:23:28.000000000 +1000
@@ -68,6 +68,7 @@
sql_array.h sql_cursor.h \
examples/ha_example.h ha_archive.h \
examples/ha_tina.h ha_blackhole.h \
+ sphinx/ha_sphinx.h \
ha_federated.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -105,6 +106,7 @@
sp_cache.cc parse_file.cc sql_trigger.cc \
examples/ha_example.cc ha_archive.cc \
examples/ha_tina.cc ha_blackhole.cc \
+ sphinx/ha_sphinx.cc \
ha_federated.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
@@ -174,6 +176,10 @@
udf_example_la_SOURCES= udf_example.c
udf_example_la_LDFLAGS= -module -rpath $(pkglibdir)
+pkglib_LTLIBRARIES = sphinx/sphinx.la
+sphinx_sphinx_la_SOURCES = sphinx/snippets_udf.cc
+sphinx_sphinx_la_LDFLAGS = -module
+
# Don't update the files from bitkeeper
%::SCCS/s.%
--- mysql-5.0.67/sql/mysqld.cc 2008-08-04 23:20:07.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/mysqld.cc 2009-02-14 09:15:48.000000000 +1000
@@ -36,6 +36,10 @@
#include <sys/prctl.h>
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+#endif
+
#ifdef HAVE_INNOBASE_DB
#define OPT_INNODB_DEFAULT 1
#else
@@ -6633,6 +6637,13 @@
{"Threads_running", (char*) &thread_running, SHOW_INT_CONST},
{"Uptime", (char*) 0, SHOW_STARTTIME},
{"Uptime_since_flush_status",(char*) 0, SHOW_FLUSHTIME},
+#ifdef HAVE_SPHINX_DB
+ {"sphinx_total", (char *)sphinx_showfunc_total, SHOW_SPHINX_FUNC},
+ {"sphinx_total_found", (char *)sphinx_showfunc_total_found, SHOW_SPHINX_FUNC},
+ {"sphinx_time", (char *)sphinx_showfunc_time, SHOW_SPHINX_FUNC},
+ {"sphinx_word_count", (char *)sphinx_showfunc_word_count, SHOW_SPHINX_FUNC},
+ {"sphinx_words", (char *)sphinx_showfunc_words, SHOW_SPHINX_FUNC},
+#endif
{NullS, NullS, SHOW_LONG}
};
@@ -6875,6 +6886,11 @@
#else
have_csv_db= SHOW_OPTION_NO;
#endif
+#ifdef HAVE_SPHINX_DB
+ have_sphinx_db= SHOW_OPTION_YES;
+#else
+ have_sphinx_db= SHOW_OPTION_NO;
+#endif
#ifdef HAVE_NDBCLUSTER_DB
have_ndbcluster=SHOW_OPTION_DISABLED;
#else
@@ -7983,6 +7999,7 @@
#undef have_example_db
#undef have_archive_db
#undef have_csv_db
+#undef have_sphinx_db
#undef have_federated_db
#undef have_partition_db
#undef have_blackhole_db
@@ -7993,6 +8010,7 @@
SHOW_COMP_OPTION have_example_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_archive_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
+SHOW_COMP_OPTION have_sphinx_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_federated_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
SHOW_COMP_OPTION have_blackhole_db= SHOW_OPTION_NO;
--- mysql-5.0.67/sql/mysql_priv.h 2008-08-04 23:20:07.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/mysql_priv.h 2009-02-14 09:15:48.000000000 +1000
@@ -1439,6 +1439,12 @@
#else
extern SHOW_COMP_OPTION have_csv_db;
#endif
+#ifdef HAVE_SPHINX_DB
+extern handlerton sphinx_hton;
+#define have_sphinx_db sphinx_hton.state
+#else
+extern SHOW_COMP_OPTION have_sphinx_db;
+#endif
#ifdef HAVE_FEDERATED_DB
extern handlerton federated_hton;
#define have_federated_db federated_hton.state
--- mysql-5.0.67/sql/set_var.cc 2008-08-04 23:20:08.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/set_var.cc 2009-02-14 09:15:48.000000000 +1000
@@ -888,6 +888,7 @@
{"have_compress", (char*) &have_compress, SHOW_HAVE},
{"have_crypt", (char*) &have_crypt, SHOW_HAVE},
{"have_csv", (char*) &have_csv_db, SHOW_HAVE},
+ {"have_sphinx", (char*) &have_sphinx_db, SHOW_HAVE},
{"have_dynamic_loading", (char*) &have_dlopen, SHOW_HAVE},
{"have_example_engine", (char*) &have_example_db, SHOW_HAVE},
{"have_federated_engine", (char*) &have_federated_db, SHOW_HAVE},
--- mysql-5.0.67/sql/sql_lex.h 2008-08-04 23:20:10.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/sql_lex.h 2009-02-14 09:15:48.000000000 +1000
@@ -57,6 +57,7 @@
SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_NDBCLUSTER_STATUS, SQLCOM_SHOW_MUTEX_STATUS,
+ SQLCOM_SHOW_SPHINX_STATUS,
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
--- mysql-5.0.67/sql/sql_parse.cc 2008-08-04 23:20:10.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/sql_parse.cc 2009-02-14 09:15:48.000000000 +1000
@@ -24,6 +24,9 @@
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
#endif
+#ifdef HAVE_SPHINX_DB
+#include "sphinx/ha_sphinx.h"
+#endif
#ifdef HAVE_NDBCLUSTER_DB
#include "ha_ndbcluster.h"
@@ -3006,6 +3009,15 @@
break;
}
#endif
+#ifdef HAVE_SPHINX_DB
+ case SQLCOM_SHOW_SPHINX_STATUS:
+ {
+ if (check_global_access(thd, SUPER_ACL))
+ goto error;
+ res = sphinx_show_status(thd);
+ break;
+ }
+#endif
#ifdef HAVE_REPLICATION
case SQLCOM_LOAD_MASTER_TABLE:
{
--- mysql-5.0.67/sql/sql_yacc.yy 2008-08-04 23:20:12.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/sql_yacc.yy 2009-02-14 09:15:48.000000000 +1000
@@ -7393,6 +7393,9 @@
case DB_TYPE_INNODB:
Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
break;
+ case DB_TYPE_SPHINX_DB:
+ Lex->sql_command = SQLCOM_SHOW_SPHINX_STATUS;
+ break;
default:
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
MYSQL_YYABORT;
--- mysql-5.0.67/sql/structs.h 2008-08-04 23:20:12.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/structs.h 2009-02-14 09:15:48.000000000 +1000
@@ -188,6 +188,9 @@
SHOW_SSL_CTX_SESS_TIMEOUTS, SHOW_SSL_CTX_SESS_CACHE_FULL,
SHOW_SSL_GET_CIPHER_LIST,
#endif /* HAVE_OPENSSL */
+#ifdef HAVE_SPHINX_DB
+ SHOW_SPHINX_FUNC,
+#endif
SHOW_NET_COMPRESSION,
SHOW_RPL_STATUS, SHOW_SLAVE_RUNNING, SHOW_SLAVE_RETRIED_TRANS,
SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_CONST_LONG, SHOW_KEY_CACHE_LONGLONG,
--- mysql-5.0.67/sql/sql_show.cc 2008-08-04 23:20:11.000000000 +1100
+++ mysql-5.0.67-sphinx/sql/sql_show.cc 2009-02-14 09:15:48.000000000 +1000
@@ -1473,6 +1473,16 @@
value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
&null_lex_str);
}
+ #ifdef HAVE_SPHINX_DB
+ else if (show_type == SHOW_SPHINX_FUNC)
+ {
+ SHOW_VAR var;
+ ((int (*)(THD *, SHOW_VAR *, char *))value)(thd, &var, buff);
+
+ value = var.value;
+ show_type = var.type;
+ }
+ #endif /* HAVE_SPHINX_DB */
pos= end= buff;
switch (show_type) {
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