Skip to content

Conversation

lcwangchao
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #48608

What is changed and how it works?

  1. Add a new parameter ctx to expression.Eval
  2. If we can get the ctx in the places calling Eval, just use it as the first paramter
  3. We introduce a new method expression.EvalWithInnerCtx to replace the Eval when we cannot not find a valid ctx. expression.EvalWithInnerCtx is deprecated and we should remove it in the later PRs.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 15, 2023
@lcwangchao lcwangchao force-pushed the eval_ctx branch 3 times, most recently from 0dc4c5d to e4ae0f0 Compare November 15, 2023 08:55
Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Merging #48609 (1242d49) into master (b8db9a5) will increase coverage by 1.8808%.
Report is 7 commits behind head on master.
The diff coverage is 92.7710%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #48609        +/-   ##
================================================
+ Coverage   71.0843%   72.9651%   +1.8808%     
================================================
  Files          1365       1389        +24     
  Lines        404348     413600      +9252     
================================================
+ Hits         287428     301784     +14356     
+ Misses        96936      93022      -3914     
+ Partials      19984      18794      -1190     
Flag Coverage Δ
integration 43.8653% <82.5301%> (?)
unit 71.4087% <90.9638%> (+0.3244%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 54.1220% <ø> (+0.1345%) ⬆️
parser ∅ <ø> (∅)
br 49.0479% <0.0000%> (-4.0215%) ⬇️

@lcwangchao
Copy link
Collaborator Author

/retest

@lcwangchao
Copy link
Collaborator Author

/test tiprow_fast_test

Copy link

ti-chi-bot bot commented Nov 15, 2023

@lcwangchao: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test canary-notify-when-compatibility-sections-changed
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-br-integration-test
  • /test pull-common-test
  • /test pull-e2e-test
  • /test pull-integration-common-test
  • /test pull-integration-copr-test
  • /test pull-integration-ddl-test
  • /test pull-integration-jdbc-test
  • /test pull-integration-mysql-test
  • /test pull-integration-nodejs-test
  • /test pull-mysql-client-test
  • /test pull-sqllogic-test
  • /test pull-tiflash-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/canary_ghpr_unit_test
  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test

In response to this:

/test tiprow_fast_test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lcwangchao
Copy link
Collaborator Author

/test tiprow_fast_test

Copy link

ti-chi-bot bot commented Nov 16, 2023

@lcwangchao: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test canary-notify-when-compatibility-sections-changed
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-br-integration-test
  • /test pull-common-test
  • /test pull-e2e-test
  • /test pull-integration-common-test
  • /test pull-integration-copr-test
  • /test pull-integration-ddl-test
  • /test pull-integration-jdbc-test
  • /test pull-integration-mysql-test
  • /test pull-integration-nodejs-test
  • /test pull-mysql-client-test
  • /test pull-sqllogic-test
  • /test pull-tiflash-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/canary_ghpr_unit_test
  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test

In response to this:

/test tiprow_fast_test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lcwangchao lcwangchao requested a review from YangKeao November 16, 2023 01:06
Comment on lines +243 to +251
func (c *Constant) EvalWithInnerCtx(row chunk.Row) (types.Datum, error) {
var ctx sessionctx.Context
if c.DeferredExpr != nil {
if sf, sfOk := c.DeferredExpr.(*ScalarFunction); sfOk {
ctx = sf.GetCtx()
}
}
return c.Eval(ctx, row)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EvalWithInnerCtx will use the the context in the ScalarFunction as the input parameter for Eval. If c.DefferedExpr is nil, the ctx will also be nil, don't worry because ctx will not be used in this case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EvalWithInnerCtx will be removed after we replaces all EvalWithInnerCtx with Eval in the later PRs

intest.AssertNotNil(ctx)
if dt.Kind() != types.KindMysqlDecimal {
val, err := dt.ConvertTo(sf.GetCtx().GetSessionVars().StmtCtx.TypeCtx(), c.RetType)
val, err := dt.ConvertTo(ctx.GetSessionVars().StmtCtx.TypeCtx(), c.RetType)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll use the input ctx instead of the inner one after this PR

if sc := ctx.GetSessionVars().StmtCtx; sc != nil {
err = sc.HandleTruncate(err)
}
if sc := ctx.GetSessionVars().StmtCtx; sc != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll use the ctx from parameter to replace the inner ctx

@lance6716
Copy link
Contributor

/approve

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 17, 2023
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 17, 2023
Copy link

ti-chi-bot bot commented Nov 17, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-17 03:53:35.446300331 +0000 UTC m=+4394013.033410461: ☑️ agreed by zimulala.
  • 2023-11-17 04:52:53.101774218 +0000 UTC m=+4397570.688884360: ☑️ agreed by YangKeao.

Copy link

ti-chi-bot bot commented Nov 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, tiancaiamao, XuHuaiyu, YangKeao, zimulala

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Nov 22, 2023
@lcwangchao
Copy link
Collaborator Author

/retest

1 similar comment
@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Nov 22, 2023

@lcwangchao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tiprow_fast_test 1242d49 link true /test tiprow_fast_test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify method signature of Expression.Eval and add a new parameter ctx.
6 participants