Optimize Postgres query on timestamp range

CLUSTER If you intend to use CLUSTER, the displayed syntax is invalid. create CLUSTER ticket USING ticket_1_idx; Run once: CLUSTER ticket USING ticket_1_idx; This can help a lot with bigger result sets. Not so much for a single or few rows returned. Postgres remembers which index to use for subsequent calls. If your table isn’t … Read more

Higher cardinality column first in an index when involving a range?

First, let’s try FORCE INDEX to pick either ef or fe. The timings are too short to get a clear picture of which is faster, but `EXPLAIN shows a difference: Forcing the range on filetime first. (Note: The order in WHERE has no impact.) mysql> EXPLAIN SELECT COUNT(*), AVG(fsize) FROM files FORCE INDEX(fe) WHERE ext=”gif” … Read more

Optimize groupwise maximum query

Assuming relatively few rows in options for many rows in records. Typically, you would have a look-up table options that is referenced from records.option_id, ideally with a foreign key constraint. If you don’t, I suggest to create one to enforce referential integrity: CREATE TABLE options ( option_id int PRIMARY KEY , option text UNIQUE NOT … Read more

Is there an “Explain Query” for MongoDB Linq?

You can get the Json easily enough if you have a query wrapper; var qLinq = Query<T>.Where(x => x.name==”jim”); Console.WriteLine(qLinq.ToJson()); There’s also an Explain() method on MongoCursor, so you could do this; var exp = Collection.FindAs<T>(qLinq).Explain() Console.WriteLine(exp.ToJson()); So if you want the time taken, “millis” is in there; var msTaken = exp.First(x => x.Name == … Read more