Merge branch 'chenjiaqi'
merge chenjia's fixes and optimization to Query:: getFinalResult
This commit is contained in:
commit
546f56790a
|
@ -829,6 +829,7 @@ void GeneralEvaluation::getFinalResult(ResultSet &ret_result)
|
|||
useful += this->temp_result->results[i].getAllVarset();
|
||||
}
|
||||
|
||||
if ((int)this->temp_result->results.size() > 1)
|
||||
{
|
||||
TempResultSet *new_temp_result = new TempResultSet();
|
||||
|
||||
|
@ -1063,58 +1064,52 @@ void GeneralEvaluation::getFinalResult(ResultSet &ret_result)
|
|||
vector<int> proj2temp = ret_result_varset.mapTo(result0.getAllVarset());
|
||||
int id_cols = result0.id_varset.getVarsetSize();
|
||||
|
||||
for (unsigned i = 0; i < ret_result.ansNum; i++)
|
||||
{
|
||||
if (!ret_result.checkUseStream())
|
||||
{
|
||||
ret_result.answer[i] = new string [ret_result.select_var_num];
|
||||
}
|
||||
vector<bool> isel;
|
||||
for (int i = 0; i < result0.id_varset.getVarsetSize(); i++)
|
||||
isel.push_back(this->query_tree.getGroupPattern().group_pattern_subject_object_maximal_varset.findVar(result0.id_varset.vars[i]));
|
||||
|
||||
for (int j = 0; j < ret_result.select_var_num; j++)
|
||||
{
|
||||
if (proj2temp[j] < id_cols)
|
||||
{
|
||||
unsigned ans_id = result0.result[i].id[proj2temp[j]];
|
||||
|
||||
if (!ret_result.checkUseStream())
|
||||
{
|
||||
ret_result.answer[i][j] = "";
|
||||
if (ans_id != INVALID)
|
||||
{
|
||||
if (this->query_tree.getGroupPattern().group_pattern_subject_object_maximal_varset.findVar(result0.id_varset.vars[proj2temp[j]]))
|
||||
this->stringindex->addRequest(ans_id, &ret_result.answer[i][j], true);
|
||||
else
|
||||
this->stringindex->addRequest(ans_id, &ret_result.answer[i][j], false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string ans_str = "";
|
||||
if (ans_id != INVALID)
|
||||
{
|
||||
if (this->query_tree.getGroupPattern().group_pattern_subject_object_maximal_varset.findVar(result0.id_varset.vars[proj2temp[j]]))
|
||||
this->stringindex->randomAccess(ans_id, &ans_str, true);
|
||||
else
|
||||
this->stringindex->randomAccess(ans_id, &ans_str, false);
|
||||
}
|
||||
ret_result.writeToStream(ans_str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ret_result.checkUseStream())
|
||||
ret_result.answer[i][j] = result0.result[i].str[proj2temp[j] - id_cols];
|
||||
else
|
||||
ret_result.writeToStream(result0.result[i].str[proj2temp[j] - id_cols]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ret_result.checkUseStream())
|
||||
{
|
||||
for (unsigned i = 0; i < ret_result.ansNum; i++)
|
||||
{
|
||||
ret_result.answer[i] = new string [ret_result.select_var_num];
|
||||
|
||||
for (int j = 0; j < ret_result.select_var_num; j++)
|
||||
{
|
||||
int k = proj2temp[j];
|
||||
if (k < id_cols)
|
||||
{
|
||||
unsigned ans_id = result0.result[i].id[k];
|
||||
if (ans_id != INVALID)
|
||||
this->stringindex->addRequest(ans_id, &ret_result.answer[i][j], isel[k]);
|
||||
}
|
||||
else
|
||||
ret_result.answer[i][j] = result0.result[i].str[k - id_cols];
|
||||
}
|
||||
}
|
||||
|
||||
this->stringindex->trySequenceAccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned i = 0; i < ret_result.ansNum; i++)
|
||||
for (int j = 0; j < ret_result.select_var_num; j++)
|
||||
{
|
||||
int k = proj2temp[j];
|
||||
if (k < id_cols)
|
||||
{
|
||||
string ans_str;
|
||||
|
||||
unsigned ans_id = result0.result[i].id[k];
|
||||
if (ans_id != INVALID)
|
||||
this->stringindex->randomAccess(ans_id, &ans_str, isel[k]);
|
||||
|
||||
ret_result.writeToStream(ans_str);
|
||||
}
|
||||
else
|
||||
ret_result.writeToStream(result0.result[i].str[k - id_cols]);
|
||||
}
|
||||
|
||||
ret_result.resetStream();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,11 +101,6 @@ bool StringIndexFile::randomAccess(unsigned id, string *str)
|
|||
return true;
|
||||
}
|
||||
|
||||
void StringIndexFile::addRequest(unsigned id, std::string *str)
|
||||
{
|
||||
this->request.push_back(AccessRequest(id, this->index_table[id].offset, this->index_table[id].length, str));
|
||||
}
|
||||
|
||||
void StringIndexFile::trySequenceAccess()
|
||||
{
|
||||
if (this->request.empty())
|
||||
|
|
|
@ -87,7 +87,10 @@ class StringIndexFile
|
|||
}
|
||||
|
||||
bool randomAccess(unsigned id, std::string *str);
|
||||
void addRequest(unsigned id, std::string *str);
|
||||
inline void addRequest(unsigned id, std::string *str)
|
||||
{
|
||||
this->request.push_back(AccessRequest(id, this->index_table[id].offset, this->index_table[id].length, str));
|
||||
}
|
||||
void trySequenceAccess();
|
||||
|
||||
void change(unsigned id, KVstore &kv_store);
|
||||
|
|
|
@ -65,7 +65,7 @@ Stream::Stream(std::vector<TYPE_ENTITY_LITERAL_ID>& _keys, std::vector<bool>& _d
|
|||
|
||||
this->mode = 0; //wait for writing records
|
||||
|
||||
int size = _rownum * _colnum * 100 / Util::GB;
|
||||
long long size = (long long)_rownum * (long long)_colnum * 100 / Util::GB;
|
||||
//TODO: get this arg from memory manager
|
||||
if(Util::memoryLeft() < size)
|
||||
{
|
||||
|
|
|
@ -433,17 +433,26 @@ Util::memoryLeft()
|
|||
FILE* fp = fopen("/proc/meminfo", "r");
|
||||
if(fp == NULL)
|
||||
return -1;
|
||||
|
||||
char str[20], tail[3];
|
||||
unsigned t, sum, unuse = 0; //WARN:unsigned,memory cant be too large!
|
||||
fscanf(fp, "%s%u%s", str, &sum, tail); //MemTotal, KB
|
||||
fscanf(fp, "%s%u%s", str, &unuse, tail); //MemFree
|
||||
fscanf(fp, "%s%u%s", str, &t, tail);
|
||||
if(strcmp(str, "MemAvailable") == 0)
|
||||
unsigned num, avail = 0, free = 0, buffer = 0, cache = 0; //WARN:unsigned,memory cant be too large!
|
||||
while (fscanf(fp, "%s%u%s", str, &num, tail) != EOF)
|
||||
{
|
||||
unuse = t;
|
||||
if(strcmp(str, "MemAvailable:") == 0)
|
||||
avail = num;
|
||||
if(strcmp(str, "MemFree:") == 0)
|
||||
free = num;
|
||||
if(strcmp(str, "Buffers:") == 0)
|
||||
buffer = num;
|
||||
if(strcmp(str, "Cached:") == 0)
|
||||
cache = num;
|
||||
}
|
||||
|
||||
if (avail == 0)
|
||||
avail = free + buffer + cache;
|
||||
|
||||
fclose(fp);
|
||||
return unuse / Util::MB;
|
||||
return avail / Util::MB;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
Loading…
Reference in New Issue