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

ranger: refine explain format, again #7041

Merged
merged 8 commits into from
Jul 17, 2018

Conversation

zz-jason
Copy link
Member

@zz-jason zz-jason commented Jul 12, 2018

What have you changed? (mandatory)

  1. Refine the string format of ranges and constant expressions:

    • use NULL to represent NULL values instead of <nil>
    • wrap string with "
  2. Show whether we use the pseudo statistics for a table or index in the explain result.

  3. Refine the count and range information for inner table of IndexJoin

Before this PR:

TiDB(localhost:4000) > desc select * from t where a = "<nil>";
+-------------------+-------+------+---------------------------------------------------------+
| id                | count | task | operator info                                           |
+-------------------+-------+------+---------------------------------------------------------+
| IndexReader_9     | 10.00 | root | index:IndexScan_8                                       |
| └─IndexScan_8     | 10.00 | cop  | table:t, index:a, range:[<nil>,<nil>], keep order:false |
+-------------------+-------+------+---------------------------------------------------------+
2 rows in set (0.01 sec)

TiDB(localhost:4000) > desc select * from t where a = "NULL";
+-------------------+-------+------+-------------------------------------------------------+
| id                | count | task | operator info                                         |
+-------------------+-------+------+-------------------------------------------------------+
| IndexReader_9     | 10.00 | root | index:IndexScan_8                                     |
| └─IndexScan_8     | 10.00 | cop  | table:t, index:a, range:[NULL,NULL], keep order:false |
+-------------------+-------+------+-------------------------------------------------------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select * from t where a is null;
+-------------------+-------+------+---------------------------------------------------------+
| id                | count | task | operator info                                           |
+-------------------+-------+------+---------------------------------------------------------+
| IndexReader_9     | 10.00 | root | index:IndexScan_8                                       |
| └─IndexScan_8     | 10.00 | cop  | table:t, index:a, range:[<nil>,<nil>], keep order:false |
+-------------------+-------+------+---------------------------------------------------------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select /*+ TIDB_INLJ(t1) */ t2.a from t1 join t2 on t1.a=t2.a;
+--------------------------+----------+------+---------------------------------------------------------------------------+
| id                       | count    | task | operator info                                                             |
+--------------------------+----------+------+---------------------------------------------------------------------------+
| Projection_5             | 12500.00 | root | test.t2.a                                                                 |
| └─IndexJoin_9            | 12500.00 | root | inner join, inner:TableReader_8, outer key:test.t1.a, inner key:test.t2.a |
|   ├─TableReader_11       | 10000.00 | root | data:TableScan_10                                                         |
|   │ └─TableScan_10       | 10000.00 | cop  | table:t1, range:[-inf,+inf], keep order:false                             |
|   └─TableReader_8        | 10000.00 | root | data:TableScan_7                                                          |
|     └─TableScan_7        | 10000.00 | cop  | table:t2, range:[-inf,+inf], keep order:false                             |
+--------------------------+----------+------+---------------------------------------------------------------------------+
6 rows in set (0.00 sec)

After this PR:

