我正在查询我的数据库(Postgres 8.4),如下所示:
SELECT COUNT(*) FROM table WHERE indexed_varchar LIKE 'bar%';
这种复杂性是O(N),因为Postgres必须计算每一行.Postgres 9.2具有仅索引扫描,但不幸的是升级不是一种选择.
但是,获得精确的行数看起来有点过分,因为我只需要知道以下三种情况中的哪一种是真的:
所以我不需要知道查询返回10,421行,只是它返回两个以上.
我知道如何处理前两种情况:
SELECT EXISTS (SELECT COUNT(*) FROM table WHERE indexed_varchar LIKE 'bar%');
如果存在一行或多行并且false不存在,则返回true.
有关如何扩展这一点以便有效地涵盖所有三种情况的任何想法?
几个月前我创建了一个全文搜索词库.我刚刚添加了一些条目,并且(我认为)我这样更新:
ALTER TEXT SEARCH CONFIGURATION english
    ALTER MAPPING FOR asciiword, asciihword, hword_asciipart
    WITH [my_thesaurus], english_stem;
但是,我实际上并不记得我的词库被称为什么.我怎么能搞清楚这一点?
以下面的程序为例:
import asyncio
from concurrent.futures import ProcessPoolExecutor
def process():
    print('processed')
async def main(loop, executor):
    await loop.run_in_executor(executor, process)
    await asyncio.sleep(60.0)
executor = ProcessPoolExecutor()
loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main(loop, executor))
except KeyboardInterrupt:
    pass
finally:
    executor.shutdown()
如果我在程序运行时点击Ctrl+ C,我会在它退出时得到一个真正的消息回溯:
processed
^CProcess Process-3:
Process Process-4:
Process Process-2:
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/pytho
n3.5/multiprocessing/process.py", line 254, in _bootstrap
    self.run()
  File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/pytho
n3.5/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/pytho
n3.5/concurrent/futures/process.py", line 169, in _process_worker
    call_item = call_queue.get(block=True)
  File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/pytho
n3.5/multiprocessing/queues.py", …客户希望每周一自动生成时事通讯,显示即将到来的一周的时间表.这很简单:
if(date('N', $time)==1) { /* Stuff */ }
将它附加到每晚运行的crontab上,我很高兴.
但是,如果在该月的最后一周生成时事通讯,则需要显示下个月的时间表.我如何确定何时需要生成月度计划?