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

Change json datatype to jsonb #257

Merged
merged 1 commit into from
Jun 15, 2015

Conversation

clemensg
Copy link
Contributor

Hi,

as the json datatype needs to be parsed over and over again and queue_classic does not make assumptions about the ordering of args' keys, a switch to jsonb seems reasonable to me.

Quote from the PostgreSQL docs: In general, most applications should prefer to store JSON data as jsonb, unless there are quite specialized needs, such as legacy assumptions about ordering of object keys.
http://www.postgresql.org/docs/current/static/datatype-json.html

In case somebody uses 9.3 or earlier, I think it is OK to fall back to text and not check for both jsonb and json. With text we have at least no DB performance penalty, but json is reparsed with every insert. jsonb is parsed only once.

@senny
Copy link
Contributor

senny commented May 18, 2015

Transitioning to jsonb makes sense. However we need to take existing users into account. There should be a migration from json to jsonb.

Not sure wether we should keep falling back to json or go straight to text.

/cc @jipiboily

@clemensg
Copy link
Contributor Author

Wouldn't it be less intrusive to only change the datatype of new migrations instead of migrating every existing args column to jsonb?
There is also less benefit for using json alone, so a fallback to text seems reasonable to me. However, I can add a fallback from jsonb to json to text if you want.

@senny
Copy link
Contributor

senny commented May 18, 2015

@clemensg this change only makes sense if we think jsonb is the thing people should be using (if available). Given that is the case, why should existing applications keep using something we are moving away from?

One should still be able to skip the migration if one pleases but we should make it easy to follow along.

@clemensg
Copy link
Contributor Author

OK, good point. But then we should also migrate old text columns, right?

I mean:

  • text on < 9.2 stays text
  • text on 9.2 and 9.3 becomes json
  • text and json on 9.4 and newer become jsonb

Or:

  • text on < 9.4 stays text
  • text and json on 9.4 and newer become jsonb

@senny
Copy link
Contributor

senny commented May 18, 2015

I don't know the details but it depends how easily we can migrate a column. I'm expecting that PostgreSQL allows us to ALTER TABLE from json to jsonb. With text, this could be more demanding.

Currently I'm thinking about a simple migration which checks for jsonb availability and migrates json to jsonb.

@clemensg can you investigate?

@clemensg
Copy link
Contributor Author

@senny Yes.

@clemensg clemensg force-pushed the change_json_to_jsonb branch from af42013 to 9fb7821 Compare May 18, 2015 13:52
@clemensg
Copy link
Contributor Author

@senny I updated the PR. Btw.: In the update_to_3_2_0.sql file, I also set the args column to text, in case json and jsonb are both not available. It's just a safety measure to fix the schema in case someone reverts to an older PostgreSQL version and still used jsonb. Then we would automatically migrate back to text.

Regarding your concerns about the text data type: PostgreSQL does allow us to change the column data type from text to json / jsonb and vice versa with a simple alter table t alter column c type x using c::x;.

@clemensg clemensg force-pushed the change_json_to_jsonb branch 2 times, most recently from 821db0d to 855619b Compare May 18, 2015 14:15
@senny
Copy link
Contributor

senny commented May 21, 2015

Could you add a corresponding downgrade script? Also, the Rails generator needs to be updated to generate an upgrade migration. See this PR for details https://github.com/QueueClassic/queue_classic/pull/217/files#diff-e455d018c3ab4c611d786db00a9c1458R1

@clemensg clemensg force-pushed the change_json_to_jsonb branch from 855619b to 12c109e Compare May 21, 2015 08:11
@clemensg
Copy link
Contributor Author

Yes, I updated the PR.

@senny
Copy link
Contributor

senny commented May 21, 2015

@clemensg awesome 💛

@jipiboily thoughts?

@clemensg
Copy link
Contributor Author

🐌

@senny
Copy link
Contributor

senny commented May 31, 2015

@clemensg please be respectful with your comments. We are investing our own personal time for Open Source projects. I understand that delays can be frustrating at times but please remember that this is on our list and sometimes we can't drop everything to get it finished. Thank you for your understanding.

@clemensg
Copy link
Contributor Author

Hey, I don't think a (cute) snail emoji is disrespectful.. do you really think so? Just to clarify: I meant "Any blockers? Anything left to do before this can get merged?"

Of course you are investing your own personal time, so am I.

@senny
Copy link
Contributor

senny commented May 31, 2015

@clemensg I'm saying a snail emoji could easily be interpreted as "why is this moving so slow?". Also bumping just leads to a bigger email flood. If you have big repositories like rails/rails on watching, you get more sensible to these kinds of comments as they flood your inbox every day.

@jipiboily
Copy link
Contributor

This sounds good generally speaking. My only worry is that so far we didn't change the column type at all. We're still using text. It might be perfectly fine but it could also break things for some people, like for queue_classic_admin or other things built around it. This is quite unlikely and should be easy to fix though so I'm 👍.

@senny
Copy link
Contributor

senny commented Jun 12, 2015

I was thinking about this some more. Maybe it's better to be conservative and don't upgrade existing databases at all. We can add a section to the README explaining how a user could perform the upgrade. This way new users get jsonb out of the box and existing ones get to choose what way they want to go.

@clemensg what do you think about that approach?

@clemensg
Copy link
Contributor Author

@senny This was my initial approach in this PR. That's why I asked Wouldn't it be less intrusive to only change the datatype of new migrations instead of migrating every existing args column to jsonb? So yes, I think so too, we should go for the more conservative approach.

I'll change / revert the PR 😉

@clemensg clemensg force-pushed the change_json_to_jsonb branch from 12c109e to c988d96 Compare June 12, 2015 15:21
@senny
Copy link
Contributor

senny commented Jun 12, 2015

@clemensg sorry for the roundtrip 😓. Thanks for helping out and adjusting the PR.

@clemensg
Copy link
Contributor Author

No problem. Sometimes it's worth thinking about a problem for a longer time.
By the way, one benchmark test failed, is this a Travis issue?

@senny
Copy link
Contributor

senny commented Jun 12, 2015

mmm, I remember a test that failed for a longer period of time but If I remember correctly I added a skip to that one. So, if I'm not mistaken the build was green. Benchmark could fail for a number of reasons related to the Travis setup though. Let's wait for the run of the update PR and see how that goes.

@clemensg
Copy link
Contributor Author

Looks like another test is asking for skip.

@clemensg clemensg force-pushed the change_json_to_jsonb branch from c988d96 to 520ff8a Compare June 13, 2015 12:47
@clemensg
Copy link
Contributor Author

@senny Interesting, now it's green after I re-triggered the Travis build.

@senny
Copy link
Contributor

senny commented Jun 13, 2015

yea, seems to be flapping. Maybe we get various speeds from Travis when running the build. Due to server load or something like that. I'll try to look at it in the near future.

senny added a commit that referenced this pull request Jun 15, 2015
@senny senny merged commit bba1775 into QueueClassic:master Jun 15, 2015
@senny
Copy link
Contributor

senny commented Jun 15, 2015

Worked fine when testing on my machine. @clemensg thanks for your patience and the roundtrip 💛!

@senny senny mentioned this pull request Jun 15, 2015
3 tasks
@clemensg clemensg deleted the change_json_to_jsonb branch June 15, 2015 10:23
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.

3 participants