本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
openCypher 遵循範例,其中數值資料類型 (例如 int、byte、short、long 等) 的相符項目是在類型提升語意下執行。例如,在查詢輸入值為 10 且輸入值為短類型的所有屬性時,在類型提升語意下,它也會比對值為 10 作為長值的屬性。在某些情況下,類型轉換可能會導致額外負荷,並導致查詢計劃效率低於未執行類型轉換時的查詢計劃。特別是在資料中一致地使用資料類型的情況下 (例如,如果所有人的年齡都存放為長值),執行類型提升會導致額外負荷,而不會影響查詢結果。
若要在已知資料庫中存放的數值屬性資料值為一致類型時允許最佳化,可以使用稱為 assumeConsistentDataTypes
(值為 true/false
,預設值為 false
) 的查詢提示。當此查詢提示提供 值時true
,引擎會假設唯一的屬性值一律為長或雙,並會略過類型提升語意。查詢中指定的數值會被視為長值 (適用於非浮點值) 和雙值 (適用於浮點值)。
如果資料持續使用單一資料類型 (例如,所有存留期都儲存為 long
),則使用assumeConsistentDataTypes
提示可以透過略過不同數值類型的不必要的等式檢查來最佳化查詢。不過,如果資料具有相同屬性的不一致資料類型,則使用提示可能會導致某些結果遺漏,因為查詢只會符合提示假設的單一資料類型。
# Database loaded with following openCypher CSV's # File 1 :ID,age:Int n1,20 n2,25 # File 2 :ID,age:Long n3,25 # Example (no hint) MATCH (n:Person) WHERE n.age >= 25 RETURN n # Result n2 n3 Returns all person whose age is >= 25 and the values >= 25 can be with any of these datatypes i.e. byte, short, int, long, double or float ----------------------------------------------------------------------------------- # Example (with hint present) USING QUERY:assumeConsistentDataTypes "true" MATCH (n:Person) WHERE n.age >= 25 RETURN n # Result n3 Returns only "n3" and not "n2". The reason is that even though the numerical value matches (25), the datatype is "int" and is considered a non-match.
您也可以透過解釋來驗證差異。
沒有說明:
# Query MATCH (n) WHERE n.age = 20 RETURN n # Explain Snippet ╔═════╤══════════╤══════════╤══════════════════════════════╤═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╤════════╤════════════╤══════════════╤═════════╤══════════════╗ ║ ID │ Out #1 │ Out #2 │ Name │ Arguments │ Mode │ Units In │ Units Out │ Ratio │ Time (ms) ║ ╠═════╪══════════╪══════════╪══════════════════════════════╪═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╪════════╪════════════╪══════════════╪═════════╪══════════════╣ ║ 0 │ 1 │ - │ DFEPipelineScan (DFX) │ pattern=Node(?n) with property 'age' as ?n_age2 and label 'ALL' │ - │ 0 │ 1 │ 0.00 │ 0.10 ║ ║ │ │ │ │ inlineFilters=[(?n_age2 IN ["20"^^xsd:byte, "20"^^xsd:int, "20"^^xsd:long, "20"^^xsd:short, "20.0"^^xsd:double, "20.0"^^xsd:float])] │ │ │ │ │ ║ ║ │ │ │ │ patternEstimate=1 │ │ │ │ │ ║ ╟─────┼──────────┼──────────┼──────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┼────────────┼──────────────┼─────────┼──────────────╢ # The inFilters field contains all numeric types
使用 提示:
# Query MATCH (n) WHERE n.age = 20 RETURN n # Explain Snippet ╔═════╤══════════╤══════════╤══════════════════════════════╤═════════════════════════════════════════════════════════════════════════════════╤════════╤════════════╤══════════════╤═════════╤══════════════╗ ║ ID │ Out #1 │ Out #2 │ Name │ Arguments │ Mode │ Units In │ Units Out │ Ratio │ Time (ms) ║ ╠═════╪══════════╪══════════╪══════════════════════════════╪═════════════════════════════════════════════════════════════════════════════════╪════════╪════════════╪══════════════╪═════════╪══════════════╣ ║ 0 │ 1 │ - │ DFEPipelineScan (DFX) │ pattern=Node(?n) with property 'age' as ?n_age2 and label 'ALL' │ - │ 0 │ 1 │ 0.00 │ 0.07 ║ ║ │ │ │ │ inlineFilters=[(?n_age2 IN ["20"^^xsd:long])] │ │ │ │ │ ║ ║ │ │ │ │ patternEstimate=1 │ │ │ │ │ ║ ╟─────┼──────────┼──────────┼──────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┼────────┼────────────┼──────────────┼─────────┼──────────────╢ # The inFilters field only contains long datatype