WITH Expression

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: with 表达式

| username: 等一分钟

Is the execution process the same for “with aa as ( xxx ) select * from aa;” and “select * from ( xxx );”?

| username: TiDBer_jYQINSnf | Original post link

Take a look at the execution plan.

| username: 等一分钟 | Original post link

It won’t create a temporary table, for example, create temporary table aa (xxxx).

| username: zhaokede | Original post link

No, it’s for easier reading, I guess.

| username: zhanggame1 | Original post link

The old version has a lot of bugs, use with caution.

| username: 等一分钟 | Original post link

Is there any issue with version 6.1.0?

| username: zhanggame1 | Original post link

Check the release notes after version 6.1.1 for any bug fixes related to CTE.

| username: 等一分钟 | Original post link

Hmm, let me take a look.

| username: ShawnYan | Original post link

Please refer to the official documentation,

If you encounter any bugs, feel free to “complain” on the forum.

| username: shigp_TIDBER | Original post link

It’s best to test it yourself using EXPLAIN.

| username: xfworld | Original post link

The WITH statement is a commonly used syntax in SQL for creating temporary tables or views to be used in subsequent queries. It can simplify the writing of complex queries and improve query performance.

The functionality of CTE has no significant bugs. Versions 6.1.7 or 6.5.x are more suitable as most issues have been fixed.

Refer to these fixes:


| username: 舞动梦灵 | Original post link

The WITH clause is not particularly well supported in TiDB yet. It’s best to use version 7 or above; I haven’t tested this myself. However, based on my previous tests in Oracle, it should be the same.

| username: yiduoyunQ | Original post link

The execution plan is different, use lower versions with caution.

| username: DBAER | Original post link

It might be more reliable to change it to a subquery. Is this about migrating to TiDB?

| username: TiDBer_RjzUpGDL | Original post link

Take a look at the execution plan.