查詢結(jié)果解讀
查詢結(jié)果的返回形式
目前支持返回格式有四種: string
、 json
、full_json
、flatbuffers
,可以通過(guò)以下幾種途徑配置:
在配置文件設(shè)定:HA3 SQL啟動(dòng)后全局生效,所有query默認(rèn)以設(shè)定的形式返回查詢結(jié)果。
在query的kvpair子句中指定:僅對(duì)當(dāng)前query生效,當(dāng)前query以設(shè)定的形式返回查詢結(jié)果(無(wú)視配置文件中的設(shè)定的形式)。
在query的kvpair中設(shè)定返回值形式
在query的 kvpair
字段中,通過(guò) formatType:json
或者 formatType:string
來(lái)控制查詢結(jié)果的返回形式。更多的 kvpair
用法見kvpair子句。
query=...&&kvpair=...;formatType:{json | string | full_json | flatbuffers};...
string形式結(jié)果解析
string形式的返回結(jié)果自帶排版格式,結(jié)果直觀,可讀性較好。一般用于開發(fā)調(diào)試,方便用戶排查問題。
/ha3_develop/source_code/ha3_manual_example/sql $ ./search.sh -s "select nid, price, brand, size from phone"
+ python2.7 /ha3_develop/install_root/usr/local/lib/python/site-packages/ha_tools/search.py -a http://localhost:39341/ -s 'select nid, price, brand, size from phone'
USE_TIME: 0.025, ROW_COUNT: 10
------------------------------- TABLE INFO ---------------------------
nid | price | brand | size |
1 | 3599 | Huawei | 5.9 |
2 | 4388 | Huawei | 5.5 |
3 | 899 | Xiaomi | 5 |
4 | 2999 | OPPO | 5.5 |
5 | 1299 | Meizu | 5.5 |
6 | 169 | Nokia | 1.4 |
7 | 3599 | Apple | 4.7 |
8 | 5998 | Apple | 5.5 |
9 | 4298 | Apple | 4.7 |
10 | 5688 | Samsung | 5.6 |
------------------------------- TRACE INFO ---------------------------
------------------------------- SEARCH INFO ---------------------------
scanInfos { kernelName: "ScanKernel" nodeName: "0_0" tableName: "phone" hashKey: 243934**** parallelNum: 1 totalOutputCount: 10 totalScanCount: 10 totalUseTime: 86 totalSeekTime: 29 totalEvaluateTime: 13 totalOu\
tputTime: 43 totalComputeTimes: 1 }
JSON形式結(jié)果解析
JSON形式的結(jié)果主要用于服務(wù)調(diào)用,方便程序解析,含有的信息量也更大,下面主要介紹一下各個(gè)返回字段的含義。
/ha3_develop/source_code/ha3_manual_example/sql $ ./search.sh -s "select nid, price, brand, size from phone&&kvpair=formatType:json"
+ python2.7 /ha3_develop/install_root/usr/local/lib/python/site-packages/ha_tools/search.py -a http://localhost:39341/ -s 'select nid, price, brand, size from phone&&kvpair=formatType:json'
{
"error_info": // 輸出error信息
"{\"Error\": ERROR_NONE}",
"format_type":
"json",
"row_count": // 結(jié)果數(shù)
10,
"search_info": // search 相關(guān)的一些信息,包括scan,sort等算子指標(biāo)
"scanInfos { kernelName: \"ScanKernel\" nodeName: \"0_0\" tableName: \"phone\" hashKey: 243934**** parallelNum: 1 totalOutputCount: 10 totalScanCount: 10 totalUseTime: 81 totalSeekTime: 28 totalEvaluateTime: 1\
1 totalOutputTime: 40 totalComputeTimes: 1 }",
"sql_result": // 結(jié)果,返回json string,
"{\"column_name\":[\"nid\",\"price\",\"brand\",\"size\"],\"column_type\":[\"uint64\",\"double\",\"multi_char\",\"double\"],\"data\":[[1,3599,\"Huawei\",5.9],[2,4388,\"Huawei\",5.5],[3,899,\"Xiaomi\",5],[4,2999\
,\"OPPO\",5.5],[5,1299,\"Meizu\",5.5],[6,169,\"Nokia\",1.4],[7,3599,\"Apple\",4.7],[8,5998,\"Apple\",5.5],[9,4298,\"Apple\",4.7],[10,5688,\"Samsung\",5.6]]}",
"total_time": // 耗時(shí),單位s
0.024,
"trace": // trace信息
[
]
}
FULL_JSON形式結(jié)果解析
full_json形式的結(jié)構(gòu)與JSON形式比較相似,唯一的不同在于sql_result字段,JSON形式下是字符串形式,full_json下是直接用JSON表示的形式。
{
"total_time": 34.003,
"covered_percent": 1,
"row_count": 10 ,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [
[
232953260,
"德克士"
],
[
239745260,
"葉氏兄弟"
],
[
240084010,
"菜老包"
],
[
240082260,
"周黑鴨"
],
[
240086260,
"絕味鴨脖"
],
[
240108260,
""
],
[
239256390,
"每一天生活超市"
],
[
240079390,
"美宜佳"
],
[
265230260,
""
],
[
239313011,
"大參林"
]
],
"column_name": [
"store_id",
"brand_name"
],
"column_type": [
"int64",
"multi_char"
]
},
"error_info": {
"ErrorCode": 0,
"Error": "ERROR_NONE",
"Message": ""
}
}
sql_result詳解
{
"column_name":[ // 列名
"nid",
"price",
"brand",
"size"
],
"column_type":[ // 列類型
"uint64",
"double",
"multi_char",
"double"
],
"data":[ // 每行數(shù)據(jù)
[
1,
3599,
"Huawei",
5.9
],
[
2,
4388,
"Huawei",
5.5
],
[
3,
899,
"Xiaomi",
5
],
[
4,
2999,
"OPPO",
5.5
],
[
5,
1299,
"Meizu",
5.5
],
[
6,
169,
"Nokia",
1.4
],
[
7,
3599,
"Apple",
4.7
],
[
8,
5998,
"Apple",
5.5
],
[
9,
4298,
"Apple",
4.7
],
[
10,
5688,
"Samsung",
5.6
]
]
}
searchInfo詳解
在返回結(jié)果中,searchInfo是一個(gè)較為復(fù)雜的字段,可以協(xié)助用戶分析查詢過(guò)程,以排查問題、優(yōu)化性能需在kvpairs中加searchInfo:true。
"search_info": {
"exchangeInfos": [
{
"fillResultUseTime": 1276, // exchange kernel從response結(jié)構(gòu)中獲取結(jié)果耗時(shí)
"hashKey": 413114****,
"kernelName": "ExchangeKernel", // exchange kernel名稱
"nodeName": "1", // exchange kernel所屬節(jié)點(diǎn)名稱
"poolSize": 472, // exchange kernel所屬worker在本次查詢使用的pool大小
"rowCount": 2, // 所有列返回合并后的有效結(jié)果行數(shù)
"searcherUseTime": 7335, // 發(fā)起search請(qǐng)求的等待耗時(shí),單位為us
"totalAccessCount": 4 // 發(fā)起search請(qǐng)求的總列數(shù)
}
],
"rpcInfos": [ // 發(fā)起的rpc請(qǐng)求詳情,該項(xiàng)有多少列返回就有多少元素
{
"beginTime": 1588131436272843, // exchange kernel調(diào)用起始時(shí)間,單位為us
"rpcNodeInfos": [
{
"callUseTime": 5431, // 該rpc node耗時(shí),單位為us
"isReturned": true, // 請(qǐng)求是否有返回
"netLatency": 664, // 網(wǎng)絡(luò)延時(shí),單位為us
"rpcBegin": 1588131436272857, // rpc調(diào)用開始時(shí)間戳,單位為us
"rpcEnd": 1588131436278288, // rpc調(diào)用結(jié)束時(shí)間戳,單位為us
"rpcUseTime": 5175, // rpc調(diào)用持續(xù)時(shí)間,單位為us
"specStr": "11.1.XX.XX:20412" // 調(diào)用server的ip和端口
},
...
],
"totalRpcCount": 4, // 發(fā)出的rpc請(qǐng)求數(shù)
"useTime": 7335 // rpc調(diào)用總時(shí)長(zhǎng)
}
],
"runSqlTimeInfo": {
"sqlPlan2GraphTime": 174, // iquan plan轉(zhuǎn)navi graph的耗時(shí),單位為us
"sqlPlanStartTime": 1588143112640920, // 向iquan發(fā)起plan的請(qǐng)求時(shí)間戳,單位為us
"sqlPlanTime": 10295, // 向iquan發(fā)起請(qǐng)求到獲取plan的總時(shí)長(zhǎng),單位為us
"sqlRunGraphTime": 13407 // 執(zhí)行sql圖的總時(shí)長(zhǎng),單位為us
},
"scanInfos": [
{
"hashKey": 691673167,
"kernelName": "ScanKernel", // kernel名稱
"parallelNum": 2, // scan并行度,全局有多少個(gè)
"parallelIndex": 1, // 該scan kernel屬于并行邏輯下的第幾個(gè),為0默認(rèn)不顯示
"tableName": "store", // table名稱
"totalComputeTimes": 4, // batchScan被調(diào)用的總次數(shù)
"totalEvaluateTime": 9, // 字段求值總耗時(shí),單位為us
"totalInitTime": 3758, // init階段總耗時(shí),單位為us
"totalOutputCount": 2, // 輸出的總行數(shù)
"totalOutputTime": 264, // 構(gòu)建輸出數(shù)據(jù)的總耗時(shí),包括增刪表中數(shù)據(jù),單位為us
"totalScanCount": 2, // scan出的記錄總數(shù)
"totalSeekTime": 2, // seek調(diào)用的總耗時(shí),單位為us
"totalUseTime": 4217 // scan kernel調(diào)用的總時(shí)長(zhǎng),單位為us
}
]
}
Flatbuffers形式
flatbuffers形式是基于flatbuffers實(shí)現(xiàn)的高效序列化結(jié)果,在對(duì)性能有高要求的場(chǎng)景下比較實(shí)用,該形式的返回結(jié)果需要對(duì)應(yīng)的客戶端反序列化解析。
SqlResult.fbs:
include "TwoDimTable.fbs";
namespace isearch.fbs;
table SqlErrorResult {
partitionId: string (id:0);
hostName: string (id:1);
errorCode: uint (id:2);
errorDescription: string (id:3);
}
table SqlResult {
processTime: double (id:0);
rowCount: uint32 (id:1);
errorResult: SqlErrorResult (id:2);
sqlTable: TwoDimTable (id:3);
searchInfo: string (id:4);
coveredPercent: double (id:5);
}
root_type SqlResult;
TwoDimTable.fbs:
include "TsdbColumn.fbs";
namespace isearch.fbs;
// multi value
table MultiInt8 { value: [byte]; }
table MultiInt16 { value: [short]; }
table MultiInt32 { value: [int]; }
table MultiInt64 { value: [long]; }
table MultiUInt8 { value: [ubyte]; }
table MultiUInt16 { value: [ushort]; }
table MultiUInt32 { value: [uint]; }
table MultiUInt64 { value: [ulong]; }
table MultiFloat { value: [float]; }
table MultiDouble { value: [double]; }
table MultiString { value: [string]; }
// column base storage
table Int8Column { value: [byte]; }
table Int16Column { value: [short]; }
table Int32Column { value: [int]; }
table Int64Column { value: [long]; }
table UInt8Column { value: [ubyte]; }
table UInt16Column { value: [ushort]; }
table UInt32Column { value: [uint]; }
table UInt64Column { value: [ulong]; }
table FloatColumn { value: [float]; }
table DoubleColumn { value: [double]; }
table StringColumn { value: [string]; }
table MultiInt8Column { value: [MultiInt8]; }
table MultiUInt8Column { value: [MultiUInt8]; }
table MultiInt16Column { value: [MultiInt16]; }
table MultiUInt16Column { value: [MultiUInt16]; }
table MultiInt32Column { value: [MultiInt32]; }
table MultiUInt32Column { value: [MultiUInt32]; }
table MultiInt64Column { value: [MultiInt64]; }
table MultiUInt64Column { value: [MultiUInt64]; }
table MultiFloatColumn { value: [MultiFloat]; }
table MultiDoubleColumn { value: [MultiDouble]; }
table MultiStringColumn { value: [MultiString]; }
// column type
union ColumnType {
Int8Column,
Int16Column,
Int32Column,
Int64Column,
UInt8Column,
UInt16Column,
UInt32Column,
UInt64Column,
FloatColumn,
DoubleColumn,
StringColumn,
MultiInt8Column,
MultiInt16Column,
MultiInt32Column,
MultiInt64Column,
MultiUInt8Column,
MultiUInt16Column,
MultiUInt32Column,
MultiUInt64Column,
MultiFloatColumn,
MultiDoubleColumn,
MultiStringColumn,
TsdbDpsColumn,
}
table Column {
name: string;
value: ColumnType;
}
table TwoDimTable {
rowCount: uint (id:0);
columns: [Column] (id:1);
}
TsdbColumn.fbs:
namespace isearch.fbs;
struct TsdbDataPoint {
ts: int64 (id:0);
value: double (id:1);
}
table TsdbDataPointSeries { points: [TsdbDataPoint]; }
table TsdbDpsColumn { value : [TsdbDataPointSeries]; }
注意
column_type:multi_前綴為多值類型,結(jié)構(gòu)為list,multi_char 為string類型。