Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Practical-Cryptdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zhaozhen
Practical-Cryptdb
Commits
71de862d
Commit
71de862d
authored
Jan 12, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify debug/load_and_store.cc
parent
d8d81270
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
994 additions
and
72 deletions
+994
-72
load_and_store.cc
debug/load_and_store.cc
+946
-0
try_select_data.cc
debug/try_select_data.cc
+45
-68
.rewrite_util.cc.swp
main/.rewrite_util.cc.swp
+0
-0
load_and_store.cc
main/load_and_store.cc
+3
-4
No files found.
debug/load_and_store.cc
0 → 100644
View file @
71de862d
This diff is collapsed.
Click to expand it.
debug/try_select_data.cc
View file @
71de862d
...
@@ -182,6 +182,8 @@ static void sp_next(std::string db, std::string query, QueryRewrite *qr,ResType
...
@@ -182,6 +182,8 @@ static void sp_next(std::string db, std::string query, QueryRewrite *qr,ResType
}
}
}
}
//===================================================gather part==========================================================
static
static
RewritePlan
*
RewritePlan
*
my_gather
(
const
Item_field
&
i
,
Analysis
&
a
){
my_gather
(
const
Item_field
&
i
,
Analysis
&
a
){
...
@@ -197,13 +199,10 @@ my_gather(const Item_field &i, Analysis &a){
...
@@ -197,13 +199,10 @@ my_gather(const Item_field &i, Analysis &a){
static
static
void
void
my_gatherAndAddAnalysisRewritePlan
(
const
Item
&
i
,
Analysis
&
a
)
my_gatherAndAddAnalysisRewritePlan
(
const
Item
&
i
,
Analysis
&
a
){
{
a
.
rewritePlans
[
&
i
]
=
std
::
unique_ptr
<
RewritePlan
>
(
my_gather
(
static_cast
<
const
Item_field
&>
(
i
),
a
));
a
.
rewritePlans
[
&
i
]
=
std
::
unique_ptr
<
RewritePlan
>
(
my_gather
(
static_cast
<
const
Item_field
&>
(
i
),
a
));
}
}
static
static
void
void
my_process_select_lex
(
const
st_select_lex
&
select_lex
,
Analysis
&
a
){
my_process_select_lex
(
const
st_select_lex
&
select_lex
,
Analysis
&
a
){
...
@@ -234,7 +233,6 @@ my_addToReturn(ReturnMeta *const rm, int pos, const OLK &constr,
...
@@ -234,7 +233,6 @@ my_addToReturn(ReturnMeta *const rm, int pos, const OLK &constr,
const
bool
test
=
static_cast
<
unsigned
int
>
(
pos
)
==
rm
->
rfmeta
.
size
();
const
bool
test
=
static_cast
<
unsigned
int
>
(
pos
)
==
rm
->
rfmeta
.
size
();
TEST_TextMessageError
(
test
,
"ReturnMeta has badly ordered"
TEST_TextMessageError
(
test
,
"ReturnMeta has badly ordered"
" ReturnFields!"
);
" ReturnFields!"
);
const
int
salt_pos
=
has_salt
?
pos
+
1
:
-
1
;
const
int
salt_pos
=
has_salt
?
pos
+
1
:
-
1
;
std
::
pair
<
int
,
ReturnField
>
std
::
pair
<
int
,
ReturnField
>
pair
(
pos
,
ReturnField
(
false
,
name
,
constr
,
salt_pos
));
pair
(
pos
,
ReturnField
(
false
,
name
,
constr
,
salt_pos
));
...
@@ -242,12 +240,10 @@ my_addToReturn(ReturnMeta *const rm, int pos, const OLK &constr,
...
@@ -242,12 +240,10 @@ my_addToReturn(ReturnMeta *const rm, int pos, const OLK &constr,
}
}
static
void
static
void
my_addSaltToReturn
(
ReturnMeta
*
const
rm
,
int
pos
)
my_addSaltToReturn
(
ReturnMeta
*
const
rm
,
int
pos
){
{
const
bool
test
=
static_cast
<
unsigned
int
>
(
pos
)
==
rm
->
rfmeta
.
size
();
const
bool
test
=
static_cast
<
unsigned
int
>
(
pos
)
==
rm
->
rfmeta
.
size
();
TEST_TextMessageError
(
test
,
"ReturnMeta has badly ordered"
TEST_TextMessageError
(
test
,
"ReturnMeta has badly ordered"
" ReturnFields!"
);
" ReturnFields!"
);
std
::
pair
<
int
,
ReturnField
>
std
::
pair
<
int
,
ReturnField
>
pair
(
pos
,
ReturnField
(
true
,
""
,
OLK
::
invalidOLK
(),
-
1
));
pair
(
pos
,
ReturnField
(
true
,
""
,
OLK
::
invalidOLK
(),
-
1
));
rm
->
rfmeta
.
insert
(
pair
);
rm
->
rfmeta
.
insert
(
pair
);
...
@@ -257,66 +253,52 @@ my_addSaltToReturn(ReturnMeta *const rm, int pos)
...
@@ -257,66 +253,52 @@ my_addSaltToReturn(ReturnMeta *const rm, int pos)
static
static
Item
*
Item
*
my_do_rewrite_type
(
const
Item_field
&
i
,
const
OLK
&
constr
,
my_do_rewrite_type
(
const
Item_field
&
i
,
const
OLK
&
constr
,
const
RewritePlan
&
rp
,
Analysis
&
a
)
const
RewritePlan
&
rp
,
Analysis
&
a
)
{
{
const
std
::
string
&
db_name
=
a
.
getDatabaseName
();
const
std
::
string
&
db_name
=
a
.
getDatabaseName
();
const
std
::
string
plain_table_name
=
i
.
table_name
;
const
std
::
string
plain_table_name
=
i
.
table_name
;
const
FieldMeta
&
fm
=
const
FieldMeta
&
fm
=
a
.
getFieldMeta
(
db_name
,
plain_table_name
,
i
.
field_name
);
a
.
getFieldMeta
(
db_name
,
plain_table_name
,
i
.
field_name
);
//check if we need onion adjustment
//assert(constr.key == fm);
const
OnionMeta
&
om
=
a
.
getOnionMeta
(
db_name
,
plain_table_name
,
i
.
field_name
,
//check if we need onion adjustment
constr
.
o
);
const
OnionMeta
&
om
=
const
SECLEVEL
onion_level
=
a
.
getOnionLevel
(
om
);
a
.
getOnionMeta
(
db_name
,
plain_table_name
,
i
.
field_name
,
assert
(
onion_level
!=
SECLEVEL
::
INVALID
);
constr
.
o
);
const
SECLEVEL
onion_level
=
a
.
getOnionLevel
(
om
);
if
(
constr
.
l
<
onion_level
)
{
assert
(
onion_level
!=
SECLEVEL
::
INVALID
);
//need adjustment, throw exception
const
TableMeta
&
tm
=
if
(
constr
.
l
<
onion_level
)
{
a
.
getTableMeta
(
db_name
,
plain_table_name
);
//need adjustment, throw exception
throw
OnionAdjustExcept
(
tm
,
fm
,
constr
.
o
,
constr
.
l
);
const
TableMeta
&
tm
=
}
a
.
getTableMeta
(
db_name
,
plain_table_name
);
bool
is_alias
;
throw
OnionAdjustExcept
(
tm
,
fm
,
constr
.
o
,
constr
.
l
);
const
std
::
string
anon_table_name
=
}
a
.
getAnonTableName
(
db_name
,
plain_table_name
,
&
is_alias
);
const
std
::
string
anon_field_name
=
om
.
getAnonOnionName
();
bool
is_alias
;
const
std
::
string
anon_table_name
=
Item_field
*
const
res
=
a
.
getAnonTableName
(
db_name
,
plain_table_name
,
&
is_alias
);
make_item_field
(
i
,
anon_table_name
,
anon_field_name
);
const
std
::
string
anon_field_name
=
om
.
getAnonOnionName
();
Item_field
*
const
res
=
make_item_field
(
i
,
anon_table_name
,
anon_field_name
);
// HACK: to get aliases to work in DELETE FROM statements
if
(
a
.
inject_alias
&&
is_alias
)
{
res
->
db_name
=
NULL
;
}
// This information is only relevant if it comes from a
// HAVING clause.
// FIXME: Enforce this semantically.
a
.
item_cache
[
&
i
]
=
std
::
make_pair
(
res
,
constr
);
// // This rewrite may be inside of an ON DUPLICATE KEY UPDATE...
// // where the query is using the VALUES(...) function.
// if (isItem_insert_value(i)) {
// const Item_insert_value &insert_i =
// static_cast<const Item_insert_value &>(i);
// return make_item_insert_value(insert_i, res);
// }
return
res
;
// HACK: to get aliases to work in DELETE FROM statements
if
(
a
.
inject_alias
&&
is_alias
)
{
res
->
db_name
=
NULL
;
}
// This information is only relevant if it comes from a
// HAVING clause.
// FIXME: Enforce this semantically.
a
.
item_cache
[
&
i
]
=
std
::
make_pair
(
res
,
constr
);
return
res
;
}
}
static
Item
*
my_rewrite
(
const
Item
&
i
,
const
EncSet
&
req_enc
,
Analysis
&
a
){
static
Item
*
my_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
);
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,
// 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
my_do_rewrite_type
(
static_cast
<
const
Item_field
&>
(
i
),
solution
.
chooseOne
(),
*
rp
.
get
(),
a
);
return
my_do_rewrite_type
(
static_cast
<
const
Item_field
&>
(
i
),
solution
.
chooseOne
(),
*
rp
.
get
(),
a
);
}
}
...
@@ -334,7 +316,6 @@ my_rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a,
...
@@ -334,7 +316,6 @@ my_rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a,
ir
=
cached_rewritten_i
->
second
.
first
;
ir
=
cached_rewritten_i
->
second
.
first
;
olk
=
cached_rewritten_i
->
second
.
second
;
olk
=
cached_rewritten_i
->
second
.
second
;
}
else
{
}
else
{
//对于select中的选择域来说,这里对应的是rewrite_field.cc中的83, do_rewrite_type
ir
=
my_rewrite
(
i
,
rp
.
es_out
,
a
);
ir
=
my_rewrite
(
i
,
rp
.
es_out
,
a
);
olk
=
rp
.
es_out
.
chooseOne
();
olk
=
rp
.
es_out
.
chooseOne
();
}
}
...
@@ -374,13 +355,13 @@ my_rewrite_select_lex(const st_select_lex &select_lex, Analysis &a){
...
@@ -374,13 +355,13 @@ my_rewrite_select_lex(const st_select_lex &select_lex, Analysis &a){
auto
item_it
=
auto
item_it
=
RiboldMYSQL
::
constList_iterator
<
Item
>
(
select_lex
.
item_list
);
RiboldMYSQL
::
constList_iterator
<
Item
>
(
select_lex
.
item_list
);
List
<
Item
>
newList
;
List
<
Item
>
newList
;
//
item的改写, 是写到newlist里面, 所以item本身不会有变化.
//
rewrite item
for
(;;)
{
for
(;;)
{
const
Item
*
const
item
=
item_it
++
;
const
Item
*
const
item
=
item_it
++
;
if
(
!
item
)
if
(
!
item
)
break
;
break
;
my_rewrite_proj
(
*
item
,
my_rewrite_proj
(
*
item
,
*
constGetAssert
(
a
.
rewritePlans
,
item
).
get
(),
*
constGetAssert
(
a
.
rewritePlans
,
item
).
get
(),
//get the rewrite plain
a
,
&
newList
);
a
,
&
newList
);
}
}
new_select_lex
->
item_list
=
newList
;
new_select_lex
->
item_list
=
newList
;
...
@@ -394,6 +375,7 @@ AbstractQueryExecutor * my_rewrite_select(Analysis &a, LEX *lex){
...
@@ -394,6 +375,7 @@ AbstractQueryExecutor * my_rewrite_select(Analysis &a, LEX *lex){
//this is actually table list instead of join list.
//this is actually table list instead of join list.
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
);
SELECT_LEX
*
const
select_lex_res
=
my_rewrite_select_lex
(
new_lex
->
select_lex
,
a
);
SELECT_LEX
*
const
select_lex_res
=
my_rewrite_select_lex
(
new_lex
->
select_lex
,
a
);
set_select_lex
(
new_lex
,
select_lex_res
);
set_select_lex
(
new_lex
,
select_lex_res
);
return
new
DMLQueryExecutor
(
*
new_lex
,
a
.
rmeta
);
return
new
DMLQueryExecutor
(
*
new_lex
,
a
.
rmeta
);
...
@@ -420,20 +402,16 @@ static void testCreateTableHandler(std::string query,std::string db="tdb"){
...
@@ -420,20 +402,16 @@ static void testCreateTableHandler(std::string query,std::string db="tdb"){
//just like what we do in Rewrite::rewrite,dispatchOnLex
//just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
SECURITY_RATING
::
SENSITIVE
);
assert
(
analysis
.
getMasterKey
().
get
()
!=
NULL
);
assert
(
analysis
.
getMasterKey
().
get
()
!=
NULL
);
assert
(
getKey
(
std
::
string
(
"113341234"
))
!=
NULL
);
assert
(
getKey
(
std
::
string
(
"113341234"
))
!=
NULL
);
std
::
unique_ptr
<
query_parse
>
p
;
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
db
,
query
));
new
query_parse
(
db
,
query
));
LEX
*
const
lex
=
p
->
lex
();
LEX
*
const
lex
=
p
->
lex
();
std
::
string
table
(
lex
->
select_lex
.
table_list
.
first
->
table_name
);
std
::
string
table
(
lex
->
select_lex
.
table_list
.
first
->
table_name
);
my_gather_select
(
analysis
,
lex
);
my_gather_select
(
analysis
,
lex
);
auto
executor
=
my_rewrite_select
(
analysis
,
lex
);
auto
executor
=
my_rewrite_select
(
analysis
,
lex
);
QueryRewrite
*
qr
=
new
QueryRewrite
(
QueryRewrite
(
true
,
analysis
.
rmeta
,
analysis
.
kill_zone
,
executor
));
QueryRewrite
*
qr
=
new
QueryRewrite
(
QueryRewrite
(
true
,
analysis
.
rmeta
,
analysis
.
kill_zone
,
executor
));
sp_next
(
db
,
query
,
qr
,
MygetResTypeFromLuaTable
(
true
));
sp_next
(
db
,
query
,
qr
,
MygetResTypeFromLuaTable
(
true
));
}
}
...
@@ -452,7 +430,6 @@ main() {
...
@@ -452,7 +430,6 @@ main() {
ps
=
new
ProxyState
(
*
shared_ps
);
ps
=
new
ProxyState
(
*
shared_ps
);
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
globalConn
->
execute
(
"use tdb"
);
globalConn
->
execute
(
"use tdb"
);
ps
->
safeCreateEmbeddedTHD
();
ps
->
safeCreateEmbeddedTHD
();
std
::
string
query1
=
"select * from child;"
;
std
::
string
query1
=
"select * from child;"
;
std
::
vector
<
std
::
string
>
querys
{
query1
};
std
::
vector
<
std
::
string
>
querys
{
query1
};
...
...
main/.rewrite_util.cc.swp
deleted
100644 → 0
View file @
d8d81270
File deleted
main/load_and_store.cc
View file @
71de862d
...
@@ -767,16 +767,17 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
...
@@ -767,16 +767,17 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
res
[
i
].
choosenOnions
.
push_back
(
res_meta
.
choosen_onions
[
i
]);
res
[
i
].
choosenOnions
.
push_back
(
res_meta
.
choosen_onions
[
i
]);
}
}
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res
);
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res
);
//why do we need this??
//why do we need this??
std
::
string
backq
=
"show databases"
;
std
::
string
backq
=
"show databases"
;
executeAndGetResultRemote
(
globalConn
,
backq
);
executeAndGetResultRemote
(
globalConn
,
backq
);
rawMySQLReturnValue
resraw2
;
rawMySQLReturnValue
resraw2
;
//load fields in the stored file
vector
<
vector
<
string
>>
res_field
=
load_table_fields
(
res_meta
);
vector
<
vector
<
string
>>
res_field
=
load_table_fields
(
res_meta
);
resraw2
.
rowValues
=
res_field
;
resraw2
.
rowValues
=
res_field
;
resraw2
.
fieldNames
=
res_meta
.
field_names
;
resraw2
.
fieldNames
=
res_meta
.
field_names
;
resraw2
.
choosen_onions
=
res_meta
.
choosen_onions
;
resraw2
.
choosen_onions
=
res_meta
.
choosen_onions
;
for
(
unsigned
int
i
=
0
;
i
<
res_meta
.
field_types
.
size
();
++
i
){
for
(
unsigned
int
i
=
0
;
i
<
res_meta
.
field_types
.
size
();
++
i
)
{
resraw2
.
fieldTypes
.
push_back
(
static_cast
<
enum_field_types
>
(
std
::
stoi
(
res_meta
.
field_types
[
i
])));
resraw2
.
fieldTypes
.
push_back
(
static_cast
<
enum_field_types
>
(
std
::
stoi
(
res_meta
.
field_types
[
i
])));
}
}
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw2
);
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw2
);
...
@@ -820,7 +821,6 @@ static void store(std::string db, std::string table){
...
@@ -820,7 +821,6 @@ static void store(std::string db, std::string table){
for
(
auto
&
item
:
res
){
for
(
auto
&
item
:
res
){
item
.
choosenOnions
.
push_back
(
0
);
item
.
choosenOnions
.
push_back
(
0
);
}
}
//generate the backup query and then fetch the tuples
//generate the backup query and then fetch the tuples
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res
);
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res
);
std
::
string
backq
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
std
::
string
backq
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
...
@@ -829,7 +829,6 @@ static void store(std::string db, std::string table){
...
@@ -829,7 +829,6 @@ static void store(std::string db, std::string table){
for
(
auto
&
item
:
res
){
for
(
auto
&
item
:
res
){
resraw
.
choosen_onions
.
push_back
(
item
.
choosenOnions
[
0
]);
resraw
.
choosen_onions
.
push_back
(
item
.
choosenOnions
[
0
]);
}
}
//write the tuples into files
//write the tuples into files
write_raw_data_to_files
(
resraw
,
db
,
table
);
write_raw_data_to_files
(
resraw
,
db
,
table
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment