Exemplo n.º 1
0
/**
* Run a particular query
*/
string run_query( string query, int printlogicaltree, int printphysicaltree, int fromInsert, bool is_delete)
{
	int status;
	time_t start = time (NULL);
	resetDIOs();
	status = query2logical(query);
	if ( status == -1) return "-1";
	else if (status != 3) //all queries other than select return status 3
	{
		// THIS IS A SELECT QUERY.
		if (printlogicaltree == 1) { cout << "I am printing the logical tree. " << endl;}
			
		cout << endl;

		if (logical2physical() == -1) return "-1";
			
		if (printphysicaltree == 1) { cout << "I am printing the physical tree. " << endl;}
		
		if (fromInsert)
			return printresults (0,1);
		else if (is_delete)
			printresults(1,0);
		else
			printresults(0,0);
		
	}

	cout << endl << "Total number of disk I/Os: " << getDIOs() << endl << endl;
	
	time_t end = time (NULL);
	printf("%4.4f seconds taken to execute the query\n\n",(float)(end-start)/1000.0);
	//Resetting global variables for next query
	ConditionMap.clear();
	conditions.clear();
	P.clear();
	T.clear();
	Pr.clear();

	return "";
}
void FileProjections::createAllProjections()
{
    if (graph->isEmpty())
    {
        return;
    }

    if(isMemoryUsed())
    {
        Projections::createAllProjections();
        return;
    }

    // Prepare nodes
    NodeMap* nodeList = graph->getNodeMap();
    unsigned count = nodeList->size();

    if (!count)
        return;

    ProjectionsWriter writer(*this);
    setWorker(&writer, true);
    startProcess(0u, count - 1);

    unsigned oldSize = projectionsList->size();
    bool isWasEmpty = !oldSize;

    projectionsList->resize(count, nullptr);
    projectionsList->shrink_to_fit();

    auto oldStart = projectionsList->begin();
    auto oldEnd = projectionsList->begin() + oldSize;
    auto it = nodeList->begin();
    Projection* pr;

    std::string saveName(graphFileName);
    unsigned nameSize = saveName.size();

    unsigned currentId;
    unsigned pos = oldSize;

    for(unsigned i = 0u; i < count; ++i, ++it)
    {
        if (isInterrupted())
        {
            projectionStatus = Status::PARTIAL;
            // if interrupted on null filled projections, shrink list
            projectionsList->resize(pos);
            break;
        }

        updateProgress(i);

        currentId = it->first;
        pr = nullptr;
        // Projection exist - skip
        if (!isWasEmpty)
        {
            auto e = std::lower_bound(oldStart, oldEnd, currentId,
                                      Projection::lessById);
            if (e != oldEnd && (*e)->getId() == currentId)
            {
                pr = *e;
                if (pr->fileExist())
                    continue;
            }
        }
        if (!pr)
        {
            pr = new Projection(currentId);
            (*projectionsList)[pos] = pr;
            ++pos;
        }
        pr->createProjection(*graph);
        if (pr->isInterrupted())
        {
            continue;
        }

        ProjectionsReader::projectionFileName(saveName, nameSize, currentId);

        bool result = writer.saveProjection(saveName.data(), pr);

        if (result)
        {
            pr->setFileExist(true);
        }
        // stay loaded last projection
        if (count - i > 1)
        {
            pr->clear();
        }
        else
        {
            loadedProjection = pr;
        }
    }

    if (!isWasEmpty)
    {
        auto end = projectionsList->end();
        std::sort(oldStart, end, Projection::less);
    }
    if (!isInterrupted())
        projectionStatus = Status::ALL;
    completeProcess();
}