Skip to content

Resolves #17: Update explain() output with user readable keys #208

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
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
7 changes: 4 additions & 3 deletions src/QLPlan.actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ struct IndexScanPlan : ConcretePlan<IndexScanPlan> {
std::vector<std::string> matchedPrefix)
: cx(cx), index(index), begin(begin), end(end), matchedPrefix(matchedPrefix) {}
bson::BSONObj describe() override {
std::string bound_begin = begin.present() ? FDB::printable(begin.get()) : "-inf";
std::string bound_end = end.present() ? FDB::printable(end.get()) : "+inf";
// #17: Added decode_key_part to update explain output with user readable keys
std::string bound_begin = begin.present() ? DataValue::decode_key_part(begin.get()).toString() : "-inf";
std::string bound_end = end.present() ? DataValue::decode_key_part(begin.get()).toString() : "+inf";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be end.get() ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this logic would work if there is only one dimension in the index. As decode_key_part assumes there is only one element in the key. It checks type on the first byte only. If you have a compound index, then the key could be multi element tuple and this would fail.

For example, following explain() would fail.

db.coll.create_index([('a', 1), ('b', 1)])
db.coll.find({'a': 'A', 'b': 64}).explain()

You can use decode_bytes() to create DataKey. Once you have DataKey, you can iterate over different elements in the key to print them by their type.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @apkar . Will look into it.

return BSON(
// clang-format off
"type" << "index scan" <<
Expand Down Expand Up @@ -708,4 +709,4 @@ ACTOR Future<std::pair<int64_t, Reference<ScanReturnedContext>>> executeUntilCom
Reference<Plan> deletePlan(Reference<Plan> subPlan, Reference<UnboundCollectionContext> cx, int64_t limit);
Reference<Plan> flushChanges(Reference<Plan> subPlan);

#endif /* _QL_PLAN_ACTOR_H_ */
#endif /* _QL_PLAN_ACTOR_H_ */