Commit 019674ff authored by casualet's avatar casualet

update

parent 5d7bad68
File added
File added
......@@ -208,7 +208,6 @@ needsSalt(OLK olk)
bool
needsSalt(EncSet es)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
for (auto pair : es.osl) {
OLK olk(pair.first, pair.second.first, pair.second.second);
if (needsSalt(olk)) {
......@@ -228,23 +227,6 @@ operator<<(std::ostream &out, const reason &r)
return out;
}
/*
void
RewritePlan::restrict(const EncSet & es) {
es_out = es_out.intersect(es);
assert_s(!es_out.empty(), "after restrict rewrite plan has empty encset");
if (plan.size()) { //node has children
for (auto pair = plan.begin(); pair != plan.end(); pair++) {
if (!es.contains(pair->first)) {
plan.erase(pair);
}
}
}
}
*/
std::ostream&
operator<<(std::ostream &out, const RewritePlan * const rp)
{
......@@ -313,7 +295,7 @@ dropAll(const std::unique_ptr<Connect> &conn)
std::vector<std::string>
getAllUDFs()
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
//std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
std::vector<std::string> udfs;
for (const udf_func * const u: udf_list) {
std::stringstream ss;
......@@ -328,11 +310,11 @@ getAllUDFs()
ss << " SONAME 'edb.so';";
udfs.push_back(ss.str());
}
std::cout<<"all udfs:"<<std::endl;
for(std::string s:udfs){
std::cout<<s<<"\t";
}
std::cout<<std::endl;
return udfs;
}
......@@ -675,14 +657,14 @@ deltaOutputBeforeQuery(const std::unique_ptr<Connect> &e_conn,
CompletionType completion_type,
uint64_t *const embedded_completion_id)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string &escaped_original_query =
escapeString(e_conn, original_query);
const std::string &escaped_rewritten_query =
escapeString(e_conn, rewritten_query);
std::cout<<"escaped_original_query: "<<escaped_original_query<<"\n"<<"original_query: "<<
original_query<<"\n"<<"escaped_rewritten_query: "<<escaped_rewritten_query<<"\n"<<"rewritten_query: "<<
rewritten_query<<std::endl;
RFIF(escaped_original_query.length() <= STORED_QUERY_LENGTH
&& escaped_rewritten_query.length() <= STORED_QUERY_LENGTH);
......@@ -717,7 +699,7 @@ deltaOutputAfterQuery(const std::unique_ptr<Connect> &e_conn,
const std::vector<std::unique_ptr<Delta> > &deltas,
uint64_t embedded_completion_id)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
RFIF(e_conn->execute("START TRANSACTION;"));
const std::string q_update =
......@@ -738,7 +720,7 @@ static bool
tableCopy(const std::unique_ptr<Connect> &c, const std::string &src,
const std::string &dest)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string delete_query =
" DELETE FROM " + dest + ";";
RETURN_FALSE_IF_FALSE(c->execute(delete_query));
......@@ -754,7 +736,7 @@ tableCopy(const std::unique_ptr<Connect> &c, const std::string &src,
bool
setRegularTableToBleedingTable(const std::unique_ptr<Connect> &e_conn)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string src = MetaData::Table::bleedingMetaObject();
const std::string dest = MetaData::Table::metaObject();
return tableCopy(e_conn, src, dest);
......@@ -763,7 +745,7 @@ setRegularTableToBleedingTable(const std::unique_ptr<Connect> &e_conn)
bool
setBleedingTableToRegularTable(const std::unique_ptr<Connect> &e_conn)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string src = MetaData::Table::metaObject();
const std::string dest = MetaData::Table::bleedingMetaObject();
return tableCopy(e_conn, src, dest);
......@@ -773,7 +755,7 @@ bool Analysis::addAlias(const std::string &alias,
const std::string &db,
const std::string &table)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
auto db_alias_pair = table_aliases.find(db);
if (table_aliases.end() == db_alias_pair) {
table_aliases.insert(
......
......@@ -108,28 +108,125 @@ class ChangeColumnSubHandler : public AlterSubHandler {
}
};
class ForeignKeySubHandler : public AlterSubHandler {
virtual LEX *
rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)
const
{
FAIL_TextMessageError("implement ForeignKeySubHandler");
LEX * ForeignKeySubHandler::rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)
const{
// LEX *const new_lex = copyWithTHD(lex);
TableMeta const &ctm =
a.getTableMeta(preamble.dbname, preamble.table);
//find essential information from froeign key
auto it =
List_iterator<Key>(lex->alter_info.key_list);
while(auto cur = it++){
if(cur->type==Key::FOREIGN_KEY){
Table_ident* ref_table = ((Foreign_key*)cur)->ref_table;
std::string ref_table_name = convert_lex_str(ref_table->table);
TableMeta const &reftm =
a.getTableMeta(preamble.dbname, ref_table_name);
auto it_ref_columns = List_iterator<Key_part_spec>(((Foreign_key*)cur)->ref_columns);
//should find Only ope, and adjust it to OPEFOREIGN
while(auto cur_ref_columns=it_ref_columns++){
std::string ref_column_name = convert_lex_str(cur_ref_columns->field_name);
OnionMeta *om = a.getOnionMeta2(preamble.dbname,ref_table_name,ref_column_name,oOPE);
FieldMeta &reffm = a.getFieldMeta(reftm,ref_column_name);
assert(om!=NULL);
if(om->getLayerBack()->level()==SECLEVEL::RND||
om->getLayerBack()->level()==SECLEVEL::OPE){
OnionAdjustExcept oje(reftm,reffm,oOPE,SECLEVEL::OPEFOREIGN);
throw oje;
}else if(om->getLayerBack()->level()==SECLEVEL::OPEFOREIGN){
//nothing here
}else{
assert(0);
}
};
}
}else if(cur->type==Key::MULTIPLE){//adjust to OPEFROEIGN
auto it_columns = List_iterator<Key_part_spec>(cur->columns);
while(auto go = it_columns++){
std::string current_field_name = convert_lex_str(go->field_name);
OnionMeta *om = a.getOnionMeta2(preamble.dbname, preamble.table, current_field_name, oOPE);
if(om!=NULL){
if(om->getLayerBack()->level()==SECLEVEL::RND||
om->getLayerBack()->level()==SECLEVEL::OPE){
const FieldMeta &fm = a.getFieldMeta(ctm,current_field_name);
OnionAdjustExcept oje(ctm,fm,oOPE,SECLEVEL::OPEFOREIGN);
throw oje;
}else if(om->getLayerBack()->level()==SECLEVEL::OPEFOREIGN){
//nothing
}else{
assert(0);
}
}
}
}else{
assert(0);
return NULL;
}
}
highLevelRewriteKey(ctm, *lex, lex, a);
highLevelRewriteForeignKey(ctm,*lex,lex,a,preamble.table);
class AddIndexSubHandler : public AlterSubHandler {
virtual LEX *
rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)
const
{
return lex;
}
LEX * AddIndexSubHandler::rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)const{
if(lex->alter_info.flags & ALTER_FOREIGN_KEY) return lex;
//LEX *const new_lex = copyWithTHD(lex);
TableMeta const &tm =
a.getTableMeta(preamble.dbname, preamble.table);
//before rewriting key, we should check the layers of the onions for each field
auto it =
List_iterator<Key>(lex->alter_info.key_list);
while(auto cur = it++){
//for each key, find the columns
switch(cur->type){
case Key::PRIMARY:
case Key::UNIQUE:
case Key::MULTIPLE:
case Key::FULLTEXT:
case Key::SPATIAL:{
//for each column, find the
auto it_columns = List_iterator<Key_part_spec>(cur->columns);
while(auto go = it_columns++){
std::string current_field_name = convert_lex_str(go->field_name);
OnionMeta *om = a.getOnionMeta2(preamble.dbname, preamble.table, current_field_name, oDET);
if(om!=NULL){
//Remove RND here(reference rewrite_field.cc)
if(om->getLayerBack()->level()==SECLEVEL::RND){
const TableMeta &tm = a.getTableMeta(preamble.dbname,preamble.table);
const FieldMeta &fm = a.getFieldMeta(tm,current_field_name);
OnionAdjustExcept oje(tm,fm,oDET,SECLEVEL::DET);
throw oje;
}
}
om = a.getOnionMeta2(preamble.dbname,preamble.table,convert_lex_str(go->field_name),oOPE);
if(om!=NULL){
//Still remove RND here
if(om->getLayerBack()->level()==SECLEVEL::RND){
const TableMeta &tm = a.getTableMeta(preamble.dbname,preamble.table);
const FieldMeta &fm = a.getFieldMeta(tm,current_field_name);
OnionAdjustExcept oje(tm,fm,oOPE,SECLEVEL::OPE);
throw oje;
}
}
}
break;
}
case Key::FOREIGN_KEY:{
//assert(0);
//do nothing here
}
}
}
//if we have foreign, then no need to rewrite here
highLevelRewriteKey(tm, *lex, lex, a);
return lex;
}
};
}
class DropIndexSubHandler : public AlterSubHandler {
virtual LEX *
......@@ -214,7 +311,6 @@ class DisableOrEnableKeys : public AlterSubHandler {
LEX *AlterSubHandler::
transformLex(Analysis &a, LEX *const lex) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string &db = lex->select_lex.table_list.first->db;
TEST_DatabaseDiscrepancy(db, a.getDatabaseName());
const Preamble preamble(db,
......
......@@ -21,5 +21,24 @@ protected:
AlterSubHandler() {;}
};
class AddIndexSubHandler : public AlterSubHandler {
virtual LEX *
rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)const;
};
class ForeignKeySubHandler : public AlterSubHandler{
virtual LEX *
rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)const;
};
class AlterDispatcher;
AlterDispatcher *buildAlterSubDispatcher();
......@@ -424,7 +424,6 @@ class MultiDeleteHandler : public DMLHandler {
class SelectHandler : public DMLHandler {
virtual void gather(Analysis &a, LEX *const lex)
const{
std::cout<<RED_BEGIN<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<COLOR_END<<std::endl<<std::endl;
//处理了选择域, 以及为having等field 设置了rewriteplain, 也就是encset, 不同的洋葱层次需要这个东西.
process_select_lex(lex->select_lex, a);
}
......
......@@ -29,7 +29,6 @@
static Item *
encrypt_item(const Item &i, const OLK &olk, Analysis &a)
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
assert(!RiboldMYSQL::is_null(i));
FieldMeta * const fm = olk.key;
......@@ -55,7 +54,6 @@ static class ANON : public CItemSubtypeIT<Item_string,
virtual RewritePlan *
do_gather_type(const Item_string &i, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << " String item do_gather " << i << std::endl;
const std::string why = "is a string constant";
reason rsn(FULL_EncSet_Str, why, i);
......@@ -63,7 +61,6 @@ static class ANON : public CItemSubtypeIT<Item_string,
}
virtual Item * do_optimize_type(Item_string *i, Analysis & a) const {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
return i;
}
......@@ -71,7 +68,6 @@ static class ANON : public CItemSubtypeIT<Item_string,
do_rewrite_type(const Item_string &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << "do_rewrite_type String item " << i << std::endl;
return encrypt_item(i, constr, a);
}
......@@ -80,7 +76,6 @@ static class ANON : public CItemSubtypeIT<Item_string,
do_rewrite_insert_type(const Item_string &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
typical_rewrite_insert_type(i, fm, a, l);
}
} ANON;
......@@ -90,7 +85,6 @@ static class ANON : public CItemSubtypeIT<Item_float,
virtual RewritePlan *
do_gather_type(const Item_float &i, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << " Float item do_gather " << i << std::endl;
const std::string why = "is a float constant";
reason rsn(PLAIN_EncSet, why, i);
......@@ -101,7 +95,6 @@ static class ANON : public CItemSubtypeIT<Item_float,
do_rewrite_type(const Item_float &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << "do_rewrite_type Float item " << i << std::endl;
return encrypt_item(i, constr, a);
}
......@@ -110,7 +103,6 @@ static class ANON : public CItemSubtypeIT<Item_float,
do_rewrite_insert_type(const Item_float &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
typical_rewrite_insert_type(i, fm, a, l);
}
} ANON;
......@@ -120,7 +112,6 @@ static class ANON : public CItemSubtypeIT<Item_int, Item::Type::INT_ITEM> {
virtual RewritePlan *
do_gather_type(const Item_int &i, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << "CItemSubtypeIT (L966) num do_gather " << i
<< std::endl;
const std::string why = "is an int constant";
......@@ -130,7 +121,6 @@ static class ANON : public CItemSubtypeIT<Item_int, Item::Type::INT_ITEM> {
virtual Item * do_optimize_type(Item_int *i, Analysis & a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
return i;
}
......@@ -138,7 +128,6 @@ static class ANON : public CItemSubtypeIT<Item_int, Item::Type::INT_ITEM> {
do_rewrite_type(const Item_int &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << "do_rewrite_type " << i << std::endl;
return encrypt_item(i, constr, a);
......@@ -148,7 +137,6 @@ static class ANON : public CItemSubtypeIT<Item_int, Item::Type::INT_ITEM> {
do_rewrite_insert_type(const Item_int &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
typical_rewrite_insert_type(i, fm, a, l);
}
} ANON;
......@@ -158,7 +146,6 @@ static class ANON : public CItemSubtypeIT<Item_decimal,
virtual RewritePlan *
do_gather_type(const Item_decimal &i, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << "CItemSubtypeIT decimal do_gather " << i
<< std::endl;
......@@ -169,7 +156,6 @@ static class ANON : public CItemSubtypeIT<Item_decimal,
virtual Item * do_optimize_type(Item_decimal *i, Analysis & a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
return i;
}
......@@ -177,7 +163,6 @@ static class ANON : public CItemSubtypeIT<Item_decimal,
do_rewrite_type(const Item_decimal &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
LOG(cdb_v) << "do_rewrite_type " << i << std::endl;
return encrypt_item(i, constr, a);
......@@ -187,7 +172,6 @@ static class ANON : public CItemSubtypeIT<Item_decimal,
do_rewrite_insert_type(const Item_decimal &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
typical_rewrite_insert_type(i, fm, a, l);
}
} ANON;
......@@ -191,8 +191,6 @@ public:
RewritePlan(const EncSet &es, reason r) : r(r), es_out(es) {};
virtual ~RewritePlan() {}
reason getReason() const {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<std::endl;
std::cout<<"reson why: "<<r.why<<"reason item: "<<r.string_item<<std::endl;
return r;
}
......
......@@ -66,7 +66,6 @@ class ANON : public CItemSubtypeIT<Item_field, Item::Type::FIELD_ITEM> {
virtual RewritePlan *
do_gather_type(const Item_field &i, Analysis &a) const
{
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAAAA"<<std::endl;
const std::string fieldname = i.field_name;
const std::string table =
i.table_name ? i.table_name :
......
......@@ -298,6 +298,7 @@ class CItemCompare : public CItemSubtypeFT<Item_func, FT> {
return ORD_EncSet; /* lambda */
}
};
const EncSet my_es = getEncSet();
TEST_BadItemArgumentCount(i.type(), 2, i.argument_count());
......
This diff is collapsed.
......@@ -370,3 +370,14 @@ private:
bool stales() const {return true;}
bool usesEmbedded() const {return true;}
};
std::pair<std::vector<std::unique_ptr<Delta> >,
std::list<std::string>>
adjustOnion(const Analysis &a, onion o, const TableMeta &tm,
const FieldMeta &fm, SECLEVEL tolevel);
......@@ -273,10 +273,13 @@ getOriginalKeyName(const Key &key)
return "PRIMARY";
}
const std::string out_name = convert_lex_str(key.name);
std::string out_name = convert_lex_str(key.name);
TEST_TextMessageError(out_name.size() > 0,
"Non-Primary keys can not have blank name!");
//TEST_TextMessageError(out_name.size() > 0,
// "Non-Primary keys can not have blank name!");
if(out_name.size()==0){
out_name="nonekey";
}
return out_name;
}
......@@ -349,14 +352,18 @@ rewrite_key(const TableMeta &tm, const Key &key, const Analysis &a)
}
*/
/*
only rewrite normal keys here, do not process foreign keys.
*/
static std::vector<Key *>
rewrite_key1(const TableMeta &tm, const Key &key, const Analysis &a)
{
rewrite_key1(const TableMeta &tm, const Key &key, const Analysis &a){
//leave foreign key unchanged
std::vector<Key *> output_keys;
if(key.type==Key::FOREIGN_KEY){
THD* cthd = current_thd;
Key *const new_key = key.clone(cthd->mem_root);
output_keys.push_back(new_key);
return output_keys;
......@@ -369,7 +376,6 @@ rewrite_key1(const TableMeta &tm, const Key &key, const Analysis &a)
for (auto onion_it : key_onions) {
const onion o = onion_it;
THD* cthd = current_thd;
//原始key的拷贝
Key *const new_key = key.clone(cthd->mem_root);
//通过key的原始名字+onion+tm哈希获得新的key名字,用的是std::hash<string>算法.
......@@ -420,7 +426,6 @@ rewrite_key1(const TableMeta &tm, const Key &key, const Analysis &a)
return std::vector<Key *>({output_keys.front()});
}
}
return output_keys;
}
......@@ -430,8 +435,7 @@ rewrite_key1(const TableMeta &tm, const Key &key, const Analysis &a)
// 'seed_lex' and 'out_lex' can be the same object.
void
highLevelRewriteKey(const TableMeta &tm, const LEX &seed_lex,
LEX *const out_lex, const Analysis &a)
{
LEX *const out_lex, const Analysis &a){
assert(out_lex);
// Add each new index.
......@@ -519,10 +523,6 @@ highLevelRewriteForeignKey(const TableMeta &tm, const LEX &seed_lex,
new_key_part->field_name = string_to_lex_str(field_name);
((Foreign_key*)new_key)->ref_columns.push_back(new_key_part);
}
output_keys.push_back(new_key);
}else{
THD* cthd = current_thd;
......
......@@ -28,8 +28,6 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
std::unique_ptr<DBResult> db_res;
//这个id来自于dbobject.
const std::string parent_id = std::to_string(this->getDatabaseID());
std::cout<<"parent id: "<<parent_id<<std::endl;
const std::string serials_query =
" SELECT " + table_name + ".serial_object,"
" " + table_name + ".serial_key,"
......@@ -37,7 +35,8 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
" FROM " + table_name +
" WHERE " + table_name + ".parent_id"
" = " + parent_id + ";";
std::cout<<serials_query<<"serial query:"<<std::endl;
//all the metadata are fetched here.
//std::cout<<serials_query<<"serial query:"<<std::endl;
TEST_TextMessageError(e_conn->execute(serials_query, &db_res),
"doFetchChildren query failed");
MYSQL_ROW row;
......@@ -92,7 +91,7 @@ std::unique_ptr<OnionMeta>
OnionMeta::deserialize(unsigned int id, const std::string &serial)
{
assert(id != 0);
std::cout<<"string before unserialize: "<<serial<<std::endl;
//std::cout<<"string before unserialize: "<<serial<<std::endl;
const auto vec = unserialize_string(serial);
//OnionMeta序列化的结果有三个.
assert(3 == vec.size());
......
......@@ -363,7 +363,7 @@ void parseResType(const ResType &rd) {
}
*/
/*
static
void parseResType2(const ResType &rd) {
std::cout<<RED_BEGIN<<"rd.affected_rows: "<<rd.affected_rows<<COLOR_END<<std::endl;
......@@ -377,12 +377,14 @@ void parseResType2(const ResType &rd) {
}
}
}
*/
static ResType
getResTypeFromLuaTable(lua_State *const L, int fields_index,
int rows_index, int affected_rows_index,
int insert_id_index, int status_index) {
std::cout<<"decide to show luaTable to ResType:"<<std::endl;
//std::cout<<"decide to show luaTable to ResType:"<<std::endl;
const bool status = lua_toboolean(L, status_index);
if (false == status) {
return ResType(false, 0, 0);
......@@ -479,7 +481,6 @@ parseReturnMeta(const ReturnMeta & rtm){
static int
next(lua_State *const L) {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
// ANON_REGION(__func__, &perf_cg);
scoped_lock l(&big_lock);
assert(0 == mysql_thread_init());
......@@ -504,11 +505,8 @@ next(lua_State *const L) {
ps->safeCreateEmbeddedTHD();
const ResType &res = getResTypeFromLuaTable(L, 2, 3, 4, 5, 6);
parseResType2(res);
//parseResType2(res);
std::cout<<"************************************************"<<std::endl;
printRes(res);
const std::unique_ptr<QueryRewrite> &qr = c_wrapper->getQueryRewrite();
parseReturnMeta(qr->rmeta);
try {
......
......@@ -129,7 +129,6 @@ std::string ListJoin(List<T> lst, std::string delim,
accum << finalized_element;
accum << delim;
}
std::string output, str_accum = accum.str();
if (str_accum.length() > 0) {
output = str_accum.substr(0, str_accum.length() - delim.length());
......@@ -530,10 +529,28 @@ prefix_add_index(Key key)
key_output << ListJoin<Key_part_spec>(key.columns, ",",
do_prefix_add_index())
<< ")";
return key_output.str();
}
static std::string
prefix_add_foreign(Key *key){
const std::string index_name = convert_lex_str(key->name);
std::ostringstream key_output;
key_output << " ADD constraint "<<" FOREIGN KEY "<<index_name<<" (";
key_output << ListJoin<Key_part_spec>(key->columns, ",",
do_prefix_add_index())
<< ")";
Table_ident* ref_table = ((Foreign_key*)key)->ref_table;
std::string ref_table_name = convert_lex_str(ref_table->table);
key_output <<" REFERENCES "<< ref_table_name<<" (";
key_output<<ListJoin<Key_part_spec>( ((Foreign_key*)key)->ref_columns,",",do_prefix_add_index())<<" )";
return key_output.str();
}
static std::string
enableOrDisableKeysOutput(const LEX &lex)
{
......@@ -565,6 +582,71 @@ prettyLockType(enum thr_lock_type lock_type)
}
*/
//process normal key in alter table command, do not process foreign key
static std::string process_normal_key(LEX &lex){
std::ostringstream key_output;
auto it =
List_iterator<Key>(lex.alter_info.key_list);
while(auto cur = it++){
switch(cur->type){
case Key::PRIMARY:{
key_output<<prefix_add_index(*cur)<<",";
break;
}
case Key::UNIQUE:
case Key::MULTIPLE:
case Key::FULLTEXT:
case Key::SPATIAL:{
key_output<<prefix_add_index(*cur)<<",";
break;
}
case Key::FOREIGN_KEY:{
break;
}
default:{
break;
}
}
}
std::string orig = key_output.str();
std::string res = orig.substr(0,orig.length()-1);
return res;
}
static std::string process_foreign_key(LEX &lex){
std::ostringstream key_output;
auto it =
List_iterator<Key>(lex.alter_info.key_list);
while(auto cur = it++){
switch(cur->type){
case Key::PRIMARY:{
break;
}
case Key::UNIQUE:
case Key::MULTIPLE:
case Key::FULLTEXT:
case Key::SPATIAL:{
break;
}
case Key::FOREIGN_KEY:{
key_output<<prefix_add_foreign(cur)<<",";
break;
}
default:{
break;
}
}
}
std::string orig = key_output.str();
std::string res = orig.substr(0,orig.length()-1);
return res;
}
static inline std::ostream&
operator<<(std::ostream &out, LEX &lex)
{
......@@ -887,15 +969,30 @@ operator<<(std::ostream &out, LEX &lex)
prev = true;
}
if(lex.alter_info.flags & ALTER_FOREIGN_KEY){
if (true == prev) {
out << ", ";
}
std::string keys;
keys = process_foreign_key(lex);
out<<" "<<keys;
prev = true;
}
if (lex.alter_info.flags & ALTER_ADD_INDEX) {
if (true == prev) {
out << ", ";
}
out << " " << ListJoin<Key>(lex.alter_info.key_list, ",",
prefix_add_index);
//process primary and index here
//out << " " << ListJoin<Key>(lex.alter_info.key_list, ",",
// prefix_add_index);
//get a vector of key type, key name, and key columns
std::string keys;
keys = process_normal_key(lex);
out<<" "<<keys;
prev = true;
}
if (lex.alter_info.flags & ALTER_DROP_INDEX) {
if (true == prev) {
out << ", ";
......@@ -960,3 +1057,5 @@ operator<<(std::ostream &out, LEX &lex)
return out;
}
OBJDIRS += showHelper
##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories.
SHOWHELPER_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard showHelper/*.cc))
all: $(SHOWHELPER_OBJS) $(OBJDIR)/libshowhelper.so
$(OBJDIR)/libshowhelper.so: $(SHOWHELPER_OBJS) \
$(OBJDIR)/libedbparser.so
$(CXX) -shared -g -o $@ $(SHOWHELPER_OBJS) $(LDFLAGS) $(LDRPATH) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -ledbcrypto -ledbutil -ledbparser
# vim: set noexpandtab:
#include"showHelper/show_AltersubHandler.hh"
#include"showHelper/show_Dispatcher.hh"
#include"showHelper/show_utilities.hh"
void showAlterSubHandler::showAll(const LEX *lex){
stepOne(lex);
}
void showAddIndexSubHandler::stepOne(const LEX *lex){
std::cout<<"add index show"<<std::endl;
show::showKeyList(lex);
}
void showForeignKeySubHandler::stepOne(const LEX *lex){
std::cout<<"add foreign key"<<std::endl;
show::showKeyList(lex);
}
#pragma once
#include"showHelper/show_SQLHandler.hh"
class showAddIndexSubHandler:public showAlterSubHandler{
public:
showAddIndexSubHandler(){}
virtual ~showAddIndexSubHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
class showForeignKeySubHandler:public showAlterSubHandler{
public:
showForeignKeySubHandler(){}
virtual ~showForeignKeySubHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
#include<iostream>
#include"showHelper/show_DDLHandler.hh"
#include"showHelper/show_Dispatcher.hh"
#include"showHelper/show_utilities.hh"
using std::cout;
using std::endl;
// #### DDLHandler
void showDDLHandler::showAll(const LEX *lex){
stepOne(lex);
}
// #### CreateTableHandler
// show essential things of create table.
void showCreateTableHandler::stepOne(const LEX *lex){
std::cout<<"TYPE CREATE_TABLE:"<<std::endl;
assert(lex!=NULL);
assert(lex->select_lex.table_list.first);
if(lex->select_lex.table_list.first){
show::showTableList(const_cast<LEX*>(lex));
show::showKeyList(const_cast<LEX*>(lex));
show::showCreateFiled(const_cast<LEX*>(lex));
}
}
//## showAlterTableHandler
void showAlterTableHandler::stepOne(const LEX *lex){
if(alterdis->canDo(lex)){
const std::vector<showAlterSubHandler*> handlers = alterdis->dispatch(lex);
assert(handlers.size()>0);
for(auto it:handlers){
it->showAll(lex);
}
}else{
std::cout<<"unable to recognize the query"<<endl;
}
}
#pragma once
#include"showHelper/show_SQLHandler.hh"
#include"showHelper/show_Dispatcher.hh"
class showDDLHandler:public showSQLHandler{
public:
showDDLHandler(){}
virtual void showAll(const LEX *lex);
virtual ~showDDLHandler(){}
private:
virtual void stepOne(const LEX *lex)=0;
};
class showCreateTableHandler:public showDDLHandler{
public:
showCreateTableHandler(){}
virtual ~showCreateTableHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
class showAlterTableHandler:public showDDLHandler{
public:
showAlterTableHandler(){}
virtual ~showAlterTableHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
#include"showHelper/show_Dispatcher.hh"
bool showSQLDispatcher::canDo(LEX *const lex)const{
auto command = extract(lex);
return handlers.find(command)!=handlers.end();
}
long long showSQLDispatcher::extract(LEX *const lex)const{
return lex->sql_command;
}
const std::shared_ptr<showSQLHandler> showSQLDispatcher::dispatch(LEX *const lex) const{
auto it = handlers.find(extract(lex));
assert(it!=handlers.end());
assert(it->second);
return it->second;
}
///showAlterDispatcher
bool showAlterDispatcher::canDo(LEX *const lex)const{
if (0 == lex->alter_info.flags) {
return false;
}
long long flags = lex->alter_info.flags;
for (const auto &it : handlers) {
flags -= lex->alter_info.flags & it.first;
}
return 0 == flags;
}
//get handlers from lex->alter_info.flags
std::vector<showAlterSubHandler *> showAlterDispatcher::dispatch(LEX *const lex) const{
std::vector<showAlterSubHandler*> out;
for (const auto &it : handlers) {
const long long extract = lex->alter_info.flags & it.first;
if (extract) {
auto it_handler = handlers.find(extract);
assert(handlers.end() != it_handler && it_handler->second);
out.push_back(it_handler->second.get());
}
}
return out;
}
/*
able to support
SQLCOM_CREATE_TABLE,
*/
showSQLDispatcher* buildShowDDLDispatcher(){
showDDLHandler *h;
showSQLDispatcher * dispatcher = new showSQLDispatcher;
h = new showCreateTableHandler;
dispatcher->addHandler(SQLCOM_CREATE_TABLE, h);
h = new showAlterTableHandler;
dispatcher->addHandler(SQLCOM_ALTER_TABLE,h);
return dispatcher;
}
showAlterDispatcher* buildShowAlterDispatcher(){
showAlterSubHandler *h;
showAlterDispatcher *dispatcher = new showAlterDispatcher;
h = new showAddIndexSubHandler;
dispatcher->addHandler(ALTER_ADD_INDEX,h);
h = new showForeignKeySubHandler;
dispatcher->addHandler(ALTER_FOREIGN_KEY,h);
return dispatcher;
}
extern const showSQLDispatcher* const ddldis = buildShowDDLDispatcher();
extern const showAlterDispatcher* const alterdis = buildShowAlterDispatcher();
#pragma once
#include"showHelper/show_SQLHandler.hh"
#include"showHelper/show_DDLHandler.hh"
#include"showHelper/show_AltersubHandler.hh"
template <typename FetchMe>
class showDispatcher {
public:
virtual ~showDispatcher() {}
bool addHandler(long long cmd, FetchMe *const h) {
if (NULL == h) {
return false;
}
auto it = handlers.find(cmd);
if (handlers.end() != it) {
return false;
}
handlers[cmd] = std::unique_ptr<FetchMe>(h);
return true;
}
virtual bool canDo(LEX *const lex) const = 0;
protected:
std::map<long long, std::shared_ptr<FetchMe>> handlers;
};
class showSQLDispatcher : public showDispatcher<showSQLHandler> {
public:
showSQLDispatcher(){}
bool canDo(LEX *const lex) const;
const std::shared_ptr<showSQLHandler> dispatch(LEX *const lex) const;
private:
virtual long long extract(LEX *const lex) const;
};
class showAlterDispatcher : public showDispatcher<showAlterSubHandler> {
public:
std::vector<showAlterSubHandler *> dispatch(LEX *const lex) const;
bool canDo(LEX *const lex) const;
};
showSQLDispatcher* buildShowDDLDispatcher();
showAlterDispatcher* buildShowAlterDispatcher();
extern const showSQLDispatcher* const ddldis;
extern const showAlterDispatcher* const alterdis;
#pragma once
#include <util/util.hh>
#include <string>
#include <sql_parse.h>
#include <parser/mysql_type_metadata.hh>
#include <parser/sql_utils.hh>
#include <crypto/BasicCrypto.hh>
#include <assert.h>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <parser/embedmysql.hh>
#include <sql_base.h>
#include <sql_select.h>
#include <sql_delete.h>
#include <sql_insert.h>
#include <sql_update.h>
#include <sql_parse.h>
#include <handler.h>
#include <parser/stringify.hh>
#include <util/errstream.hh>
#include <util/rob.hh>
#include <iostream>
class showSQLHandler{
public:
showSQLHandler(){}
virtual void showAll(const LEX *lex)=0;
virtual ~showSQLHandler(){}
};
class showAlterSubHandler{
public:
showAlterSubHandler(){}
virtual void showAll(const LEX *lex);
virtual ~showAlterSubHandler(){}
private:
virtual void stepOne(const LEX *lex)=0;
};
#include"showHelper/show_entry.hh"
#include"showHelper/show_utilities.hh"
void parseSQL(std::string query){
show::draw(query,show::RED);
std::unique_ptr<query_parse> p = show::getLex(query);
LEX *const lex = p->lex();
if(ddldis->canDo(lex)){
std::cout<<"ddl can do"<<std::endl;
const std::shared_ptr<showSQLHandler> h = ddldis->dispatch(lex);
h->showAll(lex);
}else{
}
}
#pragma once
#include "showHelper/show_DDLHandler.hh"
#include "showHelper/show_AltersubHandler.hh"
#include "showHelper/show_utilities.hh"
#include <string>
void parseSQL(std::string query);
This diff is collapsed.
#pragma once
#include <util/util.hh>
#include <string>
#include <sql_parse.h>
#include <parser/mysql_type_metadata.hh>
#include <parser/sql_utils.hh>
#include <crypto/BasicCrypto.hh>
#include <assert.h>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <parser/embedmysql.hh>
#include <sql_base.h>
#include <sql_select.h>
#include <sql_delete.h>
#include <sql_insert.h>
#include <sql_update.h>
#include <sql_parse.h>
#include <handler.h>
#include <parser/stringify.hh>
#include <util/errstream.hh>
#include <util/rob.hh>
#include <iostream>
using std::string;
namespace show{
const std::string BOLD_BEGIN = "\033[1m";
const std::string RED_BEGIN = "\033[1;31m";
const std::string GREEN_BEGIN = "\033[1;92m";
const std::string COLOR_END = "\033[0m";
enum color{
BLANK,
RED,
GREEN,
BOLD
};
//output char*
void output(char *content, color c = BLANK);
template<class T,class ...arg>
void output(T t,arg... rest){
if(t==NULL) {
std::cout<<"NULL"<<"\t";
}else{
std::cout<<std::string(t)<<"\t";
}
output(rest...);
}
//output std::string
void draw(std::string,color c = BLANK);
template<class T,class ...arg>
void draw(T t,arg... rest){
if(t.size()==0){
std::cout<<"0string\t";
}else{
std::cout<<t<<"\t";
}
draw(rest...);
}
namespace keytrans{
extern std::map<int,std::string> trans;
}
namespace commandtrans{
extern std::map<int,std::string> trans;
}
namespace altertrans{
extern std::map<long long,std::string> trans;
}
namespace itemtypetrans{
extern std::map<int,std::string> trans;
}
namespace datatypetrans{
extern std::map<int,string> trans;
}
namespace fieldflagtrans{
extern std::map<int,string> trans;
}
}
namespace show{
std::string
empty_if_null(const char *const p);
std::unique_ptr<query_parse> getLex(std::string origQuery);
//const LEX* const lex will not pass,that's why she used RiboldMYSQL::constList_iterator in parser/lex_util.hh
void showKeyList(LEX *lex);
void showCreateFiled(LEX* lex);
void showTableList(LEX *lex);
}
namespace rewrite{
string
lexToQuery(const LEX &lex);
}
......@@ -25,8 +25,8 @@ typedef enum onion {
enum class SECLEVEL {
INVALID,
PLAINVAL,
OPE,
OPEFOREIGN,
OPE,
DETJOIN,
DET,
SEARCH,
......
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