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

Fixed bug in certain limit .. offset queries #1015

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

zachmu
Copy link
Member

@zachmu zachmu commented Nov 26, 2024

No description provided.

Copy link
Contributor

Main PR
covering_index_scan_postgres 431.92/s 434.66/s +0.6%
index_join_postgres 160.56/s 159.46/s -0.7%
index_join_scan_postgres 187.20/s 184.63/s -1.4%
index_scan_postgres 15.24/s 15.09/s -1.0%
oltp_point_select 2830.97/s 2767.57/s -2.3%
oltp_read_only 1904.19/s 1883.58/s -1.1%
select_random_points 120.51/s 118.64/s -1.6%
select_random_ranges 92.55/s 92.16/s -0.5%
table_scan_postgres 14.66/s 14.61/s -0.4%
types_table_scan_postgres 6.91/s 6.88/s -0.5%

Copy link
Contributor

Main PR
Total 42090 42090
Successful 14534 14534
Failures 27556 27556
Partial Successes1 4689 4689
Main PR
Successful 34.5308% 34.5308%
Failures 65.4692% 65.4692%

Footnotes

  1. These are tests that we're marking as Successful, however they do not match the expected output in some way. This is due to small differences, such as different wording on the error messages, or the column names being incorrect while the data itself is correct.

Copy link
Collaborator

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

Overall LGTM, just would rather make that WithChildren change

@@ -21,17 +21,21 @@ import (
)

// IDs are basically arbitrary, we just need to ensure that they do not conflict with existing IDs
// Comments are to match the Stringer formatting rules in the original rule definition file, but we can't generate
// human-readable strings for these extended types because they are in another package.
// We could move these into the main GMS package to fix this deficit, if we wanted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that would be a bad idea. I'd argue that we shouldn't need to modify and coordinate changes across packages unless we absolutely need to. Adding a quick analyzer rule in Doltgres shouldn't need a GMS PR to first pass, then merge, then pass Dolt, then merge into Dolt. Especially if GMS becomes broken by someone else pushing to main first.

"github.com/dolthub/doltgresql/server/functions/framework"
)

func ReplaceArithmeticExpressions(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, scope *plan.Scope, selector analyzer.RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Function comment for this

)

func TestLimitOffset(t *testing.T) {
RunScripts(t, []ScriptTest{
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could probably throw these into Smoke since it's just one test in the file.

case *gms_expression.Arithmetic:
switch e.Operator() {
case "+":
expr, err := expression.NewBinaryOperator(framework.Operator_BinaryPlus).WithResolvedChildren(childrenAsAnySlice(e))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems way better to replace this with a call to WithChildren. Currently WithChildren makes an assumption that we've already found the operator function, but we could change it to:

func (b *BinaryOperator) WithChildren(children ...sql.Expression) (sql.Expression, error) {
	if len(children) != 2 {
		return nil, sql.ErrInvalidChildrenNumber.New(b, len(children), 2)
	}
	if b.compiledFunc != nil {
		compiledFunc, err := b.compiledFunc.WithChildren(children...)
		if err != nil {
			return nil, err
		}
		return &BinaryOperator{
			operator:     b.operator,
			compiledFunc: compiledFunc.(framework.Function),
		}, nil
	} else {
		binOp, err := b.WithResolvedChildren([]any{children[0], children[1]})
		if err != nil {
			return nil, err
		}
		return binOp.(sql.Expression), nil
	}
}

Using WithResolvedChildren outside of the GMS-only expectation adds a potential logical dependency that we probably shouldn't make a precedent for. If WithChildren calls it internally, then its usage is more of an implementation detail than a sort of API contract.

We could also make this WithChildren change to unary_operator since they're very similar expressions.

})
}

func childrenAsAnySlice(e sql.Expression) []any {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We won't need this function anymore with the change I mentioned earlier, but I would normally say to leave a function comment. Hard to over comment. Technically possible, but probably nobody but me is gonna over comment on anything lol

Expected: []sql.Row{{2, 0}, {3, 0}},
},
{
Query: "with recursive cte as ((select * from xy order by y asc limit 1 offset 1) union (select * from xy order by y asc limit 1 offset 2)) select * from cte",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not seeing these tests being added to our actual tests anywhere.

In GMS we used this TestSingleScript workflow because we didn't have anything better, but we do have something better in Doltgres with the Focus field on scripts. That way, you could write these in SmokeTests (or wherever) to test your logic, and throw on that Focus: true flag so that only these run. In effect you get the same experience here. But then when you're done, delete the flag, and now they're actual tests in our suite (with the added benefit of CI protection in case you forget to remove the flag). Easy way to expand our test coverage since you don't have to copy the tests out later, we're writing new tests directly into our normal test structures.

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.

2 participants