zoukankan      html  css  js  c++  java
  • 关于 pgsql 数据库json几个函数用法的效率测试

    关于 pgsql 数据库json几个函数用法的效率测试

    关于pgsql 几个操作符的效率测试比较
    1. json::->> 和 ->>

    测试方法:单次运行100次,运行10个单次取平均时间。
    测试结果:->> 效率高 5% 左右

    功能差异:
    json::->> 在使用前需要对对象转换为jsonb 然后再执行 ->> 操作,所以比->>更耗时 。
    所以如果我们需要对返回的对象进行jsonb操作,用jsonb_* 相关函数时,
    建议用jsonb_* 而不用 jsonb_*_text ,后者会把结果的jsonb对象转换为text,相对于会多两次 jsonb <--> text 转换操作。

    2. any 和 in
    select * from table where column in('1','3','5','7');
    select * from table where column any('{1,3,5,7}'::text[]);

    测试方法:单次运行100次,运行10个单次取平均时间。
    测试结果:in 效率高 5% 左右

    功能差异:
    如果参数是自己传入的,那么建议用in(),如果参数是jsonb对象转换的可使用any。

    3. 查询条件判断是否有值的时候,用 exists 和 判断结果 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) is not null;

    测试方法:单次运行100次,运行10个单次取平均时间。
    测试结果:exists 效率高 8-10% 左右 。
    功能差异:exists只比较不会操作数据,is not null 有操作数据的动作。

    4. false 和 1 = 2
    select * from table where false ;
    建议使用false,。

  • 相关阅读:
    单例模式 (线程安全)
    Hystrix (容错,回退,降级,缓存)
    Feign负载均衡
    Ribbon远程调用
    Eureka服务注册与发现
    适配器模式
    docker学习(二)
    使用Eclipse进行远程调试(转)
    docker学习(一)
    Mysql批量更新的一个坑-&allowMultiQueries=true允许批量更新(转)
  • 原文地址:https://www.cnblogs.com/mywebnumber/p/5826784.html
Copyright © 2011-2022 走看看