Efficiency test of several function usages of pgsql database json

Source: Internet
Author: User

Efficiency test of several function usages of pgsql database json

Comparison of efficiency tests on several operators of Pgsql
1. Json::->> and->>

Test method: A single run 100 times, run 10 single time to take average time.
Test result:->> efficiency is about 5% high

Functional differences:
Json::->> need to convert objects to jsonb before they are used, and then perform->> operations, which is more time-consuming than->>.
So if we need to do a JSONB operation on the returned object, when we use the jsonb_* correlation function,
It is recommended to use jsonb_* instead of Jsonb_*_text, which converts the Jsonb object of the result to text, which is more than two times jsonb <--> text conversion operation.

2. Any and in
SELECT * FROM table where column in (' 1 ', ' 3 ', ' 5 ', ' 7 ');
SELECT * FROM table where column any (' {1,3,5,7} ':: text[]);

Test method: A single run 100 times, run 10 single time to take average time.
Test result: In high efficiency about 5%

Functional differences:
If the parameter is passed in by itself, then it is recommended to use in () if the argument is a Jsonb object conversion.

3. When the query condition determines whether there is a value, use exists and the result is null
SELECT * FROM table1 a where exists (select 1 from jsonb_array_elements (a.value) as B where b->> ' goods_id ' = '? ');
SELECT * FROM table1 a where (select 1 from jsonb_array_elements (a.value) as B where b->> ' goods_id ' = '? ' Limit 1) I s not null;

Test method: A single run 100 times, run 10 single time to take average time.
Test Result: Exists efficiency is high 8-10% about.
Functional difference: Exists only compares not manipulating data, is not NULL has action to manipulate data.

4. False and 1 = 2
SELECT * from table where false;
It is recommended to use false.

Efficiency test of several function usages of pgsql database json

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.