TiDB(localhost:4000) > desc select * from t where a = "<nil>";
+-------------------+-------+------+---------------------------------------------------------------------------+
| id                | count | task | operator info                                                             |
+-------------------+-------+------+---------------------------------------------------------------------------+
| IndexReader_9     | 10.00 | root | index:IndexScan_8                                                         |
| └─IndexScan_8     | 10.00 | cop  | table:t, index:a, range:["<nil>","<nil>"], keep order:false, stats:pseudo |
+-------------------+-------+------+---------------------------------------------------------------------------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select * from t where a = "NULL";
+-------------------+-------+------+-------------------------------------------------------------------------+
| id                | count | task | operator info                                                           |
+-------------------+-------+------+-------------------------------------------------------------------------+
| IndexReader_9     | 10.00 | root | index:IndexScan_8                                                       |
| └─IndexScan_8     | 10.00 | cop  | table:t, index:a, range:["NULL","NULL"], keep order:false, stats:pseudo |
+-------------------+-------+------+-------------------------------------------------------------------------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select * from t where a is null;
+-------------------+-------+------+---------------------------------------------------------------------+
| id                | count | task | operator info                                                       |
+-------------------+-------+------+---------------------------------------------------------------------+
| IndexReader_9     | 10.00 | root | index:IndexScan_8                                                   |
| └─IndexScan_8     | 10.00 | cop  | table:t, index:a, range:[NULL,NULL], keep order:false, stats:pseudo |
+-------------------+-------+------+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select /*+ TIDB_INLJ(t1) */ t2.a from t1 join t2 on t1.a=t2.a;
+--------------------------+----------+------+---------------------------------------------------------------------------+
| id                       | count    | task | operator info                                                             |
+--------------------------+----------+------+---------------------------------------------------------------------------+
| Projection_5             | 12500.00 | root | test.t2.a                                                                 |
| └─IndexJoin_9            | 12500.00 | root | inner join, inner:TableReader_8, outer key:test.t1.a, inner key:test.t2.a |
|   ├─TableReader_11       | 10000.00 | root | data:TableScan_10                                                         |
|   │ └─TableScan_10       | 10000.00 | cop  | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo               |
|   └─TableReader_8        | 10.00    | root | data:TableScan_7                                                          |
|     └─TableScan_7        | 10.00    | cop  | table:t2, range: decided by [test.t1.a], keep order:false, stats:pseudo   |
+--------------------------+----------+------+---------------------------------------------------------------------------+
6 rows in set (0.01 sec)

What is the type of the changes? (mandatory)

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested? (mandatory)

  • unit test
  • explain test

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

Does this PR affect tidb-ansible update? (mandatory)

Does this PR need to be added to the release notes? (mandatory)

Refer to a related PR or issue link (optional)

fix #6935
fix #7038

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Jul 12, 2018
@zz-jason
Copy link
Member Author

@winoros PTAL

@shenli
Copy link
Member

shenli commented Jul 12, 2018

Please fix the CI.

@@ -130,6 +130,9 @@ func formatDatum(d types.Datum, isLeftSide bool) string {
if d.GetUint64() == math.MaxUint64 && !isLeftSide {
return "+inf"
}
case types.KindString, types.KindBytes, types.KindMysqlEnum, types.KindMysqlSet,
types.KindMysqlJSON, types.KindBinaryLiteral, types.KindMysqlBit:
return fmt.Sprintf("\"%v\"", d.GetValue())
}
return fmt.Sprintf("%v", d.GetValue())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just wrap it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's leaved for other types, for example decimal/double/datetime/timestamp, I think they'd better not be warped with "

@zz-jason zz-jason changed the title ranger: refine the string format of ranges ranger: refine explain format, again Jul 16, 2018
@zz-jason
Copy link
Member Author

@winoros @lamxTyler PTAL

@zz-jason
Copy link
Member Author

/run-all-tests

},
{
indexPos: 0,
exprStr: `a LIKE "\\\\a%"`,
accessConds: `[like(test.t.a, \\a%, 92)]`,
filterConds: "[]",
resultStr: `[[\a <nil>,\b <nil>)]`,
resultStr: "[[\"\\a\" NULL,\"\\b\" NULL)]",
Copy link
Member

Choose a reason for hiding this comment

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

Why change the quotation?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is due to the modification of formatDatum in util/ranger/types.go

Copy link
Member

Choose a reason for hiding this comment

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

i mean use `, we don't need escape characters

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, the result was directly copied from the test output😂

Copy link
Member Author

Choose a reason for hiding this comment

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

The usage of ` and " is not uniformed now, there are many tests use " actually.

@shenli
Copy link
Member

shenli commented Jul 16, 2018

@lamxTyler PTAL

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 17, 2018
@zz-jason
Copy link
Member Author

@winoros PTAL

if ok && !ds.statisticTable.Pseudo {
rowCount = idxHist.AvgCountPerValue(ds.statisticTable.Count)
} else {
rowCount = ds.statisticTable.PseudoAvgCountPerCount()
Copy link
Member

Choose a reason for hiding this comment

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

The method name should be PseudoAvgCountPerValue?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, already changed.

@zz-jason
Copy link
Member Author

@coocood PTAL

@coocood
Copy link
Member

coocood commented Jul 17, 2018

LGTM

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 17, 2018
@zz-jason zz-jason merged commit 1bf3f3d into pingcap:master Jul 17, 2018
@zz-jason zz-jason deleted the dev/explain-range branch July 17, 2018 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
5 participants