8000 fixed issue #4185: On execution of FULLTEXT search / AQL query db is … by jsteemann · Pull Request #4238 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

fixed issue #4185: On execution of FULLTEXT search / AQL query db is … #4238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing some stuff
  • Loading branch information
graetzer committed Jan 8, 2018
commit 3d6e2660df700c690622a4e6fe42c090ea92013d
43 changes: 30 additions & 13 deletions arangod/Aql/OptimizerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Graph/TraverserOptions.h"
#include "Indexes/Index.h"
#include "Transaction/Methods.h"
#include "VocBase/Methods/Collections.h"

#include <boost/optional.hpp>
#include <tuple>
Expand Down Expand Up @@ -4489,10 +4490,14 @@ void arangodb::aql::inlineSubqueriesRule(Optimizer* opt,
opt->addPlan(std::move(plan), rule, modified);
}

static bool isValueTypeString(AstNode* node) {
static bool isValueTypeString(AstNode const* node) {
return (node->type == NODE_TYPE_VALUE && node->value.type == VALUE_TYPE_STRING);
}

static bool isValueTypeCollection(AstNode const* node) {
return node->type == NODE_TYPE_COLLECTION || isValueTypeString(node);
}

static bool isValueTypeNumber(AstNode* node) {
return (node->type == NODE_TYPE_VALUE && (node->value.type == VALUE_TYPE_INT ||
node->value.type == VALUE_TYPE_DOUBLE));
Expand Down Expand Up @@ -4535,34 +4540,33 @@ static bool applyFulltextOptimization(EnumerateListNode* elnode,
AstNode* attrArg = fargs->getMember(1);
AstNode* queryArg = fargs->getMember(2);
AstNode* limitArg = fargs->numMembers() == 4 ? fargs->getMember(3) : nullptr;
if ((collArg->type != NODE_TYPE_COLLECTION) ||
!isValueTypeString(attrArg) || !isValueTypeString(queryArg) ||
if (!isValueTypeCollection(collArg) || !isValueTypeString(attrArg) ||
!isValueTypeString(queryArg) || // (... || queryArg->type == NODE_TYPE_REFERENCE)
(limitArg != nullptr && !isValueTypeNumber(limitArg))) {
return false;
}

std::string name = collArg->getString();
TRI_vocbase_t* vocbase = plan->getAst()->query()->vocbase();
aql::Collections* colls = plan->getAst()->query()->collections();
aql::Collection const* coll = colls->add(name, AccessMode::Type::READ);
std::vector<basics::AttributeName> field;
TRI_ParseAttributeString(attrArg->getString(), field, /*allowExpansion*/false);
if (field.empty()) {
return false;
}

// check for suitable indexes
std::shared_ptr<LogicalCollection> logical = coll->getCollection();
std::shared_ptr<arangodb::Index> index;
for (auto idx : logical->getIndexes()) {
if (idx->type() == arangodb::Index::IndexType::TRI_IDX_TYPE_FULLTEXT_INDEX) {
TRI_ASSERT(idx->fields().size() == 1);
if (basics::AttributeName::isIdentical(idx->fields()[0], field, false)) {
index = idx;
8000 break;
methods::Collections::lookup(vocbase, name, [&](LogicalCollection* logical) {
for (auto idx : logical->getIndexes()) {
if (idx->type() == arangodb::Index::IndexType::TRI_IDX_TYPE_FULLTEXT_INDEX) {
TRI_ASSERT(idx->fields().size() == 1);
if (basics::AttributeName::isIdentical(idx->fields()[0], field, false)) {
index = idx;
break;
}
}
}
}
});
if (!index) { // no index found
return false;
}
Expand All @@ -4581,6 +4585,19 @@ static bool applyFulltextOptimization(EnumerateListNode* elnode,
condition->andCombine(cond);
condition->normalize(plan);

// we assume by now that collection `name` exists
aql::Collections* colls = plan->getAst()->query()->collections();
aql::Collection* coll = colls->get(name);
if (coll == nullptr) { // TODO: cleanup this mess
coll = colls->add(name, AccessMode::Type::READ);
if (!ServerState::instance()->isCoordinator()) {
TRI_ASSERT(coll != nullptr);
coll->setCollection(vocbase->lookupCollection(name));
// FIXME: does this need to happen in the coordinator?
plan->getAst()->query()->trx()->addCollectionAtRuntime(name);
}
}

auto indexNode = new IndexNode(plan, plan->nextId(), vocbase,
coll, elnode->outVariable(),
std::vector<transaction::Methods::IndexHandle>{
Expand Down
10 changes: 7 additions & 3 deletions arangod/RocksDBEngine/RocksDBFulltextIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,14 @@ IndexIterator* RocksDBFulltextIndex::iteratorForCondition(transaction::Methods*
size_t numMembers = args->numMembers();
TRI_ASSERT(numMembers == 3 || numMembers == 4);

std::string query = args->getMember(2)->getString();

aql::AstNode const* queryNode = args->getMember(2);
if (queryNode->type != aql::NODE_TYPE_VALUE ||
queryNode->value.type != aql::VALUE_TYPE_STRING) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
}

FulltextQuery parsedQuery;
Result res = parseQueryString(query, parsedQuery);
Result res = parseQueryString(queryNode->getString(), parsedQuery);
if (res.fail()) {
THROW_ARANGO_EXCEPTION(res);
}
Expand Down
19 changes: 16 additions & 3 deletions js/server/tests/aql/aql-optimizer-fulltext.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ function optimizerRuleTestSuite() {
assertEqual(findExecutionNodes(plan, "FilterNode").length, 0, query + " Has no FilterNode");
};
var hasNoIndexNode = function (plan,query) {
assertEqual(findExecutionNodes(plan, "IndexNode").length, 0, query + " Has no IndexNode");
assertEqual(findExecutionNodes(plan, "IndexNode").length, 0, query + " Has IndexNode, but should not have one");
};
var hasIndexNode = function (plan,query) {
var rn = findExecutionNodes(plan,"IndexNode");
assertEqual(rn.length, 1, query + " Has IndexNode");
assertEqual(rn.length, 1, query + " Has no IndexNode, but should have one");
assertEqual(rn[0].indexes.length, 1);
var indexType = rn[0].indexes[0].type;
assertTrue(indexType === "fulltext", indexType + " wrong type");
Expand Down Expand Up @@ -151,9 +151,22 @@ function optimizerRuleTestSuite() {
checkQuery("FOR d IN FULLTEXT(@@coll, @attr, 'prefix:quergestreift,|koedern,|prefix:römer,-melken') SORT d.id RETURN d.id", [ 2, 4, 7 ]);
checkQuery("FOR d IN FULLTEXT(@@coll, @attr, 'prefix:quergestreift,|koedern,|prefix:römer,-melken', 2) SORT d.id RETURN d.id", [ 2, 4 ]);
checkQuery("FOR d IN FULLTEXT(@@coll, @attr, 'prefix:quergestreift,|koedern,|prefix:römer,-melken', 2) LIMIT 1 SORT d.id RETURN d.id", [ 2]);
}, // testRuleBasics

testRuleStringCollection : function() {
// collection is not known to query before optimizer rule is applied
let q = "FOR d IN FULLTEXT('" + colName + "', 't1', 'möchten,müller') RETURN d.id";
let plan = AQL_EXPLAIN(q, {});
hasIndexNode(plan,q);
hasNoFilterNode(plan,q);

let r = [ 3, 6 ];
let r1 = AQL_EXECUTE(q, {}, { optimizer: { rules: [ "-all" ] } });
let r2 = AQL_EXECUTE(q, {});
assertEqual(r1.json, r, "Invalid fulltext result");
assertEqual(r2.json, r, "Invalid fulltext result");
} // testRuleBasics


}; // test dictionary (return)
} // optimizerRuleTestSuite

Expand Down
0