fix bugs in build()

This commit is contained in:
bookug 2016-06-15 16:35:50 +08:00
parent ab233a19e2
commit bafcf4f565
11 changed files with 851 additions and 528 deletions

View File

@ -343,8 +343,16 @@ Database::build(const string& _rdf_file)
// this->encodeRDF(ret);
this->encodeRDF_new(ret);
cout << "finish encode." << endl;
//this->kvstore->flush();
delete this->kvstore;
this->kvstore = NULL;
sync();
cout <<"sync kvstore"<<endl;
//this->kvstore->release();
//cout<<"release kvstore"<<endl;
//(this->kvstore)->open();
string _entry_file = this->getSignatureBFile();
(this->kvstore)->open();
cout << "begin build VS-Tree on " << ret << "..." << endl;
(this->vstree)->buildTree(_entry_file);
@ -353,8 +361,15 @@ Database::build(const string& _rdf_file)
cout << "after build, used " << (tv_build_end - tv_build_begin) << "ms." << endl;
cout << "finish build VS-Tree." << endl;
//this->vstree->saveTree();
delete this->vstree;
this->vstree = NULL;
sync();
cout<<"sync vstree"<<endl;
string cmd = "rm -rf " + _entry_file;
system(cmd.c_str());
cout<<"signature file removed"<<endl;
return true;
}
@ -593,6 +608,13 @@ Database::encodeRDF_new(const string _rdf_file)
//100G+ for DBpedia2014
//this->so2p_s2o(_p_id_tuples, _id_tuples_max);
//WARN:we must free the memory for id_tuples array
for(int i = 0; i < _id_tuples_max; ++i)
{
delete[] _p_id_tuples[i];
}
delete[] _p_id_tuples;
bool flag = this->saveDBInfoFile();
if (!flag)
{

View File

@ -134,8 +134,11 @@ private:
//NOTICE: below is the new one
//bool s2p_s2po_sp2o(int** _p_id_tuples, int _id_tuples_max);
bool s2p_s2o_s2po_sp2o(int** _p_id_tuples, int _id_tuples_max);
//bool s2p_s2o_s2po_sp2o_sp2n(int** _p_id_tuples, int _id_tuples_max);
bool o2p_o2s_o2ps_op2s(int** _p_id_tuples, int _id_tuples_max);
//bool o2p_o2s_o2ps_op2s_op2n(int** _p_id_tuples, int _id_tuples_max);
bool p2s_p2o_p2so(int** _p_id_tuples, int _id_tuples_max);
//bool p2s_p2o_p2so_p2n(int** _p_id_tuples, int _id_tuples_max);
bool so2p_s2o(int** _p_id_tuples, int _id_tuples_max);
static int _spo_cmp(const void* _a, const void* _b);

File diff suppressed because it is too large Load Diff

View File

@ -155,6 +155,8 @@ private:
//score the node according to degree and size
double score_node(unsigned _degree, unsigned _size);
void toStartJoin();
bool filter_before_join();
bool constant_edge_filter(int _var_i);
void preid_filter(int _var_i);

View File

@ -114,16 +114,7 @@ Strategy::handle(SPARQLquery& _query)
oid = (this->kvstore)->getIDByLiteral(triple.object);
}
#ifdef SO2P
this->kvstore->getpreIDlistBysubIDobjID(sid, oid, id_list, id_list_len);
#else
int *list1 = NULL, *list2 = NULL;
int len1 = 0, len2 = 0;
this->kvstore->getpreIDlistBysubID(sid, list1, len1);
this->kvstore->getpreIDlistByobjID(oid, list2, len2);
Util::intersect(id_list, id_list_len, list1, len1, list2, len2);
#endif
//copy to result list
for(int i = 0; i < id_list_len; ++i)
{
@ -230,6 +221,10 @@ Strategy::handler0(BasicQuery* _bq, vector<int*>& _result_list)
const EntityBitSet& entityBitSet = _bq->getVarBitSet(i);
IDList* idListPtr = &( _bq->getCandidateList(i) );
this->vstree->retrieveEntity(entityBitSet, idListPtr);
if(!flag)
{
_bq->setReady(i);
}
//the basic query should end if one non-literal var has no candidates
if(idListPtr->size() == 0 && !flag)
{
@ -237,6 +232,8 @@ Strategy::handler0(BasicQuery* _bq, vector<int*>& _result_list)
}
}
//if(_bq->isReady(0))
//cout<<"error: var 0 is ready?"<<endl;
//TODO:end directly if one is empty!
long tv_retrieve = Util::get_cur_time();

