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

executor: align behavior of foreign keys in "SHOW CREATE TABLE" with MySQL. | tidb-test=pr/2312 #51294

Merged

Conversation

negachov
Copy link
Contributor

@negachov negachov commented Feb 24, 2024

What problem does this PR solve?

Issue Number: ref #51837

Problem Summary:

I'm using parallel_tests with Ruby.
I copy the schema for use, but since foreign keys have schemas, I need to fix the discrepancy in results.

ex)

  • CREATE TABLE
CREATE TABLE `foos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE `bars` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `foo_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_xxx` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
  • SHOW CREATE TABLE(MySQL)
mysql> SHOW CREATE TABLE bars \G
******************** 1. row ********************
       Table: bars
Create Table: CREATE TABLE `bars` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `foo_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_xxx` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
  • SHOW CREATE TABLE(TiDB)
mysql> SHOW CREATE TABLE bars \G
******************** 1. row ********************
       Table: bars
Create Table: CREATE TABLE `bars` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `foo_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_xxx` FOREIGN KEY (`foo_id`) REFERENCES `schema_name`.`foo` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

It's a quick hack, so it's not a good fix.

What changed and how does it work?

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.

When performing a SHOW CREATE TABLE on a table with foreign keys set to tables within the same schema, the target table name of the foreign key will not be qualified with the schema name.

@sre-bot
Copy link
Contributor

sre-bot commented Feb 24, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

ti-chi-bot bot commented Feb 24, 2024

Welcome @negachov!

It looks like this is your first PR to pingcap/tidb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb. 😃

Copy link

ti-chi-bot bot commented Feb 24, 2024

Hi @negachov. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@ti-chi-bot ti-chi-bot bot added needs-ok-to-test size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 24, 2024
Copy link

tiprow bot commented Feb 24, 2024

Hi @negachov. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@negachov
Copy link
Contributor Author

/test all

Copy link

ti-chi-bot bot commented Feb 25, 2024

@negachov: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test all

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.

1 similar comment
Copy link

tiprow bot commented Feb 25, 2024

@negachov: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test all

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.

@hawkingrei hawkingrei changed the title executor: I have aligned behavior of foreign keys in "SHOW CREATE TABLE" with MySQL. executor: align behavior of foreign keys in "SHOW CREATE TABLE" with MySQL. Feb 25, 2024
@hawkingrei
Copy link
Member

/ok-to-test

@lance6716
Copy link
Contributor

You can click the "Details" link of tiprow_fast_test to see the failed tests

https://tiprow.hawkingrei.com/view/gs/pingcapprow/pr-logs/pull/pingcap_tidb/51294/tiprow_fast_test/1761773928004456448

    result.go:49: 
        	Error Trace:	pkg/testkit/result.go:49
        	            				pkg/ddl/tests/fk/foreign_key_test.go:355
        	Error:      	Not equal: 
        	            	expected: "[t2 CREATE TABLE `t2` (\n  `id` int(11) NOT NULL,\n  `a` int(11) DEFAULT NULL,\n  `b` int(11) DEFAULT NULL,\n  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n  KEY `fk` (`a`),\n  CONSTRAINT `fk` FOREIGN KEY (`a`) REFERENCES `test2`.`t2` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin]\n"
        	            	actual  : "[t2 CREATE TABLE `t2` (\n  `id` int(11) NOT NULL,\n  `a` int(11) DEFAULT NULL,\n  `b` int(11) DEFAULT NULL,\n  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n  KEY `fk` (`a`),\n  CONSTRAINT `fk` FOREIGN KEY (`a`) REFERENCES `t2` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin]\n"

@negachov

@negachov
Copy link
Contributor Author

/retest

@negachov
Copy link
Contributor Author

/test unit-test

Copy link

tiprow bot commented Feb 26, 2024

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

  • /test tidb_parser_test
  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test unit-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.

@lance6716
Copy link
Contributor

/retest

Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Merging #51294 (54dfc77) into master (b91a1b3) will decrease coverage by 16.9844%.
Report is 1 commits behind head on master.
The diff coverage is 100.0000%.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #51294         +/-   ##
=================================================
- Coverage   72.4334%   55.4490%   -16.9844%     
=================================================
  Files          1481       1593        +112     
  Lines        365290     628072     +262782     
=================================================
+ Hits         264592     348260      +83668     
- Misses        81150     256036     +174886     
- Partials      19548      23776       +4228     
Flag Coverage Δ
integration 36.6964% <100.0000%> (?)

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

Components Coverage Δ
dumpling 53.9957% <ø> (-2.3014%) ⬇️
parser ∅ <ø> (∅)
br 51.2557% <ø> (+4.8771%) ⬆️

@negachov
Copy link
Contributor Author

@lance6716

https://do.pingcap.net/jenkins/blue/organizations/jenkins/pingcap%2Ftidb%2Fghpr_mysql_test/detail/ghpr_mysql_test/4258/pipeline

The tests for foreign_key and foreign_key1 are failing, so it seems necessary to revise the test cases.
Are these tests within the private repository git@github.com:PingCAP-QE/tidb-test.git?

time="2024-02-27T10:51:15+08:00" level=error msg="run test [foreign_key] err: sql:show create table t2;: failed to run query \n\"show create table t2;\" \n around line 46, \nwe need(347):\nshow create table t2;\nTable\tCreate Table\nt2\tCREATE TABLE `t2` (\n  `a` int(11) NOT NULL,\n  `b` int(11) DEFAULT NULL,\n  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n  KEY `ind` (`b`),\n  CONSTRAINT `fk_1` FOREIGN KEY (`b`) REFERENCES `foreign_key`.`t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLAT\nbut got(347):\nshow create table t2;\nTable\tCreate Table\nt2\tCREATE TABLE `t2` (\n  `a` int(11) NOT NULL,\n  `b` int(11) DEFAULT NULL,\n  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n  KEY `ind` (`b`),\n  CONSTRAINT `fk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n\n"
time="2024-02-27T10:51:16+08:00" level=error msg="run test [foreign_key1] err: sql:SHOW CREATE TABLE t2;: failed to run query \n\"SHOW CREATE TABLE t2;\" \n around line 128, \nwe need(432):\nSHOW CREATE TABLE t2;\nTable\tCreate Table\nt2\tCREATE TABLE `t2` (\n  `a` int(11) NOT NULL,\n  `b` int(11) DEFAULT NULL,\n  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n  KEY `name567890123456789012345678901234567890123456789012345678901234` (`b`),\n  CONSTRAINT `name567890123456789012345678901234567890123456789012345678901234` FOREIGN KEY (`b`) REFERENCES `foreign_key1`.`t1` (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLA\nbut got(432):\nSHOW CREATE TABLE t2;\nTable\tCreate Table\nt2\tCREATE TABLE `t2` (\n  `a` int(11) NOT NULL,\n  `b` int(11) DEFAULT NULL,\n  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n  KEY `name567890123456789012345678901234567890123456789012345678901234` (`b`),\n  CONSTRAINT `name567890123456789012345678901234567890123456789012345678901234` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n\n"

@lance6716
Copy link
Contributor

@negachov We will change the tests in private repo soon. Let's start review

@negachov
Copy link
Contributor Author

@crazycs520 @hawkingrei Cc: @lance6716
I apologize for bothering you while you're busy.

If alternative revisions are preferred, providing guidance on the policy may enable the creation of a diff, so comments would be appreciated.

🙇

@dveeden
Copy link
Contributor

dveeden commented Mar 14, 2024

This looks like a good change to make. Please add a release note to the description and add a link to an issue (create one if needed).

@lance6716
Copy link
Contributor

/assign @ywqzzy

@dveeden
Copy link
Contributor

dveeden commented Mar 15, 2024

@negachov could you:

  • Add a release note to the description
  • Link to an issue (create a new one if there isn't one that is related)

@negachov
Copy link
Contributor Author

If there are no existing issues matching, I will create a new issue.

@dveeden dveeden changed the title executor: align behavior of foreign keys in "SHOW CREATE TABLE" with MySQL. executor: align behavior of foreign keys in "SHOW CREATE TABLE" with MySQL. | tidb-test=pr/2312 Mar 15, 2024
@dveeden
Copy link
Contributor

dveeden commented Mar 15, 2024

/test mysql-test

Copy link

tiprow bot commented Mar 15, 2024

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

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test mysql-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.

Copy link

ti-chi-bot bot commented Mar 18, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-03-15 05:22:46.533142595 +0000 UTC m=+1008593.555388982: ☑️ agreed by lance6716.
  • 2024-03-18 02:15:18.348528612 +0000 UTC m=+1256545.370774985: ☑️ agreed by zimulala.

@lance6716
Copy link
Contributor

/check-issue-triage-complete

@lance6716
Copy link
Contributor

/retest

1 similar comment
@lance6716
Copy link
Contributor

/retest

Copy link

ti-chi-bot bot commented Mar 18, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dveeden, lance6716, 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

@dveeden
Copy link
Contributor

dveeden commented Mar 18, 2024

/retest

@negachov
Copy link
Contributor Author

@lance6716 plz /retest

@ti-chi-bot ti-chi-bot bot merged commit 61ba639 into pingcap:master Mar 21, 2024
23 checks passed
@negachov negachov deleted the show-create-table-fk-without-current-schema branch March 21, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test release-note size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants