小编Pet*_*son的帖子

聚合过滤器表达式不能使用索引吗?

关于过滤器表达式的一个很酷的事情是,您可以在一个查询中执行多个不同的过滤器和聚合."where"部分成为聚合的一部分而不是整个"where"子句.

例如:

SELECT count('id') FILTER (WHERE account_type=1) as regular,
       count('id') FILTER (WHERE account_type=2) as gold,
       count('id') FILTER (WHERE account_type=3) as platinum
FROM clients;
Run Code Online (Sandbox Code Playgroud)

(来自Django文档)

这是PostgreSQL 9.5中的一个错误,或者我做得不对,或者它只是PostgreSQL的一个限制.

考虑这两个查询:

select count(*)
from main_search
where created >= '2017-10-12T00:00:00.081739+00:00'::timestamptz
and created < '2017-10-13T00:00:00.081739+00:00'::timestamptz
and parent_id is null;

select
count('id') filter (
where created >= '2017-10-12T00:00:00.081739+00:00'::timestamptz
and created < '2017-10-13T00:00:00.081739+00:00'::timestamptz
and parent_id is null) as count
from main_search;
Run Code Online (Sandbox Code Playgroud)

(该main_search表有一个组合的btree索引created and parent_id is null)

这是输出:

 count
-------
  9682
(1 row) …
Run Code Online (Sandbox Code Playgroud)

sql postgresql

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

JavaScript中对数组的布尔运算

使用ES6集,我可以这样做:

let ints = new Set([1,2,3])
console.log(ints.has(3))
Run Code Online (Sandbox Code Playgroud)

而且它打印true,因为3 是在集合.

但阵列怎么样?例如

let coordinates = new Set([[1,1], [1,2], [2,0]])
console.log(coordinates.has([1,2]))
Run Code Online (Sandbox Code Playgroud)

这打印false.

正如您在此CodePen演示中所看到的

因此,在没有首先将坐标转换为字符串(例如['1,1', '1,2', '2,0'])的情况下,我如何处理集合中的数组,就像数组是可以清除的一样?

javascript arrays ecmascript-6

3
推荐指数
1
解决办法
50
查看次数

Nginx 中 CSV 文件的内容类型标头重复

我有一些.csv文件是直接从文件系统通过 Nginx 提供的。目前它看起来像这样::

location ~ /static/csv_exports/ {
        add_header Content-Type text/csv;
}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我必须这样做,因为否则它将被用作text/plain. 这是我对它进行卷曲时得到的结果:

$ curl -v http://localhost/static/csv_exports/20110322_172651.csv >> /dev/null
...
 < HTTP/1.1 200 OK
 < Server: nginx/0.7.67
 < Date: Tue, 22 Mar 2011 17:32:07 GMT
 < Content-Type: text/plain
 < Content-Length: 356623
 < Last-Modified: Tue, 22 Mar 2011 17:26:52 GMT
 < Connection: keep-alive
 < Cache-Control: public
 < Content-Type: text/csv
 < Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)

看!它有两个“Content-Type”标头。在浏览器中打开它会自动打开 Open Office,它工作得很好,但我怀疑我做得不对。

nginx

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

在负载均衡的Tornado站点上使用apache基准测试获取失败的请求但没有记录

也许这是一个关于ab的问题,而不是关于龙卷风的问题,但有些事情没有意义.

我像这样运行基准测试:

$ ab -n 100 http://localdomainname/ # 2 tornados being 1 nginx
 ...
Concurrency Level:      1
Time taken for tests:   0.162 seconds
Complete requests:      100
Failed requests:        17
   (Connect: 0, Receive: 0, Length: 17, Exceptions: 0)
Write errors:           0
Run Code Online (Sandbox Code Playgroud)

因此,根据100个请求中的17个失败.

在运行benchamark之前,我重置日志文件并再次查看它们:

$ wc -l /tmp/gkc.access.log 
100 /tmp/gkc.access.log
$ cat /tmp/gkc.access.log | grep ' 200 ' | wc -l
100
Run Code Online (Sandbox Code Playgroud)

所以,据Nginx说,没有请求失败!为什么说ab中的17个失败了?

(顺便说一下,100个中只有17个只是一个例子.它上下起伏但从未出现过0,我期待)

UPDATE

在没有触及Tornado + Nginx设置的情况下使用httperf进行测试后,我得到了0个失败的请求.

benchmarking tornado apachebench

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