Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose better types for the ci_sessions table #2256

Merged
merged 3 commits into from
Feb 24, 2021
Merged

Choose better types for the ci_sessions table #2256

merged 3 commits into from
Feb 24, 2021

Conversation

pstef
Copy link
Contributor

@pstef pstef commented Sep 22, 2019

Description
Choose better types for the ci_sessions table:

  • for Postgres, use type BYTEA for binary data. Compared to storing base64-encoded text, this takes less space
  • update the user guide to suggest using type INET for storing IP addresses in Postgres. This type offers input error checking and specialized operators and functions
  • for both MySQL and Postgres, use type timestamp instead of integer. This type is easier to work with when analyzing session activity.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

It's not so difficult to use after all and the type saves space
compared to base64-encoded text.
They are easier to work with than plain integers.
It is the core Postgres type to store IP addresses.
@lonnieezell
Copy link
Member

Unfortunately this solution is not scalable. While I applaud the desire for better performing tables, in this case all of the checks are either Postgre or not Postrge, which is semi-workable now since we only have 3 drivers, but there will be more drivers down the line that get ported over.

@pstef
Copy link
Contributor Author

pstef commented Sep 23, 2019

A single DatabaseHandler is not "scalable", but is currently the accepted solution anyway.

Usually you go from "semi-workable" to "scalable" by refactoring; this could be redone when there are too many drivers to keep the checks. Worrying about it now seems premature.

@lonnieezell
Copy link
Member

Looking back at this one and my rejection looks like it was premature. We already had postgre-specific checks in the code so I'll re-open this now.

My main concern now is about the BC-breaking of changing to timestamp column type. If you can roll that part back to integers than I'm happy to include the other changes now.

@lonnieezell lonnieezell reopened this Feb 29, 2020
@pstef
Copy link
Contributor Author

pstef commented Feb 29, 2020

4b1774a requires one to change the type of column ci_sessions.data whenever its creation predates whatever CI version that would include this change first. I admit I haven't thought about it until now, but it feels like that would have been OK for a 4.0.0 release (or any other release expected to break compatibility).

Currently I can't see 529b5ad breaking anything except applications that already exist and expect integers coming from that particular column. Again, I assumed that this change would be included in a release allowed to make such changes.

dd8a920 has the potential of breaking backwards compatibility if an application has to deal with nonconforming addresses - the new behavior of Postgres rejecting those could be surprising, but perhaps healthier in the long run. An attempt to convert an existing column would result either in a failure or success - I mean, it's not something that would silently cause damage until you decide to look at it.

Please feel free to make adjustments or cherry-pick any of these changes.

@lonnieezell
Copy link
Member

@michalsn @MGatner @paulbalandan Which one of you knows Postgres enough to validate these changes?

@MGatner
Copy link
Member

MGatner commented Feb 12, 2021

Sadly I know no Postgres.

@paulbalandan
Copy link
Member

Postgres is Greek to me. 😂 Maybe @samsonasik ?

'timestamp' => time(),
'data' => $this->platform === 'postgre' ? base64_encode($sessionData) : $sessionData,
'timestamp' => 'now()',
'data' => $this->platform === 'postgre' ? '\x' . bin2hex($sessionData) : $sessionData,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just remember \x prefix is valid for hex in postgres 👍

@MGatner MGatner merged commit ad8aa07 into codeigniter4:develop Feb 24, 2021
@gmeister2 gmeister2 mentioned this pull request Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants