小编Ric*_*don的帖子

分析 postgres 中插入的性能

我有一个语句正在将一堆行(这个问题的内容或位置并不重要)插入到 Postgres 数据库中,但它没有我想要的那么快。我可以运行一个解释查询来查看它在做什么,我得到如下结果:

 Insert on dpdb.datapoints  (cost=0.00..6917.76 rows=44184 width=1786) (actual time=15558.623..15558.623 rows=0 loops=1)
   Buffers: shared hit=34670391 read=98370 dirtied=48658 written=39875
   I/O Timings: read=704.525 write=242.915
   ->  Seq Scan on public.fred  (cost=0.00..6917.76 rows=44184 width=1786) (actual time=0.018..197.853 rows=44184 loops=1)
         Output: nextval('datapoints_id_seq'::regclass), fred.company_id, fred.tag, ... lots more columns ...
         Buffers: shared hit=44186 read=6253 dirtied=1
         I/O Timings: read=29.176
 Planning time: 0.110 ms
 Trigger RI_ConstraintTrigger_c_14845718 for constraint datapoints_tag_source_fkey: time=236.677 calls=44184
 Trigger RI_ConstraintTrigger_c_14845723 for constraint datapoints_sheet_type_fkey: time=536.367 calls=44184
 Trigger RI_ConstraintTrigger_c_14845728 for constraint datapoints_subcontext_fkey: time=178.200 calls=44184
 Trigger RI_ConstraintTrigger_c_14845733 for …
Run Code Online (Sandbox Code Playgroud)

postgresql postgresql-performance

6
推荐指数
1
解决办法
3077
查看次数

从 JQ 中的稀疏对象数组生成新数组

我有一个 JSON 文件,我想用 JQ 处理它。它在另一个对象内有一个对象数组,其中有一个我想用来填充新数组的键。

在我的真实用例中,它嵌套在许多其他绒毛中,并且还有更多数组,但将此作为此类事物的一个更简单但具有代表性的示例:

{
  "numbers": [
    {
      "numeral": 1,
      "ordinal": "1st",
      "word": "One"
    },
    {
      "numeral": 2,
      "ordinal": "2nd",
      "word": "Two"
    },
    {
      "numeral": 5,
      "ordinal": "5th",
      "word": "Five"
    },
    {
      "some-other-fluff-i-want-to-ignore": true
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我想使用 JQ 根据元素获取一个新数组,忽略一些元素并处理丢失的元素。例如

[
  "The 1st word is One",
  "The 2nd word is Two",
  "Wot no number 3?",
  "Wot no number 4?",
  "The 5th word is Five"
]
Run Code Online (Sandbox Code Playgroud)

在循环中对现有元素执行此操作非常简单、简洁且优雅:

.numbers | map( . | select( .numeral) | [ "The", .ordinal, "word …
Run Code Online (Sandbox Code Playgroud)

jq

2
推荐指数
1
解决办法
356
查看次数

标签 统计

jq ×1

postgresql ×1

postgresql-performance ×1