Commit 0d57098d authored by yiwenshao's avatar yiwenshao

add comments

parent f41f2731
...@@ -16,6 +16,6 @@ oOPE: OPE RND ...@@ -16,6 +16,6 @@ oOPE: OPE RND
#oOPE: OPEFOREIGN OPE RND #oOPE: OPEFOREIGN OPE RND
[onions for str] [onions for str]
oDET: DET oDET: DET
#oOPE: OPE oOPE: OPE
#oSWP: SEARCH oSWP: SEARCH
[end] [end]
...@@ -14,7 +14,7 @@ EncSet::EncSet(Analysis &a, FieldMeta * const fm) { ...@@ -14,7 +14,7 @@ EncSet::EncSet(Analysis &a, FieldMeta * const fm) {
for (const auto &pair : fm->getChildren()) { for (const auto &pair : fm->getChildren()) {
OnionMeta *const om = pair.second.get(); OnionMeta *const om = pair.second.get();
OnionMetaKey const &key = pair.first; OnionMetaKey const &key = pair.first;
//就是当前的onionmeta的back 对应的level //the coresponding level of the back of the current onionmeta.
osl[key.getValue()] = LevelFieldPair(a.getOnionLevel(*om), fm); osl[key.getValue()] = LevelFieldPair(a.getOnionLevel(*om), fm);
} }
} }
...@@ -43,7 +43,6 @@ EncSet::intersect(const EncSet & es2) const ...@@ -43,7 +43,6 @@ EncSet::intersect(const EncSet & es2) const
static_cast<SECLEVEL>( static_cast<SECLEVEL>(
min(static_cast<int>(it->second.first), min(static_cast<int>(it->second.first),
static_cast<int>(it2.second.first))); static_cast<int>(it2.second.first)));
/* /*
* FIXME: Each clause of this if statement should make sure * FIXME: Each clause of this if statement should make sure
* that it's OnionMeta actually has the SecLevel. * that it's OnionMeta actually has the SecLevel.
......
...@@ -44,13 +44,13 @@ handleUpdateType(SIMPLE_UPDATE_TYPE update_type, const EncSet &es, ...@@ -44,13 +44,13 @@ handleUpdateType(SIMPLE_UPDATE_TYPE update_type, const EncSet &es,
List<Item> *const res_fields, List<Item> *const res_fields,
List<Item> *const res_values, Analysis &a); List<Item> *const res_values, Analysis &a);
//expand the Item i to a set of encrypted onions and the salt.
template <typename ContainerType> template <typename ContainerType>
void rewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a, void rewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a,
ContainerType *const append_list) ContainerType *const append_list){
{
std::vector<Item *> l; std::vector<Item *> l;
/*first look up the right class and then use the rewritting function of the specific data type /*first look up the right class and then use the rewritting function of the specific data type
for table student, the function typical_rewrite_insert_type in ANON is used finally. */ for table student, the function typical_rewrite_insert_type in ANON is used finally.*/
itemTypes.do_rewrite_insert(i, fm, a, &l); itemTypes.do_rewrite_insert(i, fm, a, &l);
for (auto it : l) { for (auto it : l) {
append_list->push_back(it); append_list->push_back(it);
...@@ -59,9 +59,8 @@ void rewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a, ...@@ -59,9 +59,8 @@ void rewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a,
void InsertHandler::gather(Analysis &a, LEX *const lex) const { void InsertHandler::gather(Analysis &a, LEX *const lex) const {
//only select xxx etc?不是的!!! //only select xxx etc? no!!
process_select_lex(lex->select_lex, a); process_select_lex(lex->select_lex, a);
// ----------------------- // -----------------------
// ON DUPLICATE KEY UPDATE // ON DUPLICATE KEY UPDATE
// ----------------------- // -----------------------
...@@ -69,11 +68,10 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const { ...@@ -69,11 +68,10 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const {
auto val_it = List_iterator<Item>(lex->value_list); auto val_it = List_iterator<Item>(lex->value_list);
//find plain for field and value rewrite? //find plain for field and value rewrite?
process_field_value_pairs(fd_it, val_it, a); process_field_value_pairs(fd_it, val_it, a);
return; return;
} }
AbstractQueryExecutor * InsertHandler::rewrite(Analysis &a, LEX *const lex) AbstractQueryExecutor * InsertHandler::rewrite(Analysis &a, LEX *const lex)
const{ const{
LEX *const new_lex = copyWithTHD(lex); LEX *const new_lex = copyWithTHD(lex);
const std::string &table = const std::string &table =
...@@ -108,7 +106,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const { ...@@ -108,7 +106,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const {
if (!i) { if (!i) {
break; break;
} }
//这下也就知道了field item是什么了
TEST_TextMessageError(i->type() == Item::FIELD_ITEM, TEST_TextMessageError(i->type() == Item::FIELD_ITEM,
"Expected field item!"); "Expected field item!");
const Item_field *const ifd = const Item_field *const ifd =
...@@ -177,7 +174,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const { ...@@ -177,7 +174,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const {
//li pointer to items of lex->many_values //li pointer to items of lex->many_values
auto it0 = List_iterator<Item>(*li); auto it0 = List_iterator<Item>(*li);
auto fmVecIt = fmVec.begin(); auto fmVecIt = fmVec.begin();
for (;;) { for (;;) {
const Item *const i = it0++; const Item *const i = it0++;
assert(!!i == (fmVec.end() != fmVecIt)); assert(!!i == (fmVec.end() != fmVecIt));
...@@ -197,7 +193,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const { ...@@ -197,7 +193,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const {
} }
new_lex->many_values = newList; new_lex->many_values = newList;
} }
//for queries with ON DUPLICATE KEY UPDATE //for queries with ON DUPLICATE KEY UPDATE
// ----------------------- // -----------------------
// ON DUPLICATE KEY UPDATE // ON DUPLICATE KEY UPDATE
...@@ -217,9 +212,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const { ...@@ -217,9 +212,6 @@ void InsertHandler::gather(Analysis &a, LEX *const lex) const {
return new DMLQueryExecutor(*new_lex, a.rmeta); return new DMLQueryExecutor(*new_lex, a.rmeta);
} }
class UpdateHandler : public DMLHandler { class UpdateHandler : public DMLHandler {
virtual void gather(Analysis &a, LEX *lex) const { virtual void gather(Analysis &a, LEX *lex) const {
process_table_list(lex->select_lex.top_join_list, a); process_table_list(lex->select_lex.top_join_list, a);
...@@ -415,7 +407,6 @@ AbstractQueryExecutor * ...@@ -415,7 +407,6 @@ AbstractQueryExecutor *
SelectHandler::rewrite(Analysis &a, LEX *lex) SelectHandler::rewrite(Analysis &a, LEX *lex)
const{ const{
LEX *const new_lex = copyWithTHD(lex); LEX *const new_lex = copyWithTHD(lex);
//table list rewrite //table list rewrite
new_lex->select_lex.top_join_list = new_lex->select_lex.top_join_list =
rewrite_table_list(lex->select_lex.top_join_list, a); rewrite_table_list(lex->select_lex.top_join_list, a);
...@@ -483,8 +474,8 @@ process_select_lex(const st_select_lex &select_lex, Analysis &a) ...@@ -483,8 +474,8 @@ process_select_lex(const st_select_lex &select_lex, Analysis &a)
numOfItem++; numOfItem++;
gatherAndAddAnalysisRewritePlan(*item, a); gatherAndAddAnalysisRewritePlan(*item, a);
} }
/*
/*process select_lex.where and select_lex.having, all of which are of the type Item. process select_lex.where and select_lex.having, all of which are of the type Item.
rewriteplain is added for those items. Also, process_order is used internally to process rewriteplain is added for those items. Also, process_order is used internally to process
select_lex.group_list and select_lex.order_list select_lex.group_list and select_lex.order_list
*/ */
...@@ -647,13 +638,15 @@ addSaltToReturn(ReturnMeta *const rm, int pos) ...@@ -647,13 +638,15 @@ addSaltToReturn(ReturnMeta *const rm, int pos)
rm->rfmeta.insert(pair); rm->rfmeta.insert(pair);
} }
//Item needs to be encrypted using the RewritePlain from the gather phase. The results will be put in newList, and Analysis is helper class. /*Item needs to be encrypted using the RewritePlain from the gather phase.
*The results will be put in newList, and Analysis is helper class.
*The rewriteplain contains encset and reason. reason itself also contains the encset.
*/
static void static void
rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a, rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a,
List<Item> *const newList) { List<Item> *const newList) {
AssignOnce<OLK> olk; AssignOnce<OLK> olk;
AssignOnce<Item *> ir; AssignOnce<Item *> ir;
if (i.type() == Item::Type::FIELD_ITEM) { if (i.type() == Item::Type::FIELD_ITEM) {
const Item_field &field_i = static_cast<const Item_field &>(i); const Item_field &field_i = static_cast<const Item_field &>(i);
const auto &cached_rewritten_i = a.item_cache.find(&field_i); const auto &cached_rewritten_i = a.item_cache.find(&field_i);
...@@ -678,7 +671,6 @@ rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a, ...@@ -678,7 +671,6 @@ rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a,
// This line implicity handles field aliasing for at least some cases. // This line implicity handles field aliasing for at least some cases.
// As i->name can/will be the alias. // As i->name can/will be the alias.
addToReturn(&a.rmeta, a.pos++, olk.get(), use_salt, i.name); addToReturn(&a.rmeta, a.pos++, olk.get(), use_salt, i.name);
if (use_salt) { if (use_salt) {
TEST_TextMessageError(Item::Type::FIELD_ITEM == ir.get()->type(), TEST_TextMessageError(Item::Type::FIELD_ITEM == ir.get()->type(),
"a projection requires a salt and is not a field; cryptdb" "a projection requires a salt and is not a field; cryptdb"
...@@ -695,13 +687,11 @@ rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a, ...@@ -695,13 +687,11 @@ rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a,
} }
st_select_lex * st_select_lex *
rewrite_select_lex(const st_select_lex &select_lex, Analysis &a) rewrite_select_lex(const st_select_lex &select_lex, Analysis &a) {
{
// rewrite_filters_lex must be called before rewrite_proj because // rewrite_filters_lex must be called before rewrite_proj because
// it is responsible for filling Analysis::item_cache which // it is responsible for filling Analysis::item_cache which
// rewrite_proj uses. // rewrite_proj uses.
st_select_lex *const new_select_lex = rewrite_filters_lex(select_lex, a); st_select_lex *const new_select_lex = rewrite_filters_lex(select_lex, a);
LOG(cdb_v) << "rewrite select lex input is " LOG(cdb_v) << "rewrite select lex input is "
<< select_lex << std::endl; << select_lex << std::endl;
auto item_it = auto item_it =
...@@ -709,9 +699,8 @@ rewrite_select_lex(const st_select_lex &select_lex, Analysis &a) ...@@ -709,9 +699,8 @@ rewrite_select_lex(const st_select_lex &select_lex, Analysis &a)
List<Item> newList; List<Item> newList;
int numOfItem=0; int numOfItem=0;
//item的改写, 是写到newlist里面, 所以item本身不会有变化. //Rewrite item to new list. and item does not change.
for (;;) { for (;;) {
const Item *const item = item_it++; const Item *const item = item_it++;
if (!item) if (!item)
break; break;
...@@ -720,19 +709,7 @@ rewrite_select_lex(const st_select_lex &select_lex, Analysis &a) ...@@ -720,19 +709,7 @@ rewrite_select_lex(const st_select_lex &select_lex, Analysis &a)
*constGetAssert(a.rewritePlans, item).get(), *constGetAssert(a.rewritePlans, item).get(),
a, &newList); a, &newList);
} }
// auto item_it_new =
// RiboldMYSQL::constList_iterator<Item>(newList);
// std::cout<<"rewrite#############" <<std::endl;
// for(;;){
// const Item *const item = item_it_new++;
// if(!item) break;
// std::cout<<"itemname: "<<item->name<<std::endl;
// }
// std::cout<<"num of item: "<<numOfItem<<std::endl;
new_select_lex->item_list = newList; new_select_lex->item_list = newList;
return new_select_lex; return new_select_lex;
} }
......
...@@ -371,13 +371,7 @@ private: ...@@ -371,13 +371,7 @@ private:
bool usesEmbedded() const {return true;} bool usesEmbedded() const {return true;}
}; };
std::pair<std::vector<std::unique_ptr<Delta> >, std::pair<std::vector<std::unique_ptr<Delta> >,
std::list<std::string>> std::list<std::string>>
adjustOnion(const Analysis &a, onion o, const TableMeta &tm, adjustOnion(const Analysis &a, onion o, const TableMeta &tm,
const FieldMeta &fm, SECLEVEL tolevel); const FieldMeta &fm, SECLEVEL tolevel);
...@@ -23,12 +23,13 @@ Item * ...@@ -23,12 +23,13 @@ Item *
rewrite(const Item &i, const EncSet &req_enc, Analysis &a) { rewrite(const Item &i, const EncSet &req_enc, Analysis &a) {
const std::unique_ptr<RewritePlan> &rp = const std::unique_ptr<RewritePlan> &rp =
constGetAssert(a.rewritePlans, &i); constGetAssert(a.rewritePlans, &i);
//req_enc can come from the rewriteplain.es_out or ???
const EncSet solution = rp->es_out.intersect(req_enc); const EncSet solution = rp->es_out.intersect(req_enc);
// FIXME: Use version that takes reason, expects 0 children, // FIXME: Use version that takes reason, expects 0 children,
// and lets us indicate what our EncSet does have. // and lets us indicate what our EncSet does have.
TEST_NoAvailableEncSet(solution, i.type(), req_enc, rp->r.why, TEST_NoAvailableEncSet(solution, i.type(), req_enc, rp->r.why,
std::vector<std::shared_ptr<RewritePlan> >()); std::vector<std::shared_ptr<RewritePlan> >());
return itemTypes.do_rewrite(i, solution.chooseOne(), *rp.get(), a); return itemTypes.do_rewrite(i, solution.chooseOne(), *rp.get(), a);
} }
...@@ -141,7 +142,7 @@ rewrite_table_list(List<TABLE_LIST> tll, Analysis &a) { ...@@ -141,7 +142,7 @@ rewrite_table_list(List<TABLE_LIST> tll, Analysis &a) {
RewritePlan * RewritePlan *
gather(const Item &i, Analysis &a) gather(const Item &i, Analysis &a)
{ {
return itemTypes.do_gather(i, a); return itemTypes.do_gather(i,a);
} }
void void
...@@ -582,7 +583,8 @@ encrypt_item_all_onions(const Item &i, const FieldMeta &fm, ...@@ -582,7 +583,8 @@ encrypt_item_all_onions(const Item &i, const FieldMeta &fm,
} }
} }
//Called by do_rewrite_insert_type //Called by do_rewrite_insert_type, the input Item i is either integer or string, and the returned vector l
//is a set of encrypted onions and the salt.
void void
typical_rewrite_insert_type(const Item &i, const FieldMeta &fm, typical_rewrite_insert_type(const Item &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) { Analysis &a, std::vector<Item *> *l) {
......
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