HyperGraphDB查詢中的變數
Introduction
A feature that has been requested on a few occasions is the ability to parametarize HyperGraphDB queries with variables, sort of like the JDBC PreparedStatement allows. That feature has now been implemented with the introduction of named variables. Named variables can be used in place of a regular condition parameters and can contain arbitrary values, whatever is expected by the condition.
The benefits are twofold: increase performance by avoiding to recompile queries where only a few condition parameters change and a cleaner code with less query duplication. The performance increase of precompiled queries is quite tangible and shouldn't be neglected.
Nearly all predefined query conditions support variables, except for the TypePlusCondition which is expanded into a type disjunction during query compilation and therefore cannot be easily precompiled into a parametarized form. It must also be noted that some optimizations made during the compilation phase, in particular related to index usage, can't be performed when a condition is parametarized.
A simple example of this limitation is a parameterized TypeCondition - indices are defined per type, so if the type is not known during query analysis, no index will be used.
The API
The API is designed to fit the existing query condition expressions. A variable is created by calling the hg.var method and the result of that method passed as a condition parameter. For example: q = hg.make(HGHandle.class, graph).compile(
2.hg.and(hg.type(typeHandle),hg.incident(hg.var("targetOfInterest"))));
A feature that has been requested on a few occasions is the ability to parametarize HyperGraphDB queries with variables, sort of like the JDBC PreparedStatement allows. That feature has now been implemented with the introduction of named variables. Named variables can be used in place of a regular condition parameters and can contain arbitrary values, whatever is expected by the condition.
The benefits are twofold: increase performance by avoiding to recompile queries where only a few condition parameters change and a cleaner code with less query duplication. The performance increase of precompiled queries is quite tangible and shouldn't be neglected.
Nearly all predefined query conditions support variables, except for the TypePlusCondition which is expanded into a type disjunction during query compilation and therefore cannot be easily precompiled into a parametarized form. It must also be noted that some optimizations made during the compilation phase, in particular related to index usage, can't be performed when a condition is parametarized.
A simple example of this limitation is a parameterized TypeCondition - indices are defined per type, so if the type is not known during query analysis, no index will be used.
The API
The API is designed to fit the existing query condition expressions. A variable is created by calling the hg.var method and the result of that method passed as a condition parameter. For example:
CODE:
1.HGQuery2.hg.and(hg.type(typeHandle),hg.incident(hg.var("targetOfInterest"))));
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-751709/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 查詢繫結變數的值變數
- 查詢hadoop引數變數Hadoop變數
- SQL Server解惑——查詢條件IN中能否使用變數SQLServer變數
- C++ 變數型別查詢C++變數型別
- Oracle中如何查詢未使用繫結變數的SQL語句?Oracle變數SQL
- 查詢出系統中沒有使用繫結變數的SQL變數SQL
- 10g中查詢初始化引數的值有所改變
- C++ 查詢某個變數的型別C++變數型別
- oracle 查詢未使用繫結變數的sqlOracle變數SQL
- SQLServer中動態查詢sql返回值給變數<整理>SQLServer變數
- 環境變數與檔案查詢變數
- 獲取request中的查詢引數
- 查詢oracle中的隱形引數Oracle
- 查詢沒有使用繫結變數的sql zt變數SQL
- 在 Linux 中查詢 CPU 的核數Linux
- MySQL 查詢所有表中的記錄數MySql
- 查詢表空間中的extent數量
- V$sql查詢未使用繫結變數的語句SQL變數
- 【效能優化】查詢繫結變數的sql語句優化變數SQL
- 【實驗】sql語句在shared_pool中的查詢(程式 繫結變數)SQL變數
- Elasticsearch中的Term查詢和全文查詢Elasticsearch
- 【八】查詢變換
- oracle學習(3) -變數為null時的查詢處理Oracle變數Null
- Laravel同時接收路由引數和查詢字串中的引數Laravel路由字串
- MySQL 查詢字串的個數MySql字串
- 隱含引數的查詢
- oracle 查詢計劃中的基數cardinality概念(二)Oracle
- oracle 查詢計劃中的基數cardinality概念(一)Oracle
- Java中查詢陣列多數元素的4種方法Java陣列
- c++中的變數型別_C ++中的變數C++變數型別
- 讓CSS的查詢匹配原理變高效CSS
- Oracle資料庫的查詢變慢了Oracle資料庫
- Java中查詢給定數字下最大素數的2種方法Java
- K大數查詢
- mysql查詢表列數MySql
- 開啟查詢慢查詢日誌引數
- 物件點查詢和中括號查詢的區別物件
- 轉:C++實現的變種二分查詢法(折半查詢)--二叉查詢樹C++