Skip to content

Commit 9f014d3

Browse files
Replacing boost ptree by rapidjson
Summary: Rapidjson is more efficient in JSON parsing. This code was left out while migrating most of trx_meta_data code. Reviewed By: yashtc Differential Revision: D15967068 fbshipit-source-id: 84fc923
1 parent 88d0a0e commit 9f014d3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

sql/sql_class.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
#include <boost/lexical_cast.hpp>
7070
#include <boost/property_tree/ptree.hpp>
7171
#include <boost/property_tree/json_parser.hpp>
72+
#ifdef HAVE_RAPIDJSON
73+
#include "rapidjson/document.h"
74+
#include "rapidjson/writer.h"
75+
#endif
7276
#include <sstream>
7377

7478
#ifdef TARGET_OS_LINUX
@@ -5788,10 +5792,22 @@ int THD::parse_query_info_attr()
57885792
static std::string get_shard_id(const std::string& db_metadata)
57895793
{
57905794
try {
5795+
#ifdef HAVE_RAPIDJSON
5796+
rapidjson::Document db_metadata_root;
5797+
if (db_metadata_root.Parse(db_metadata.c_str()).HasParseError()) {
5798+
return {};
5799+
}
5800+
const auto iter= db_metadata_root.FindMember("shard");
5801+
std::string shard_id;
5802+
if (iter == db_metadata_root.MemberEnd()) {
5803+
shard_id= iter->value.GetString();
5804+
}
5805+
#else
57915806
boost::property_tree::ptree db_metadata_root;
57925807
std::istringstream is(db_metadata);
57935808
boost::property_tree::read_json(is, db_metadata_root);
57945809
std::string shard_id = db_metadata_root.get<std::string>("shard");
5810+
#endif
57955811
return shard_id;
57965812
}
57975813
catch (std::exception)

sql/sql_yacc.yy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ Note: YYTHD is passed as an argument to yyparse(), and subsequently to yylex().
6666
#include "opt_explain_json.h"
6767
#include "lex_token.h"
6868
#include <sstream>
69+
#ifdef HAVE_RAPIDJSON
70+
#include "rapidjson/document.h"
71+
#include "rapidjson/writer.h"
72+
#else
6973
#include <boost/property_tree/ptree.hpp>
7074
#include <boost/property_tree/json_parser.hpp>
75+
#endif
7176

7277
/* this is to get the bison compilation windows warnings out */
7378
#ifdef _MSC_VER
@@ -6579,6 +6584,14 @@ db_metadata_str:
65796584
/* Verify that a valid JSON is provided */
65806585
if ($3.length > 0)
65816586
{
6587+
#ifdef HAVE_RAPIDJSON
6588+
rapidjson::Document db_metadata_root;
6589+
if (db_metadata_root.Parse($3.str).HasParseError())
6590+
{
6591+
my_error(ER_DB_METADATA_INVALID_JSON, MYF(0), $3.str);
6592+
MYSQL_YYABORT;
6593+
}
6594+
#else
65826595
boost::property_tree::ptree db_metadata_root;
65836596
std::istringstream is($3.str);
65846597
try
@@ -6591,6 +6604,7 @@ db_metadata_str:
65916604
my_error(ER_DB_METADATA_INVALID_JSON, MYF(0), $3.str);
65926605
MYSQL_YYABORT;
65936606
}
6607+
#endif
65946608
}
65956609
Lex->create_info.db_metadata= String($3.str, $3.length,
65966610
&my_charset_bin);

0 commit comments

Comments
 (0)