-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
RFC: a new typing system for CockroachDB SQL #4121
Conversation
This is by far the most impressive RFC yet. Very well written and complete. Nice job! My preference is definitely for Morty, with suggestions to the user to use explicit casts where there is confusion. The differences between the two – as far as usability goes – are slight, so whichever is simpler to implement and less magical is preferable. Review status: 0 of 1 files reviewed at latest revision, all discussions resolved. Comments from the review on Reviewable.io |
I have a strong preference for Morty as well. Rick is a genius, but too mercurial. Review status: 0 of 1 files reviewed at latest revision, 6 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): docs/RFCS/typing.md, line 816 [r3] (raw file): docs/RFCS/typing.md, line 945 [r3] (raw file): docs/RFCS/typing.md, line 964 [r3] (raw file): docs/RFCS/typing.md, line 987 [r3] (raw file): docs/RFCS/typing.md, line 1038 [r3] (raw file): Comments from the review on Reviewable.io |
Guys, For background reference, here's a document I had written up to compare type conversion in CockroachDB with Postgres: Feel free to comment in the document itself, but preferably here to maintain the continuity of the discussion. It is not a proposal or recommendation per se, but does highlight a lot of the stuff that Postgres does and how it does it. It is a long document (over 30 pages), but the overview section is worth reading. I'd also call attention to what Postgres calls Assignment - INSERT and UPDATE, which have a slightly different semantics than either expression operators or function arguments. Also, Postgres gets a lot of mileage out of treating all string constants as having UNKNOWN type and freely allowing coercion from UNKNOWN to any type, with a bias towards TEXT if not closer type match. This UNKNOWN to any conversion makes positional parameter substitution very easy. And don't forget the non-numeric types, BOOLEAN and TEXT, especially for Assignment. I certainly don't want this input to derail or bog down any of your proposed work, but there might be some reference material that might be useful at least as a check. I'm fairly confident that you guys are probably better off making a solid incremental improvement in the near-term, as with this RFC, independent of what the product should have for a full, final production-ready model of type conversion that handles all of the cases Postgres handles even if not exactly 100% compatible. I was hesitant to jump into the discussion for this RFC out of fear that the perfect might become the enemy of the good, as they say. In any case, it's good to see progress. Don't let my input in any way slow you down on the sprint to Beta. I won't argue too strenuously for full compatibility with Postgres, but I will argue for full migration doc for users coming from Postgres, MySQL,, etc., who may wonder why certain queries are either not allowed or giving unexpected results. Have fun! |
Morty++ Review status: 0 of 1 files reviewed at latest revision, 10 unresolved discussions. docs/RFCS/typing.md, line 546 [r3] (raw file): docs/RFCS/typing.md, line 573 [r3] (raw file): docs/RFCS/typing.md, line 841 [r3] (raw file): docs/RFCS/typing.md, line 939 [r3] (raw file): docs/RFCS/typing.md, line 964 [r3] (raw file): Comments from the review on Reviewable.io |
@JackKupransky Allowing string constants to coerce to integers is way too magical. That Postgres (and other systems) allow this is a mistake in my opinion. I think not being compatible here is a feature. We definitely will need to document what are rules are and the goal is to make the rules saner and less surprising than other systems. Review status: 0 of 1 files reviewed at latest revision, 10 unresolved discussions. Comments from the review on Reviewable.io |
-- ^ fail, but continue | ||
-- $1 + $2, f($1) continue | ||
-- ^ | ||
-- .... , f($1::$1) now retry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume this should be f($1::int)?
Reviewed 1 of 2 files at r3. docs/RFCS/typing.md, line 395 [r3] (raw file): docs/RFCS/typing.md, line 405 [r3] (raw file): docs/RFCS/typing.md, line 518 [r3] (raw file): docs/RFCS/typing.md, line 652 [r3] (raw file): docs/RFCS/typing.md, line 945 [r3] (raw file): docs/RFCS/typing.md, line 987 [r3] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 15 unresolved discussions. docs/RFCS/typing.md, line 395 [r3] (raw file): docs/RFCS/typing.md, line 518 [r3] (raw file): docs/RFCS/typing.md, line 546 [r3] (raw file): docs/RFCS/typing.md, line 573 [r3] (raw file): docs/RFCS/typing.md, line 798 [r3] (raw file): docs/RFCS/typing.md, line 841 [r3] (raw file): docs/RFCS/typing.md, line 964 [r3] (raw file): docs/RFCS/typing.md, line 971 [r3] (raw file): docs/RFCS/typing.md, line 987 [r3] (raw file): docs/RFCS/typing.md, line 1038 [r3] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 15 unresolved discussions. docs/RFCS/typing.md, line 405 [r3] (raw file): docs/RFCS/typing.md, line 573 [r3] (raw file): docs/RFCS/typing.md, line 652 [r3] (raw file): docs/RFCS/typing.md, line 816 [r3] (raw file): docs/RFCS/typing.md, line 841 [r3] (raw file): docs/RFCS/typing.md, line 939 [r3] (raw file): docs/RFCS/typing.md, line 945 [r3] (raw file): docs/RFCS/typing.md, line 971 [r3] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 13 unresolved discussions. docs/RFCS/typing.md, line 395 [r3] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 8 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): docs/RFCS/typing.md, line 964 [r3] (raw file): Comments from the review on Reviewable.io |
Reviewed 1 of 1 files at r5, 1 of 1 files at r8. Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 8 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 9 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): We like the implicit cast from
However in other cases it's less clear it's good: About So we if want (1) to error out, we have to accept that sometimes we don't want the implicit cast; instead, we want a cast that fails when it would lose information (we can call this a
This still leaves open the question about what happens when literals interact with untyped placeholders:
For I and II, we'd like to infer If we don't want to refuse the addition in If we go with implicitly casting from anything to I still don't really have an opinion on what to do here. docs/RFCS/typing.md, line 790 [r8] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 9 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 9 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): docs/RFCS/typing.md, line 790 [r8] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 11 unresolved discussions. docs/RFCS/typing.md, line 798 [r3] (raw file): docs/RFCS/typing.md, line 789 [r9] (raw file): docs/RFCS/typing.md, line 796 [r9] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 11 unresolved discussions. docs/RFCS/typing.md, line 789 [r9] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 11 unresolved discussions. docs/RFCS/typing.md, line 789 [r9] (raw file): Comments from the review on Reviewable.io |
The changes primarily consist of: - Changing type names in examples to be consistent with CockroachDB's implementation (ie. `text` -> `string`, `bytea` -> `bytes`) - Introducing another unresolved question - Adding a few links - Spelling and grammar changes
Review status: 0 of 1 files reviewed at latest revision, 11 unresolved discussions. docs/RFCS/typing.md, line 789 [r9] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 13 unresolved discussions. docs/RFCS/typing.md, line 810 [r10] (raw file): docs/RFCS/typing.md, line 835 [r10] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 13 unresolved discussions. docs/RFCS/typing.md, line 810 [r10] (raw file): docs/RFCS/typing.md, line 835 [r10] (raw file): Comments from the review on Reviewable.io |
Reviewed 1 of 1 files at r11. docs/RFCS/typing.md, line 790 [r8] (raw file): docs/RFCS/typing.md, line 858 [r11] (raw file): docs/RFCS/typing.md, line 913 [r11] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 13 unresolved discussions. docs/RFCS/typing.md, line 858 [r11] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 13 unresolved discussions. docs/RFCS/typing.md, line 858 [r11] (raw file): So, I suggest we remove this rule 13, as the issue of parsing these arguments is not really a typing issue. Formally Morty just assumes that it gets whatever type it asked for. We should make a note below about all this, and we can say that whomever implements the parsing of these arguments (our pgwire implementation) uses the same code/principles as a Comments from the review on Reviewable.io |
Review status: 0 of 1 files reviewed at latest revision, 13 unresolved discussions. docs/RFCS/typing.md, line 790 [r8] (raw file): docs/RFCS/typing.md, line 858 [r11] (raw file): Comments from the review on Reviewable.io |
It would also be good to qualify what user personas the type rules are aimed at. I mean, some people can figure out the rules no matter how complex or poorly specified they are (either by experimentation or reading the code), while others need very clear, specific, and detailed rules, others need clear rules but they must be very simple and intuitive, and the less-sophisticated users really need the type system to do the right thing in an especially intuitive manner and especially cope with users attempting really dumb things. AFAICT, the current discussion is somewhere between Morty and Rick, but with some degree of uncertainty thrown into the mix. |
I recognize the complexity injected by positional parameters and the separation of the prepare/execute process and we certainly need the rules to be complete and clear, but I do think that we should have a subset of the rules for documentation that make the type system clear and simple for non-parameter usage as a first priority, with parameter rules layered on top of that, at least from a user tutorial perspective. |
The typing rules INSERT and UPDATE (VALUES) should also be documented separately from general SELECT expressions. Yes, they do behave like functions, sort of, but with a single signature, so the rules should be stated more simply for this "assignment" scenario, without the extra complexity needed for typing of multi-signature functions. |
@JackKrupansky I agree with your assessment that typing should be documented separately for the people who will use our SQL dialect. However this will be a different work (towards our online docs) than this RFC, which is uniquely geared towards the devs who will implement this. I can promise however that while writing the RFC we were pretty much focused on the ease to explain what is going on to a user as well; despite the wealth of details in the RFC I am rather confident our typing doc will be rather short yet effective. |
LGTM Review status: 0 of 1 files reviewed at latest revision, 13 unresolved discussions, some commit checks failed. Comments from the review on Reviewable.io |
Hi guys unless someone raises their hand during the weekend I propose to merge the RFC on Monday with status "accepted" and a stated preference for Morty. We'll then get down to implement this thing starting next week. |
@JackKrupansky: I should be starting docs on data types, type conversion, prepared statements, and other related topics within the next month. Will be great to hear your thoughts. |
I am still a little confused/concerned about what the final rules really are - are they pure-Morty as in the RFC document itself or what fraction of the discussed changes are being adopted? My comment about doc was less about the doc itself and more about having a solid but readable spec that really does cover all the cases that have been raised. If too many of the rules are blended together (e.g., functions and INSERT/UPDATE), it does make it more difficult to review all of the fine details. For example, for the case of attempting to insert 4.5 into an INT column, did we decide to make that an error or silently truncate? Seems like there were other spec cases up in the air as well. Again, my concern was that the spec be specific about these cases. I know the doc is separate, but we should be able to judge what the doc effort/result might be from the spec itself. It seems to me that at a minimum there should be a final spec that is solely "here's what it will be", as opposed to the original proposal (which was fine for that stage) which mixed two proposals. Again, if the final proposal is 100% pure Morty from the original RFC, fine, but it would help to have some clarity on the status of the changes that were raised during discussion. As it stands, the direction as stated most recently above is "stated preference for Morty", which does make it sound as if all the other changes are definitively rejected. |
The conclusion was Morty (and we should indeed reflect that in the RFC). On Tue, Feb 16, 2016 at 1:08 PM, Jack Krupansky notifications@github.com
|
@JackKrupansky as you have seen the Github PR is a process whereby the document has undergone several iterations and changes. Most of the discussion has been processed and integrated in the RFC already, except for the last point which you outline about which decision is being taken. If you think there are still open questions beyond that after considering the latest version of the RFC in the PR we could take them onboard. See @andreimatei's response for the technical specific bit. |
Okay, thanks. I guess my problem was that I looked briefly at the RFC doc a second time and didn't see any apparent changes right away and assumed that it had not yet been updated. I see now that there was a second commit with changes. Thanks again. In any case, don't let me slow down the Beta implementation. |
RFC: a new typing system for CockroachDB SQL
cc @andreimatei @nvanbenschoten
[ci skip]