| 1 | // |
| 2 | // $Id: ha_sphinx.h 4818 2014-09-24 08:53:38Z tomat $ |
| 3 | // |
| 4 | |
| 5 | #ifdef USE_PRAGMA_INTERFACE |
| 6 | #pragma interface // gcc class implementation |
| 7 | #endif |
| 8 | |
| 9 | |
| 10 | #if MYSQL_VERSION_ID>=50515 |
| 11 | #define TABLE_ARG TABLE_SHARE |
| 12 | #elif MYSQL_VERSION_ID>50100 |
| 13 | #define TABLE_ARG st_table_share |
| 14 | #else |
| 15 | #define TABLE_ARG st_table |
| 16 | #endif |
| 17 | |
| 18 | |
| 19 | #if MYSQL_VERSION_ID>=50120 |
| 20 | typedef uchar byte; |
| 21 | #endif |
| 22 | |
| 23 | |
| 24 | /// forward decls |
| 25 | class THD; |
| 26 | struct CSphReqQuery; |
| 27 | struct CSphSEShare; |
| 28 | struct CSphSEAttr; |
| 29 | struct CSphSEStats; |
| 30 | struct CSphSEThreadTable; |
| 31 | |
| 32 | /// Sphinx SE handler class |
| 33 | class ha_sphinx : public handler |
| 34 | { |
| 35 | protected: |
| 36 | THR_LOCK_DATA m_tLock; ///< MySQL lock |
| 37 | |
| 38 | CSphSEShare * m_pShare; ///< shared lock info |
| 39 | |
| 40 | uint m_iMatchesTotal; |
| 41 | uint m_iCurrentPos; |
| 42 | const byte * m_pCurrentKey; |
| 43 | uint m_iCurrentKeyLen; |
| 44 | |
| 45 | char * m_pResponse; ///< searchd response storage |
| 46 | char * m_pResponseEnd; ///< searchd response storage end (points to wilderness!) |
| 47 | char * m_pCur; ///< current position into response |
| 48 | bool m_bUnpackError; ///< any errors while unpacking response |
| 49 | |
| 50 | public: |
| 51 | #if MYSQL_VERSION_ID<50100 |
| 52 | ha_sphinx ( TABLE_ARG * table_arg ); // NOLINT |
| 53 | #else |
| 54 | ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg ); |
| 55 | #endif |
| 56 | ~ha_sphinx (); |
| 57 | |
| 58 | const char * table_type () const { return "SPHINX" ; } ///< SE name for display purposes |
| 59 | const char * index_type ( uint ) { return "HASH" ; } ///< index type name for display purposes |
| 60 | |
| 61 | #if MYSQL_VERSION_ID>50100 |
| 62 | ulonglong table_flags () const { return HA_CAN_INDEX_BLOBS | |
| 63 | HA_CAN_TABLE_CONDITION_PUSHDOWN; } ///< bitmap of implemented flags (see handler.h for more info) |
| 64 | #else |
| 65 | ulong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info) |
| 66 | #endif |
| 67 | |
| 68 | ulong index_flags ( uint, uint, bool ) const { return 0; } ///< bitmap of flags that says how SE implements indexes |
| 69 | uint max_supported_record_length () const { return HA_MAX_REC_LENGTH; } |
| 70 | uint max_supported_keys () const { return 1; } |
| 71 | uint max_supported_key_parts () const { return 1; } |
| 72 | uint max_supported_key_length () const { return MAX_KEY_LENGTH; } |
| 73 | uint max_supported_key_part_length () const { return MAX_KEY_LENGTH; } |
| 74 | |
| 75 | #if MYSQL_VERSION_ID>50100 |
| 76 | virtual double scan_time () { return (double)( stats.records+stats.deleted )/20.0 + 10; } ///< called in test_quick_select to determine if indexes should be used |
| 77 | #else |
| 78 | virtual double scan_time () { return (double)( records+deleted )/20.0 + 10; } ///< called in test_quick_select to determine if indexes should be used |
| 79 | #endif |
| 80 | |
| 81 | virtual double read_time(uint index, uint ranges, ha_rows rows) |
| 82 | { return ranges + (double)rows/20.0 + 1; } ///< index read time estimate |
| 83 | |
| 84 | public: |
| 85 | int open ( const char * name, int mode, uint test_if_locked ); |
| 86 | int close (); |
| 87 | |
| 88 | int write_row ( byte * buf ); |
| 89 | int update_row ( const byte * old_data, const byte * new_data ); |
| 90 | int delete_row ( const byte * buf ); |
| 91 | int ( enum ha_extra_function op ); |
| 92 | |
| 93 | int index_init ( uint keynr, bool sorted ); // 5.1.x |
| 94 | int index_init ( uint keynr ) { return index_init ( keynr, false ); } // 5.0.x |
| 95 | |
| 96 | int index_end (); |
| 97 | int index_read ( byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag ); |
| 98 | int index_read_idx ( byte * buf, uint idx, const byte * key, uint key_len, enum ha_rkey_function find_flag ); |
| 99 | int index_next ( byte * buf ); |
| 100 | int index_next_same ( byte * buf, const byte * key, uint keylen ); |
| 101 | int index_prev ( byte * buf ); |
| 102 | int index_first ( byte * buf ); |
| 103 | int index_last ( byte * buf ); |
| 104 | |
| 105 | int get_rec ( byte * buf, const byte * key, uint keylen ); |
| 106 | |
| 107 | int rnd_init ( bool scan ); |
| 108 | int rnd_end (); |
| 109 | int rnd_next ( byte * buf ); |
| 110 | int rnd_pos ( byte * buf, byte * pos ); |
| 111 | void position ( const byte * record ); |
| 112 | |
| 113 | #if MYSQL_VERSION_ID>=50030 |
| 114 | int info ( uint ); |
| 115 | #else |
| 116 | void info ( uint ); |
| 117 | #endif |
| 118 | |
| 119 | int reset(); |
| 120 | int external_lock ( THD * thd, int lock_type ); |
| 121 | int delete_all_rows (); |
| 122 | ha_rows records_in_range ( uint inx, key_range * min_key, key_range * max_key ); |
| 123 | |
| 124 | int delete_table ( const char * from ); |
| 125 | int rename_table ( const char * from, const char * to ); |
| 126 | int create ( const char * name, TABLE * form, HA_CREATE_INFO * create_info ); |
| 127 | |
| 128 | THR_LOCK_DATA ** store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type ); |
| 129 | |
| 130 | public: |
| 131 | #if MYSQL_VERSION_ID<50610 |
| 132 | virtual const COND * cond_push ( const COND *cond ); |
| 133 | #else |
| 134 | virtual const Item * cond_push ( const Item *cond ); |
| 135 | #endif |
| 136 | virtual void cond_pop (); |
| 137 | |
| 138 | private: |
| 139 | uint32 m_iFields; |
| 140 | char ** m_dFields; |
| 141 | |
| 142 | uint32 m_iAttrs; |
| 143 | CSphSEAttr * m_dAttrs; |
| 144 | int m_bId64; |
| 145 | |
| 146 | int * m_dUnboundFields; |
| 147 | |
| 148 | private: |
| 149 | int Connect ( const char * sQueryHost, ushort uPort ); |
| 150 | int ConnectAPI ( const char * sQueryHost, int iQueryPort ); |
| 151 | int HandleMysqlError ( struct st_mysql * pConn, int iErrCode ); |
| 152 | |
| 153 | uint32 UnpackDword (); |
| 154 | char * UnpackString (); |
| 155 | bool UnpackSchema (); |
| 156 | bool UnpackStats ( CSphSEStats * pStats ); |
| 157 | bool CheckResponcePtr ( int iLen ); |
| 158 | |
| 159 | CSphSEThreadTable * GetTls (); |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | #if MYSQL_VERSION_ID < 50100 |
| 164 | bool sphinx_show_status ( THD * thd ); |
| 165 | #endif |
| 166 | |
| 167 | int sphinx_showfunc_total_found ( THD *, SHOW_VAR *, char * ); |
| 168 | int sphinx_showfunc_total ( THD *, SHOW_VAR *, char * ); |
| 169 | int sphinx_showfunc_time ( THD *, SHOW_VAR *, char * ); |
| 170 | int sphinx_showfunc_word_count ( THD *, SHOW_VAR *, char * ); |
| 171 | int sphinx_showfunc_words ( THD *, SHOW_VAR *, char * ); |
| 172 | |
| 173 | // |
| 174 | // $Id: ha_sphinx.h 4818 2014-09-24 08:53:38Z tomat $ |
| 175 | // |
| 176 | |