View File

@ -1190,12 +1190,14 @@ bool KVstore::setpreIDlistBysubID(int _subid, const int* _preidlist, int _list_l
}
//for preID 2 subIDlist
bool KVstore::open_preID2subIDlist(const int _mode)
bool
KVstore::open_preID2subIDlist(const int _mode)
{
return this->open(this->preID2subIDlist, KVstore::s_pID2sIDlist, _mode);
}
bool KVstore::getsubIDlistBypreID(int _preid, int*& _subidlist, int& _list_len)
bool
KVstore::getsubIDlistBypreID(int _preid, int*& _subidlist, int& _list_len)
{
char* _tmp = NULL;
int _len = 0;
@ -1218,19 +1220,22 @@ bool KVstore::getsubIDlistBypreID(int _preid, int*& _subidlist, int& _list_len)
return true;
}
bool KVstore::setsubIDlistBypreID(int _preid, const int* _subidlist, int _list_len)
bool
KVstore::setsubIDlistBypreID(int _preid, const int* _subidlist, int _list_len)
{
return this->setValueByKey
(this->preID2subIDlist, (char*)&_preid, sizeof(int),(char*)_subidlist, _list_len * sizeof(int));
}
//for objID 2 preIDlist
bool KVstore::open_objID2preIDlist(const int _mode)
bool
KVstore::open_objID2preIDlist(const int _mode)
{
return this->open(this->objID2preIDlist, KVstore::s_oID2pIDlist, _mode);
}
bool KVstore::getpreIDlistByobjID(int _objid, int*& _preidlist, int& _list_len)
bool
KVstore::getpreIDlistByobjID(int _objid, int*& _preidlist, int& _list_len)
{
char* _tmp = NULL;
int _len = 0;
@ -1253,19 +1258,22 @@ bool KVstore::getpreIDlistByobjID(int _objid, int*& _preidlist, int& _list_len)
return true;
}
bool KVstore::setpreIDlistByobjID(int _objid, const int* _preidlist, int _list_len)
bool
KVstore::setpreIDlistByobjID(int _objid, const int* _preidlist, int _list_len)
{
return this->setValueByKey
(this->objID2preIDlist, (char*)&_objid, sizeof(int),(char*)_preidlist, _list_len * sizeof(int));
}
//for preID 2 objIDlist
bool KVstore::open_preID2objIDlist(const int _mode)
bool
KVstore::open_preID2objIDlist(const int _mode)
{
return this->open(this->preID2objIDlist, KVstore::s_pID2oIDlist, _mode);
}
bool KVstore::getobjIDlistBypreID(int _preid, int*& _objidlist, int& _list_len)
bool
KVstore::getobjIDlistBypreID(int _preid, int*& _objidlist, int& _list_len)
{
char* _tmp = NULL;
int _len = 0;
@ -1288,20 +1296,24 @@ bool KVstore::getobjIDlistBypreID(int _preid, int*& _objidlist, int& _list_len)
return true;
}
bool KVstore::setobjIDlistBypreID(int _preid, const int* _objidlist, int _list_len)
bool
KVstore::setobjIDlistBypreID(int _preid, const int* _objidlist, int _list_len)
{
return this->setValueByKey
(this->preID2objIDlist, (char*)&_preid, sizeof(int), (char*)_objidlist, _list_len * sizeof(int));
}
//for subID&objID2preIDlist _mode is either KVstore::CREATE_MODE or KVstore::READ_WRITE_MODE
bool KVstore::open_subIDobjID2preIDlist(const int _mode)
bool
KVstore::open_subIDobjID2preIDlist(const int _mode)
{
return this->open(this->subIDobjID2preIDlist, KVstore::s_sIDoID2pIDlist, _mode);
}
bool KVstore::getpreIDlistBysubIDobjID(int _subid, int _objid, int*& _preidlist, int& _list_len)
bool
KVstore::getpreIDlistBysubIDobjID(int _subid, int _objid, int*& _preidlist, int& _list_len)
{
#ifdef SO2P
char* _tmp = NULL;
int _len = 0;
int* _sp = new int[2];
@ -1323,11 +1335,20 @@ bool KVstore::getpreIDlistBysubIDobjID(int _subid, int _objid, int*& _preidlist,
memcpy((char*)_preidlist, _tmp, sizeof(int)*_list_len);
}
//delete[] _tmp;
#else
int *list1 = NULL, *list2 = NULL;
int len1 = 0, len2 = 0;
this->getpreIDlistBysubID(_subid, list1, len1);
this->getpreIDlistByobjID(_objid, list2, len2);
Util::intersect(_preidlist, _list_len, list1, len1, list2, len2);
#endif
return true;
}
bool KVstore::setpreIDlistBysubIDobjID(int _subid, int _objid, const int* _preidlist, int _list_len)
//NOTICE:this is not used because so2p is implemented by s2p and o2p now
bool
KVstore::setpreIDlistBysubIDobjID(int _subid, int _objid, const int* _preidlist, int _list_len)
{
int* _sp = new int[2];
_sp[0] = _subid;
@ -1342,12 +1363,14 @@ bool KVstore::setpreIDlistBysubIDobjID(int _subid, int _objid, const int* _preid
}
//preID2subID&objIDlist
bool KVstore::open_preID2subIDobjIDlist(const int _mode)
bool
KVstore::open_preID2subIDobjIDlist(const int _mode)
{
return this->open(this->preID2subIDobjIDlist, KVstore::s_pID2sIDoIDlist, _mode);
}
bool KVstore::getsubIDobjIDlistBypreID(int _preid, int*& _subid_objidlist, int& _list_len)
bool
KVstore::getsubIDobjIDlistBypreID(int _preid, int*& _subid_objidlist, int& _list_len)
{
char* _tmp = NULL;
int _len = 0;
@ -1370,12 +1393,121 @@ bool KVstore::getsubIDobjIDlistBypreID(int _preid, int*& _subid_objidlist, int&
return true;
}
bool KVstore::setsubIDobjIDlistBypreID(int _preid, const int* _subid_objidlist, int _list_len)
bool
KVstore::setsubIDobjIDlistBypreID(int _preid, const int* _subid_objidlist, int _list_len)
{
return this->setValueByKey
(this->preID2subIDobjIDlist, (char*)&_preid, sizeof(int),(char*)_subid_objidlist, _list_len * sizeof(int));
}
//preID2num
bool
KVstore::open_preID2num(const int _mode)
{
return this->open(this->preID2num, KVstore::s_pID2num, _mode);
}
int
KVstore::getNumBypreID(int _preid)
{
char* _tmp = NULL;
int _len = 0;
bool _get = this->getValueByKey(this->preID2num, (char*)&_preid, sizeof(int), _tmp, _len);
if(!_get)
{
return 0;
}
return _tmp[0];
}
bool
KVstore::setNumBypreID(int _preid, int _tripleNum)
{
return this->setValueByKey(this->preID2num, (char*)&_preid, sizeof(int), (char*)&_tripleNum, sizeof(int));
}
//subIDpreID2num
bool
KVstore::open_subIDpreID2num(const int _mode)
{
return this->open(this->subIDpreID2num, KVstore::s_sIDpID2num, _mode);
}
int
KVstore::getNumBysubIDpreID(int _subid, int _preid)
{
int* _key = new int[2];
_key[0] = _subid;
_key[1] = _preid;
char* _tmp = NULL;
int _len = 0;
bool _get = this->getValueByKey(this->subIDpreID2num, (char*)_key, 2 * sizeof(int), _tmp, _len);
if(!_get)
{
return 0;
}
delete[] _key;
return _tmp[0];
}
bool
KVstore::setNumBysubIDpreID(int _subid, int _preid, int _tripleNum)
{
int* _key = new int[2];
_key[0] = _subid;
_key[1] = _preid;
bool ret = this->setValueByKey(this->subIDpreID2num, (char*)_key, 2 * sizeof(int), (char*)&_tripleNum, sizeof(int));
delete[] _key;
return ret;
}
//objIDpreID2num
bool
KVstore::open_objIDpreID2num(const int _mode)
{
return this->open(this->objIDpreID2num, KVstore::s_oIDpID2num, _mode);
}
int
KVstore::getNumByobjIDpreID(int _objid, int _preid)
{
int* _key = new int[2];
_key[0] = _objid;
_key[1] = _preid;
char* _tmp = NULL;
int _len = 0;
bool _get = this->getValueByKey(this->objIDpreID2num, (char*)_key, 2 * sizeof(int), _tmp, _len);
if(!_get)
{
return 0;
}
delete[] _key;
return _tmp[0];
}
bool
KVstore::setNumByobjIDpreID(int _objid, int _preid, int _tripleNum)
{
int* _key = new int[2];
_key[0] = _objid;
_key[1] = _preid;
bool ret = this->setValueByKey(this->objIDpreID2num, (char*)_key, 2 * sizeof(int), (char*)&_tripleNum, sizeof(int));
delete[] _key;
return ret;
}
//==========================================================================================================================
//set the store_path as the root dir of this KVstore
//initial all Tree pointer as NULL
KVstore::KVstore(const string _store_path){
@ -1407,39 +1539,69 @@ KVstore::KVstore(const string _store_path){
this->subIDobjID2preIDlist = NULL;
this->preID2subIDobjIDlist = NULL;
this->preID2num = NULL;
this->subIDpreID2num = NULL;
this->objIDpreID2num = NULL;
}
//release all the memory used in this KVstore
//before destruction
KVstore::~KVstore()
{
//this->release();
this->flush();
this->release();
}
void
KVstore::release()
{
delete this->entity2id;
this->entity2id = NULL;
delete this->id2entity;
this->id2entity = NULL;
delete this->literal2id;
this->literal2id = NULL;
delete this->id2literal;
this->id2literal = NULL;
delete this->predicate2id;
this->predicate2id = NULL;
delete this->id2predicate;
this->id2predicate = NULL;
delete this->objID2subIDlist;
this->objID2subIDlist = NULL;
delete this->subID2objIDlist;
this->subID2objIDlist = NULL;
delete this->objIDpreID2subIDlist;
this->objIDpreID2subIDlist = NULL;
delete this->subIDpreID2objIDlist;
this->subIDpreID2objIDlist = NULL;
delete this->subID2preIDobjIDlist;
this->subID2preIDobjIDlist = NULL;
delete this->objID2preIDsubIDlist;
this->objID2preIDsubIDlist = NULL;
delete this->subID2preIDlist;
this->subID2preIDlist = NULL;
delete this->preID2subIDlist;
this->preID2subIDlist = NULL;
delete this->objID2preIDlist;
this->objID2preIDlist = NULL;
delete this->preID2objIDlist;
this->preID2objIDlist = NULL;
delete this->subIDobjID2preIDlist;
this->subIDobjID2preIDlist = NULL;
delete this->preID2subIDobjIDlist;
this->preID2subIDobjIDlist = NULL;
//delete this->preID2num;
//delete this->subIDpreID2num;
//delete this->objIDpreID2num;
}
/*
@ -1448,7 +1610,9 @@ KVstore::~KVstore()
* any Tree pointer that is null or
* has not been modified will do nothing
* */
void KVstore::flush(){
void
KVstore::flush()
{
this->flush(this->entity2id);
this->flush(this->id2entity);
@ -1473,35 +1637,23 @@ void KVstore::flush(){
this->flush(this->preID2objIDlist);
this->flush(this->subIDobjID2preIDlist);
this->flush(preID2subIDobjIDlist);
//this->flush(this->preID2num);
//this->flush(this->subIDpreID2num);
//this->flush(this->objIDpreID2num);
}
/* Release all the memory used in this KVstore,
* following an flush() for each Tree pointer
* any Tree pointer that is null or
* has not been modified will do nothing
* */
//void KVstore::release(){
// cout << "release of KVstore..." << endl;
// this->release(this->entity2id);
// this->release(this->id2entity);
//
// this->release(this->literal2id);
// this->release(this->id2literal);
//
// this->release(this->predicate2id);
// this->release(this->id2predicate);
//
// this->release(this->objID2subIDlist);
// this->release(this->subID2objIDlist);
//
// this->release(this->objIDpreID2subIDlist);
// this->release(this->subIDpreID2objIDlist);
//
// this->release(this->subID2preIDobjIDlist);
// this->release(this->objID2preIDsubIDlist);
//}
void
KVstore::flush(Tree* _p_btree)
{
if(_p_btree != NULL)
{
_p_btree->save();
}
}
void KVstore::open()
void
KVstore::open()
{
cout << "open KVstore" << endl;
@ -1531,20 +1683,17 @@ void KVstore::open()
this->open(this->subIDobjID2preIDlist, KVstore::s_sIDoID2pIDlist, KVstore::READ_WRITE_MODE);
#endif
this->open(this->preID2subIDobjIDlist, KVstore::s_pID2sIDoIDlist, KVstore::READ_WRITE_MODE);
}
void KVstore::flush(Tree* _p_btree)
{
if(_p_btree != NULL)
{
_p_btree->save();
}
//this->open(this->preID2num, KVstore::s_pID2num, KVstore::READ_WRITE_MODE);
//this->open(this->subIDpreID2num, KVstore::s_sIDpID2num, KVstore::READ_WRITE_MODE);
//this->open(this->objIDpreID2num, KVstore::s_oIDpID2num, KVstore::READ_WRITE_MODE);
}
/* Open a btree according the mode */
/* CREATE_MODE: build a new btree and delete if exist */
/* READ_WRITE_MODE: open a btree, btree must exist */
bool KVstore::open(Tree* & _p_btree, const string _tree_name, const int _mode){
bool
KVstore::open(Tree* & _p_btree, const string _tree_name, const int _mode){
if(_p_btree != NULL)
{
return false;
@ -1626,3 +1775,7 @@ string KVstore::s_pID2oIDlist="s_pID2oIDlist";
string KVstore::s_sIDoID2pIDlist="s_sIDoID2pIDlist";
string KVstore::s_pID2sIDoIDlist="s_pID2sIDoIDlist";
string KVstore::s_pID2num = "s_pID2num";
string KVstore::s_sIDpID2num = "s_sIDpID2num";
string KVstore::s_oIDpID2num = "s_oIDpID2num";

View File

@ -138,10 +138,30 @@ public:
bool getsubIDobjIDlistBypreID(int _preid, int*& _subid_objidlist, int& _list_len);
bool setsubIDobjIDlistBypreID(int _preid, const int* _subid_objidlist, int _list_len);
//QUERY:is the below 3 indexes needed?
//In fact, p2so can compute the num of triples if dividing so_len by 2
//However, sometimes this can be very large and costly
//For example, the predicate is <rdf:type>
//for predicate 2 triple num
bool open_preID2num(const int _mode);
int getNumBypreID(int _preid);
bool setNumBypreID(int _preid, int _tripleNum);
//for subject&predicate 2 triple num
bool open_subIDpreID2num(const int _mode);
int getNumBysubIDpreID(int _subID, int _preID);
bool setNumBysubIDpreID(int _subID, int _preID, int _tripleNum);
//for object&predicate 2 triple num
bool open_objIDpreID2num(const int _mode);
int getNumByobjIDpreID(int _objid, int _preid);
bool setNumByobjIDpreID(int _objid, int _preid, int _tripleNum);
KVstore(std::string _store_path = ".");
~KVstore();
void flush();
//void release();
void release();
void open();
private:
@ -196,6 +216,13 @@ private:
static std::string s_sIDoID2pIDlist;
static std::string s_pID2sIDoIDlist;
Tree* preID2num;
Tree* subIDpreID2num;
Tree* objIDpreID2num;
static std::string s_pID2num;
static std::string s_sIDpID2num;
static std::string s_oIDpID2num;
void flush(Tree* _p_btree);
bool setValueByKey(Tree* _p_btree, const char* _key, int _klen, const char* _val, int _vlen);
bool getValueByKey(Tree* _p_btree, const char* _key, int _klen, char*& _val, int& _vlen);

View File

@ -20,8 +20,9 @@ class Storage
public:
static const unsigned BLOCK_SIZE = 1 << 16; //fixed size of disk-block
//there are 18 B+Tree indexes and one vstree index, so set 3G buffer size
static const unsigned long long MAX_BUFFER_SIZE = 0xC0000000; //max buffer size
//static const unsigned long long MAX_BUFFER_SIZE = 0xC0000000; //max buffer size
//static const unsigned long long MAX_BUFFER_SIZE = 0x1ffffffff; //max buffer size
static const unsigned long long MAX_BUFFER_SIZE = 0xffffffff; //max buffer size
//static const unsigned SET_BUFFER_SIZE = 1 << 30; //set buffer size
static const unsigned HEAP_SIZE = MAX_BUFFER_SIZE/Node::INTL_SIZE;
static const unsigned MAX_BLOCK_NUM = 1 << 24; //max block-num

View File

@ -55,8 +55,10 @@ BasicQuery::clear()
delete[] this->candidate_list;
this->candidate_list = NULL;
delete[] this->is_literal_candidate_added;
this->is_literal_candidate_added = NULL;
//delete[] this->is_literal_candidate_added;
//this->is_literal_candidate_added = NULL;
delete[] this->ready;
this->ready = NULL;
delete[] this->need_retrieve;
this->need_retrieve = NULL;
for (unsigned i=0;i<this->result_list.size();++i)
@ -265,17 +267,17 @@ BasicQuery::isFreeLiteralVariable(int _var)
return true;
}
bool
BasicQuery::isAddedLiteralCandidate(int _var)
{
return this->is_literal_candidate_added[_var];
}
//bool
//BasicQuery::isAddedLiteralCandidate(int _var)
//{
//return this->is_literal_candidate_added[_var];
//}
void
BasicQuery::setAddedLiteralCandidate(int _var)
{
this->is_literal_candidate_added[_var] = true;
}
//void
//BasicQuery::setAddedLiteralCandidate(int _var)
//{
//this->is_literal_candidate_added[_var] = true;
//}
bool
BasicQuery::if_need_retrieve(int _var)
@ -289,6 +291,21 @@ BasicQuery::isSatelliteInJoin(int _var)
return _var >= 0 && _var < this->graph_var_num && !(this->need_retrieve[_var]);
}
bool
BasicQuery::isReady(int _var) const
{
return _var >= 0 && _var < this->graph_var_num && this->ready[_var];
}
void
BasicQuery::setReady(int _var)
{
if(_var >= 0 && _var < this->graph_var_num)
{
this->ready[_var] = true;
}
}
void
BasicQuery::updateSubSig(int _sub_id, int _pre_id, int _obj_id, string _obj,int _line_id)
{
@ -342,7 +359,7 @@ BasicQuery::updateObjSig(int _obj_id, int _pre_id, int _sub_id, string _sub,int
}
// encode relative signature data of the query graph
void
bool
BasicQuery::encodeBasicQuery(KVstore* _p_kvstore, const vector<string>& _query_var)
{
//TODO:the third parameter should be selected predicate variables
@ -437,6 +454,7 @@ BasicQuery::encodeBasicQuery(KVstore* _p_kvstore, const vector<string>& _query_v
//BETTER:this is too robust, not only one query, try return false
cerr << "invalid query because the pre is not found: " << pre << endl;
//exit(1);
return false;
}
}
int sub_id = -1;
@ -512,6 +530,7 @@ BasicQuery::encodeBasicQuery(KVstore* _p_kvstore, const vector<string>& _query_v
}
cout << "OUT encodeBasicQuery" << endl;
return true;
}
int
@ -575,7 +594,8 @@ BasicQuery::null_initial()
this->triple_vt.clear();
this->var_str2id.clear();
this->var_degree = NULL;
this->is_literal_candidate_added = NULL;
//this->is_literal_candidate_added = NULL;
this->ready = NULL;
this->need_retrieve = NULL;
this->edge_id = NULL;
this->edge_nei_id = NULL;
@ -607,7 +627,8 @@ BasicQuery::initial()
this->edge_pre_id = new int*[BasicQuery::MAX_VAR_NUM];
this->edge_type = new char*[BasicQuery::MAX_VAR_NUM];
this->is_literal_candidate_added = new bool[BasicQuery::MAX_VAR_NUM];
//this->is_literal_candidate_added = new bool[BasicQuery::MAX_VAR_NUM];
this->ready = new bool[BasicQuery::MAX_VAR_NUM];
this->need_retrieve = new bool[BasicQuery::MAX_VAR_NUM];
for(int i = 0; i < BasicQuery::MAX_VAR_NUM; ++i)
@ -615,7 +636,8 @@ BasicQuery::initial()
this->var_degree[i] = 0;
this->var_sig[i].reset();
this->var_name[i] = "";
this->is_literal_candidate_added[i] = false;
//this->is_literal_candidate_added[i] = false;
this->ready[i] = false;
this->need_retrieve[i] = false;
this->edge_sig[i] = new EdgeBitSet[BasicQuery::MAX_VAR_NUM];
@ -817,28 +839,49 @@ BasicQuery::getVarID_FirstProcessWhenJoin()
{
int min_var = -1;
int min_size = Util::TRIPLE_NUM_MAX;
//int min_var2 = -1;
//int min_size2 = Util::TRIPLE_NUM_MAX;
for(int i = 0; i < this->graph_var_num; ++i)
{
// when join variables' mapping candidate list, we should start with entity variable.
// since literal variables' candidate list may not include all literals.
if(this->isLiteralVariable(i) || this->isSatelliteInJoin(i))
//if(this->isSatelliteInJoin(i))
//if(this->isLiteralVariable(i) || this->isSatelliteInJoin(i))
if(!this->isReady(i))
{
cout<<"var "<<i<<" is not ready!"<<endl;
continue;
}
else
cout<<"var "<<i<<" is ready!"<<endl;
int tmp_size = (this->candidate_list[i]).size();
if(tmp_size < min_size)
{
min_var = i;
min_size = tmp_size;
}
int tmp_size = (this->candidate_list[i]).size();
//if(this->isLiteralVariable(i))
//{
//if(tmp_size < min_size2)
//{
//min_var2 = i;
//min_size2 = tmp_size;
//}
//}
//else
//{
if(tmp_size < min_size)
{
min_var = i;
min_size = tmp_size;
}
//}
}
if (min_var == -1)
if(min_var == -1)
{
// in this case, all variables may include literal results.
// then the join-step starting with any variables is ok.
return 0;
// in this case, all core vertices are literal variables
// we must generate candidates for satellites or use p2o to add literals for a core vertex
// For example:
// A->B<-C select A B C
//return min_var2;
return -1;
}
else
{
@ -846,7 +889,8 @@ BasicQuery::getVarID_FirstProcessWhenJoin()
}
}
string BasicQuery::candidate_str()
string
BasicQuery::candidate_str()
{
stringstream _ss;

View File

@ -124,7 +124,8 @@ private:
int* var_degree;
//whether has added the variable's literal candidate
bool* is_literal_candidate_added;
//bool* is_literal_candidate_added;
bool* ready;
//if need to be retrieved by vstree or generate when join(first is graph var)
bool* need_retrieve;
@ -245,17 +246,21 @@ public:
bool isFreeLiteralVariable(int _var);
// check whether has added _var's literal candidates
bool isAddedLiteralCandidate(int _var);
//bool isAddedLiteralCandidate(int _var);
// set _var's literal candidates has been added
void setAddedLiteralCandidate(int _var);
//void setAddedLiteralCandidate(int _var);
//check if need to be retrieved
bool if_need_retrieve(int _var);
bool isSatelliteInJoin(int _var);
//if the candidates of var(in join) is all ready
bool isReady(int _var) const;
void setReady(int _var);
// encode relative signature data of the query graph
void encodeBasicQuery(KVstore* _p_kvstore, const std::vector<std::string>& _query_var);
bool encodeBasicQuery(KVstore* _p_kvstore, const std::vector<std::string>& _query_var);
unsigned getPreVarNum() const;
const PreVar& getPreVarByID(unsigned) const;

View File

@ -16,8 +16,10 @@
class VNode
{
public:
static const int MAX_CHILD_NUM = 151;
static const int MIN_CHILD_NUM = 60;
static const int MAX_CHILD_NUM = 200;
//static const int MAX_CHILD_NUM = 151;
static const int MIN_CHILD_NUM = 100;
//static const int MIN_CHILD_NUM = 60;
//debug
// static const int MAX_CHILD_NUM = 50;