Index: include/my_base.h =================================================================== --- include/my_base.h (revision 17416) +++ include/my_base.h (revision 17417) @@ -249,11 +249,12 @@ enum ha_base_keytype { #define HA_SPATIAL 1024 /* For spatial search */ #define HA_NULL_ARE_EQUAL 2048 /* NULL in key are cmp as equal */ #define HA_GENERATED_KEY 8192 /* Automaticly generated key */ +#define HA_CLUSTERING 131072 /* for TOKUDB: Clustering key */ /* The combination of the above can be used for key type comparison. */ #define HA_KEYFLAG_MASK (HA_NOSAME | HA_PACK_KEY | HA_AUTO_KEY | \ HA_BINARY_PACK_KEY | HA_FULLTEXT | HA_UNIQUE_CHECK | \ - HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY) + HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY | HA_CLUSTERING) #define HA_KEY_HAS_PART_KEY_SEG 65536 /* Key contains partial segments */ Index: sql/sql_yacc.yy =================================================================== --- sql/sql_yacc.yy (revision 17416) +++ sql/sql_yacc.yy (revision 17417) @@ -759,6 +759,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong * %token CIPHER_SYM %token CLIENT_SYM %token CLOSE_SYM /* SQL-2003-R */ +%token CLUSTERING_SYM %token COALESCE /* SQL-2003-N */ %token CODE_SYM %token COLLATE_SYM /* SQL-2003-R */ @@ -1359,7 +1360,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong * option_type opt_var_type opt_var_ident_type %type - normal_key_type opt_unique constraint_key_type fulltext spatial + normal_key_type opt_unique constraint_key_type fulltext spatial clustering %type btree_or_rtree @@ -1865,6 +1866,16 @@ create: if (add_create_index(Lex, $2, $4.str)) MYSQL_YYABORT; } + | CREATE clustering INDEX_SYM ident key_alg ON table_ident + { + if (add_create_index_prepare(Lex, $7)) + MYSQL_YYABORT; + } + '(' key_list ')' normal_key_options + { + if (add_create_index(Lex, $2, $4.str)) + MYSQL_YYABORT; + } | CREATE fulltext INDEX_SYM ident init_key_options ON table_ident { @@ -4851,6 +4862,12 @@ key_def: if (add_create_index (Lex, $1, $3)) MYSQL_YYABORT; } + | clustering opt_key_or_index opt_ident init_key_options + '(' key_list ')' fulltext_key_options + { + if (add_create_index (Lex, $1, $3)) + MYSQL_YYABORT; + } | spatial opt_key_or_index opt_ident init_key_options '(' key_list ')' spatial_key_options { @@ -5481,6 +5498,10 @@ fulltext: FULLTEXT_SYM { $$= Key::FULLTEXT;} ; +clustering: + CLUSTERING_SYM { $$= Key::CLUSTERING;} + ; + spatial: SPATIAL_SYM { Index: sql/sql_class.h =================================================================== --- sql/sql_class.h (revision 17416) +++ sql/sql_class.h (revision 17417) @@ -197,7 +197,7 @@ class Alter_column :public Sql_alloc { class Key :public Sql_alloc { public: - enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY}; + enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY, CLUSTERING}; enum Keytype type; KEY_CREATE_INFO key_create_info; List columns; Index: sql/table.cc =================================================================== --- sql/table.cc (revision 17416) +++ sql/table.cc (revision 17417) @@ -787,6 +787,14 @@ static int open_binary_frm(THD *thd, TABLE_SHARE * if (new_frm_ver >= 3) { keyinfo->flags= (uint) uint2korr(strpos) ^ HA_NOSAME; + // + // Tokutek change, HA_CLUSTERING in frm means HA_SPATIAL and HA_FULLTEXT set + // + if (keyinfo->flags & HA_SPATIAL && keyinfo->flags & HA_FULLTEXT) { + keyinfo->flags |= HA_CLUSTERING; + keyinfo->flags &= ~(HA_SPATIAL); + keyinfo->flags &= ~(HA_FULLTEXT); + } keyinfo->key_length= (uint) uint2korr(strpos+2); keyinfo->key_parts= (uint) strpos[4]; keyinfo->algorithm= (enum ha_key_alg) strpos[5]; Index: sql/lex.h =================================================================== --- sql/lex.h (revision 17416) +++ sql/lex.h (revision 17417) @@ -107,6 +107,7 @@ static SYMBOL symbols[] = { { "CIPHER", SYM(CIPHER_SYM)}, { "CLIENT", SYM(CLIENT_SYM)}, { "CLOSE", SYM(CLOSE_SYM)}, + { "CLUSTERING", SYM(CLUSTERING_SYM)}, { "COALESCE", SYM(COALESCE)}, { "CODE", SYM(CODE_SYM)}, { "COLLATE", SYM(COLLATE_SYM)}, Index: sql/sql_show.cc =================================================================== --- sql/sql_show.cc (revision 17416) +++ sql/sql_show.cc (revision 17417) @@ -1369,6 +1369,8 @@ int store_create_info(THD *thd, TABLE_LIST *table_ packet->append(STRING_WITH_LEN("FULLTEXT KEY ")); else if (key_info->flags & HA_SPATIAL) packet->append(STRING_WITH_LEN("SPATIAL KEY ")); + else if (key_info->flags & HA_CLUSTERING) + packet->append(STRING_WITH_LEN("CLUSTERING KEY ")); else packet->append(STRING_WITH_LEN("KEY ")); Index: sql/unireg.cc =================================================================== --- sql/unireg.cc (revision 17416) +++ sql/unireg.cc (revision 17417) @@ -517,7 +517,15 @@ static uint pack_keys(uchar *keybuff, uint key_cou key_parts=0; for (key=keyinfo,end=keyinfo+key_count ; key != end ; key++) { - int2store(pos, (key->flags ^ HA_NOSAME)); + uint16 key_flags = (uint16)key->flags; + // + // Tokutek change, HA_CLUSTERING in frm means HA_SPATIAL and HA_FULLTEXT set + // + if (key->flags & HA_CLUSTERING) { + key_flags |= HA_SPATIAL; + key_flags |= HA_FULLTEXT; + } + int2store(pos, (key_flags ^ HA_NOSAME)); int2store(pos+2,key->key_length); pos[4]= (uchar) key->key_parts; pos[5]= (uchar) key->algorithm; Index: sql/sql_table.cc =================================================================== --- sql/sql_table.cc (revision 17416) +++ sql/sql_table.cc (revision 17417) @@ -3001,6 +3001,9 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INF sym_group_geom.name, sym_group_geom.needed_define); DBUG_RETURN(TRUE); #endif + case Key::CLUSTERING: + key_info->flags = HA_CLUSTERING; + break; case Key::FOREIGN_KEY: key_number--; // Skip this key continue; @@ -6271,6 +6274,9 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, } else if (key_info->flags & HA_FULLTEXT) key_type= Key::FULLTEXT; + else if (key_info->flags & HA_CLUSTERING) { + key_type = Key::CLUSTERING; + } else key_type= Key::MULTIPLE;