I have a pretty simple table
CREATE TABLE approved_posts (
project_id INTEGER,
feed_id INTEGER,
post_id INTEGER,
approved_time TIMESTAMP NOT NULL,
post_time TIMESTAMP NOT NULL,
PRIMARY KEY (project_id, feed_id, post_id)
)
Run Code Online (Sandbox Code Playgroud)
And I'm trying to optimize this query:
SELECT *
FROM approved_posts
WHERE feed_id IN (?, ?, ?)
AND project_id = ?
ORDER BY approved_time DESC, post_time DESC
LIMIT 1;
Run Code Online (Sandbox Code Playgroud)
The query optimizer is fetching every single approved_post that matches the predicate, sorting all 100k results, and returning the top one …
我的朋友写了一个程序,它比较模具面的随机排列,找到面部分布最均匀的面孔 - 特别是当面部不仅仅是一个序列时.
我将他的程序翻译成了haskell,因为我一直在寻找一个理由来谈论别人的耳朵,看看有多酷.但是,我对haskell并不是很精通(我花了很长时间才写出它并经历了几次巨大的重构)所以我有两个问题.
这是最相关的代码:
-- _CENTERS :: [{ x :: Float, y :: Float, z :: Float}]
-- _VALUES :: [Num]
-- Basically just (repeat $ map rand [0.._SIDES]), but never using a seed twice
randstates from = (take _SIDES (infrand from)) : randstates newseed
where infrand seed = seed : infrand (shuffle seed)
newseed = (infrand from) !! (_SIDES + 1)
-- yates shuffle
yates _ (last:[]) = [last]
yates (rand:pass) (swap:order) = choice:yates pass rorder …Run Code Online (Sandbox Code Playgroud)