未加星标

N1QL enhancements in 4.5.1 - Part2

字体大小 | |
[数据库(综合) 所属分类 数据库(综合) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏
Simplify Transitioning from RDBMS

Couchbase Server 4.5.1 release brings multiple functionality, usability and performance improvements in N1QL to address needs ofenterprise applications. These enhancements address many of our customer critical issues, and simplify Transitioning from RDBMS .

Try Couchbase Server 4.5.1. Its ready for production, field tested by partners & customers. See what’s new for full list of enhancements and improvements.

Don't misspart1 of the blog.

New query setting pretty

Pretty!! Pretty!! pretty !! Yes, pretty is super impressive new query setting in N1QL that can enable or disable pretty formatting of query results. You might ask, what’s so great about it?? And, why anybody may want to disable the beautiful pretty formatting of the JSON output.

As the old adage goes, there are no free lunches. Pretty formatting query results comes with its own expense:

First, a quick fact is that the white space (tabs, spaces, newlines) characters in a pretty-formatted JSON document consume almost a third of it’s size. So, simply cutting down on the beautification will save all the raw bytes flowing over the network. Moreover, consider the corresponding saving on the memory and processing resources of N1QL service. Altogether, savings are pretty significant. The pretty output format is good for human readable scenarios, with human manageableresult sizes . However, real world applications and computer programs run queries much more often than humans, and process much bigger query results. For these, what matters is performance and efficiency ; not pretty formatting. In fact, such formatting is an overhead to the JSON parser and application, and is usually discarded. Typically, applications have their own presentation layer to format the data appropriately for respective users. For example, consider a travel reservation website, where you are searching for flights. I am sure, no travel site dumps available flights as bunch of JSON documents.

The new query parameter pretty in 4.5.1 allows to enable/disable formatting a query result. The parameter can be:

set to true or false . Passed to CBQ engine as command line parameters Passed as Query parameter with REST calls.

By default, it is set to true . When set to false , the white space characters are stripped from the query results. The performance benefits are significantly visible when queries produce large results, and it of course depends on the percentage of white-space overhead in your documents. For example, following query which selects all documents from travel-sample, run almost 3x faster when pretty = false . Also, note the size of result set, which is one third of the pretty formatted result.

With pretty = true varakurprasad$ time curl -v http://localhost:8093/query/service -d "pretty=true&statement=SELECT * from \`travel-sample\`" | tail -15 * Hostname was NOT found in DNS cache % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying ::1... * Connected to localhost (::1) port 8093 (#0) * Server auth using Basic with user 'travel-sample' > POST /query/service HTTP/1.1 > Authorization: Basic dHJhdmVsLXNhbXBsZTpoZWxsbw== > User-Agent: curl/7.37.1 > Host: localhost:8093 > Accept: */* > Content-Length: 51 > Content-Type: application/x-www-form-urlencoded > } [data not shown] * upload completely sent off: 51 out of 51 bytes < HTTP/1.1 200 OK < Content-Type: application/json; version=1.6.0 < Date: Sat, 15 Oct 2016 02:04:09 GMT < Transfer-Encoding: chunked < { [data not shown] 100 103M 0 103M 100 51 16.6M 8 0:00:06 0:00:06 --:--:-- 17.2M * Connection #0 to host localhost left intact ], "sourceairport": "TLV", "stops": 0, "type": "route" } } ], "status": "success", "metrics": { "elapsedTime": "6.165034483s", "executionTime": "6.164993497s", "resultCount": 31591, "resultSize": 107830610 } } real 0m6.208s user 0m5.704s sys 0m0.373s With pretty = false

Note that the total resultSize now is only36754457bytes, and the query run in 2.2sec.

varakurprasad$ time curl -v http://localhost:8093/query/service -d "pretty=false&statement=SELECT * from \`travel-sample\`" | tail -5 * Hostname was NOT found in DNS cache % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying ::1... * Connected to localhost (::1) port 8093 (#0) * Server auth using Basic with user 'travel-sample' > POST /query/service HTTP/1.1 > Authorization: Basic dHJhdmVsLXNhbXBsZTpoZWxsbw== > User-Agent: curl/7.37.1 > Host: localhost:8093 > Accept: */* > Content-Length: 52 > Content-Type: application/x-www-form-urlencoded > } [data not shown] * upload completely sent off: 52 out of 52 bytes < HTTP/1.1 200 OK < Content-Type: application/json; version=1.6.0 < Date: Sat, 15 Oct 2016 02:03:29 GMT < Transfer-Encoding: chunked < { [data not shown] 100 35.1M 0 35.1M 100 52 15.9M 23 0:00:02 0:00:02 --:--:-- 15.9M "status": "success", "metrics": {"elapsedTime": "2.148354775s","executionTime": "2.148323137s","resultCount": 31591,"resultSize": 36754457} } real 0m2.223s user 0m1.977s sys 0m0.141s Enhancements to dynamic object construction in N1QL queries

N1QL already supports creation of JSON objects dynamically in queries. This immensely helps in creating specifically constructed result objects in query projection-lists. Couchbase server 4.5.1 extends the power of expressions and enriches the dynamic object creation and object processing in N1QL queries.

In Couchbase Server 4.5.1, N1QL allows both names and values of object fields to be arbitrary expressions. In earlier versions, the names of fields are required to be static strings. If a name does not evaluate to a string, the result of the object construction is NULL. For example: SELECT { UPPER(callsign) || "_key" : callsign || ":" || country || ":" || name } AS myobj FROM `travel-sample` WHERE type = 'airline' limit 1; [ { "myobj": { "MILE-AIR_key": "MILE-AIR:United States:40-Mile Air" } } ] When constructing objects in a N1QL query, the names of fields in name-value pairs is made optional in 4.5.1. For example, the following query implicitly assigns names "type" and "name" for respective values: SELECT {type, name} AS myobj FROM `travel-sample` LIMIT 1; [ { "myobj": { "type": "airport" "name": "airport_123" } } ] New array function ARRAY_INTERSECT() ARRAY_INTERSECT() function takes two or more arrays as parameters and returns the intersection of the input arrays as the result, i.e the array containing values that are present in all the input a

本文数据库(综合)相关术语:系统安全软件

主题: RESTGMLV
分页:12
转载请注明
本文标题:N1QL enhancements in 4.5.1 - Part2
本站链接:http://www.codesec.net/view/483997.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(33)