antonlindstrom / pgstore

A Postgres session store backend for gorilla/sessions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

index for performance?

danielbprice opened this issue · comments

Hi, I was wondering if you've had real-world experience with this package under load? In reviewing the code, I see that there are queries against expires_on and key, but neither have an index. Doesn't that make these queries sequential scans, and therefore pretty expensive?

Maybe there is something I'm not understanding?

@danielbprice Thank you for reaching out with yourt concerns! I am afraid to say that I have not used it at any extensive load, therefor not having any issues with the fields not being indexed. This would be very interesting to dig deeper into, not only indexing but also looking at the performance of this package in a broad sense. Do you think there will be any drawbacks of adding an index on those fields?

Again, thank you for looking at this and showing interest for the project!

What I've done for now is to simply have my code create the indices at initialization time if they are not present:

CREATE INDEX IF NOT EXISTS http_sessions_expiry_idx ON http_sessions (expires_on);
CREATE INDEX IF NOT EXISTS http_sessions_key_idx ON http_sessions (key);

I manually verified these against the queries in the library using SET enable_seqscan = OFF; EXPLAIN ANALYZE <query>;

I don't know whether my project will achieve the scale needed to test this, but, if it does, I'll let you know.

@danielbprice Sounds good, thank you for your efforts! Let me know if we should add it to the repository.

Implemented by @kmulvey, than you both Dan and Kevin!