diff --git a/_sql/analytics/generic_inference/jobs_by_ip_address.sql b/_sql/analytics/generic_inference/jobs_by_ip_address.sql index ef0f4995c0..211553d6cf 100644 --- a/_sql/analytics/generic_inference/jobs_by_ip_address.sql +++ b/_sql/analytics/generic_inference/jobs_by_ip_address.sql @@ -6,7 +6,8 @@ -- NB: Nevermind, there's no index on `created_at` -- select count(*) from generic_inference_jobs where created_at > now() - interval 1 minute; --- When the database is under contention, use this form to reduce the number of rows scanned +-- Bin histogram by (creator user, IP address) (including logged out) +-- NB: no index on ip, hence subquery SELECT maybe_creator_user_token, users.username as maybe_creator_username, @@ -32,32 +33,11 @@ group by maybe_creator_user_token, maybe_creator_username, creator_ip_address order by attempts desc; --- When the database is under contention, use this form to reduce the number of rows scanned +-- Bin histogram by creator user (including logged out) +-- NB: no index on ip, hence subquery SELECT - creator_ip_address, - count(*) as attempts -FROM ( - SELECT - maybe_creator_user_token, - creator_ip_address - FROM ( - SELECT maybe_creator_user_token, - creator_ip_address, - created_at - FROM generic_inference_jobs - ORDER BY id DESC - LIMIT 10000 - ) as j - WHERE j.created_at > NOW() - INTERVAL 30 MINUTE -) as jobs -group by creator_ip_address -order by attempts desc; - - --- When the database is under contention, use this form to reduce the number of rows scanned -SELECT - maybe_creator_user_token, users.username as maybe_creator_username, + maybe_creator_user_token, count(*) as attempts FROM ( SELECT @@ -77,3 +57,50 @@ LEFT OUTER JOIN users ON users.token = jobs.maybe_creator_user_token group by maybe_creator_user_token, maybe_creator_username order by attempts desc; + + +-- Bin histogram by IP (logged in and non-logged in +-- NB: no index on ip, hence subquery +SELECT + creator_ip_address, + count(*) as attempts +FROM ( + SELECT + maybe_creator_user_token, + creator_ip_address + FROM ( + SELECT maybe_creator_user_token, + creator_ip_address, + created_at + FROM generic_inference_jobs + ORDER BY id DESC + LIMIT 10000 + ) as j + WHERE j.created_at > NOW() - INTERVAL 30 MINUTE + ) as jobs +group by creator_ip_address +order by attempts desc; + + +-- Bin histogram by non-logged in IP +-- NB: no index on ip, hence subquery +SELECT + creator_ip_address, + count(*) as attempts +FROM ( + SELECT + maybe_creator_user_token, + creator_ip_address + FROM ( + SELECT maybe_creator_user_token, + creator_ip_address, + created_at + FROM generic_inference_jobs + ORDER BY id DESC + LIMIT 10000 + ) as j + WHERE j.created_at > NOW() - INTERVAL 30 MINUTE + AND j.maybe_creator_user_token IS NULL + ) as jobs +group by creator_ip_address +order by attempts desc;