From b4d91518bb28876dd323f5790aa48e6a9c76862c Mon Sep 17 00:00:00 2001 From: Haibin Xie Date: Tue, 30 Jul 2019 17:37:22 +0800 Subject: [PATCH] stats: fix estimation for time equal conditions (#11511) (#11526) All tests passed, auto merged by Bot --- .../r/explain_complex_stats.result | 12 ++--- cmd/explaintest/r/explain_easy.result | 14 +++++ cmd/explaintest/r/tpch.result | 54 +++++++++---------- cmd/explaintest/t/explain_easy.test | 7 +++ statistics/cmsketch.go | 4 +- statistics/update_test.go | 4 +- 6 files changed, 58 insertions(+), 37 deletions(-) diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index eb965953b17f0..5449129ff6744 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -115,13 +115,13 @@ PRIMARY KEY (aid,dic) load stats 's/explain_complex_stats_rr.json'; explain SELECT ds, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(dic) as install_device FROM dt use index (cm) WHERE (ds >= '2016-09-01') AND (ds <= '2016-11-03') AND (cm IN ('1062', '1086', '1423', '1424', '1425', '1426', '1427', '1428', '1429', '1430', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442', '1443', '1444', '1445', '1446', '1447', '1448', '1449', '1450', '1451', '1452', '1488', '1489', '1490', '1491', '1492', '1493', '1494', '1495', '1496', '1497', '1550', '1551', '1552', '1553', '1554', '1555', '1556', '1557', '1558', '1559', '1597', '1598', '1599', '1600', '1601', '1602', '1603', '1604', '1605', '1606', '1607', '1608', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1623', '1624', '1625', '1626', '1627', '1628', '1629', '1630', '1631', '1632', '1709', '1719', '1720', '1843', '2813', '2814', '2815', '2816', '2817', '2818', '2819', '2820', '2821', '2822', '2823', '2824', '2825', '2826', '2827', '2828', '2829', '2830', '2831', '2832', '2833', '2834', '2835', '2836', '2837', '2838', '2839', '2840', '2841', '2842', '2843', '2844', '2845', '2846', '2847', '2848', '2849', '2850', '2851', '2852', '2853', '2854', '2855', '2856', '2857', '2858', '2859', '2860', '2861', '2862', '2863', '2864', '2865', '2866', '2867', '2868', '2869', '2870', '2871', '2872', '3139', '3140', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3157', '3158', '3386', '3387', '3388', '3389', '3390', '3391', '3392', '3393', '3394', '3395', '3664', '3665', '3666', '3667', '3668', '3670', '3671', '3672', '3673', '3674', '3676', '3677', '3678', '3679', '3680', '3681', '3682', '3683', '3684', '3685', '3686', '3687', '3688', '3689', '3690', '3691', '3692', '3693', '3694', '3695', '3696', '3697', '3698', '3699', '3700', '3701', '3702', '3703', '3704', '3705', '3706', '3707', '3708', '3709', '3710', '3711', '3712', '3713', '3714', '3715', '3960', '3961', '3962', '3963', '3964', '3965', '3966', '3967', '3968', '3978', '3979', '3980', '3981', '3982', '3983', '3984', '3985', '3986', '3987', '4208', '4209', '4210', '4211', '4212', '4304', '4305', '4306', '4307', '4308', '4866', '4867', '4868', '4869', '4870', '4871', '4872', '4873', '4874', '4875')) GROUP BY ds, p1, p2, p3, p4, p5, p6_md5, p7_md5 ORDER BY ds2 DESC; id count task operator info -Projection_7 21.40 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, install_device -└─Sort_8 21.40 root test.dt.ds2:desc - └─HashAgg_17 21.40 root group by:col_10, col_11, col_12, col_13, col_14, col_15, col_16, col_17, funcs:count(col_0), firstrow(col_1), firstrow(col_2), firstrow(col_3), firstrow(col_4), firstrow(col_5), firstrow(col_6), firstrow(col_7), firstrow(col_8), firstrow(col_9) - └─IndexLookUp_18 21.40 root +Projection_7 21.53 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, install_device +└─Sort_8 21.53 root test.dt.ds2:desc + └─HashAgg_17 21.53 root group by:col_10, col_11, col_12, col_13, col_14, col_15, col_16, col_17, funcs:count(col_0), firstrow(col_1), firstrow(col_2), firstrow(col_3), firstrow(col_4), firstrow(col_5), firstrow(col_6), firstrow(col_7), firstrow(col_8), firstrow(col_9) + └─IndexLookUp_18 21.53 root ├─IndexScan_14 128.32 cop table:dt, index:cm, range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false - └─HashAgg_11 21.40 cop group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic), firstrow(test.dt.ds), firstrow(test.dt.ds2), firstrow(test.dt.p1), firstrow(test.dt.p2), firstrow(test.dt.p3), firstrow(test.dt.p4), firstrow(test.dt.p5), firstrow(test.dt.p6_md5), firstrow(test.dt.p7_md5) - └─Selection_16 21.43 cop ge(test.dt.ds, 2016-09-01 00:00:00.000000), le(test.dt.ds, 2016-11-03 00:00:00.000000) + └─HashAgg_11 21.53 cop group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic), firstrow(test.dt.ds), firstrow(test.dt.ds2), firstrow(test.dt.p1), firstrow(test.dt.p2), firstrow(test.dt.p3), firstrow(test.dt.p4), firstrow(test.dt.p5), firstrow(test.dt.p6_md5), firstrow(test.dt.p7_md5) + └─Selection_16 21.56 cop ge(test.dt.ds, 2016-09-01 00:00:00.000000), le(test.dt.ds, 2016-11-03 00:00:00.000000) └─TableScan_15 128.32 cop table:dt, keep order:false explain select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.bm = 0 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; id count task operator info diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 0c989d357bba6..7f3e55d88e919 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -516,3 +516,17 @@ Projection_8 8320.83 root test.t.a, test.t1.a └─TableScan_15 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo rollback; drop table if exists t; +create table t(a time, b date); +insert into t values (1, "1000-01-01"), (2, "1000-01-02"), (3, "1000-01-03"); +analyze table t; +explain select * from t where a = 1; +id count task operator info +TableReader_7 1.00 root data:Selection_6 +└─Selection_6 1.00 cop eq(test.t.a, 00:00:01.000000) + └─TableScan_5 3.00 cop table:t, range:[-inf,+inf], keep order:false +explain select * from t where b = "1000-01-01"; +id count task operator info +TableReader_7 1.00 root data:Selection_6 +└─Selection_6 1.00 cop eq(test.t.b, 1000-01-01 00:00:00.000000) + └─TableScan_5 3.00 cop table:t, range:[-inf,+inf], keep order:false +drop table t; diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index 560b2e3b1b6f7..b18857c42c6de 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -124,7 +124,7 @@ Sort_6 2.94 root tpch.lineitem.l_returnflag:asc, tpch.lineitem.l_linestatus:asc └─HashAgg_14 2.94 root group by:col_13, col_14, funcs:sum(col_0), sum(col_1), sum(col_2), sum(col_3), avg(col_4, col_5), avg(col_6, col_7), avg(col_8, col_9), count(col_10), firstrow(col_11), firstrow(col_12) └─TableReader_15 2.94 root data:HashAgg_9 └─HashAgg_9 2.94 cop group by:tpch.lineitem.l_linestatus, tpch.lineitem.l_returnflag, funcs:sum(tpch.lineitem.l_quantity), sum(tpch.lineitem.l_extendedprice), sum(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))), sum(mul(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), plus(1, tpch.lineitem.l_tax))), avg(tpch.lineitem.l_quantity), avg(tpch.lineitem.l_extendedprice), avg(tpch.lineitem.l_discount), count(1), firstrow(tpch.lineitem.l_returnflag), firstrow(tpch.lineitem.l_linestatus) - └─Selection_13 293683189.00 cop le(tpch.lineitem.l_shipdate, 1998-08-15) + └─Selection_13 293795345.00 cop le(tpch.lineitem.l_shipdate, 1998-08-15) └─TableScan_12 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false /* Q2 Minimum Cost Supplier Query @@ -251,7 +251,7 @@ limit 10; id count task operator info Projection_14 10.00 root tpch.lineitem.l_orderkey, 7_col_0, tpch.orders.o_orderdate, tpch.orders.o_shippriority └─TopN_17 10.00 root 7_col_0:desc, tpch.orders.o_orderdate:asc, offset:0, count:10 - └─HashAgg_20 40227041.09 root group by:col_4, col_5, col_6, funcs:sum(col_0), firstrow(col_1), firstrow(col_2), firstrow(col_3) + └─HashAgg_20 40252367.98 root group by:col_4, col_5, col_6, funcs:sum(col_0), firstrow(col_1), firstrow(col_2), firstrow(col_3) └─Projection_56 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority └─IndexJoin_26 91515927.49 root inner join, inner:IndexLookUp_25, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey ├─HashRightJoin_46 22592975.51 root inner join, inner:TableReader_52, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] @@ -444,17 +444,17 @@ supp_nation, cust_nation, l_year; id count task operator info -Sort_22 768.91 root tpch.shipping.supp_nation:asc, tpch.shipping.cust_nation:asc, shipping.l_year:asc -└─Projection_24 768.91 root tpch.shipping.supp_nation, tpch.shipping.cust_nation, shipping.l_year, 14_col_0 - └─HashAgg_27 768.91 root group by:shipping.l_year, tpch.shipping.cust_nation, tpch.shipping.supp_nation, funcs:sum(shipping.volume), firstrow(tpch.shipping.supp_nation), firstrow(tpch.shipping.cust_nation), firstrow(shipping.l_year) - └─Projection_28 584459.32 root tpch.n1.n_name, tpch.n2.n_name, extract("YEAR", tpch.lineitem.l_shipdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)) - └─HashLeftJoin_33 584459.32 root inner join, inner:TableReader_85, equal:[eq(tpch.customer.c_nationkey, tpch.n2.n_nationkey)], other cond:or(and(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n2.n_name, "INDIA")), and(eq(tpch.n1.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN"))) - ├─IndexJoin_37 7305741.46 root inner join, inner:TableReader_36, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey - │ ├─IndexJoin_43 7305741.46 root inner join, inner:TableReader_42, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey - │ │ ├─HashLeftJoin_64 7305741.46 root inner join, inner:TableReader_78, equal:[eq(tpch.supplier.s_nationkey, tpch.n1.n_nationkey)] - │ │ │ ├─HashLeftJoin_69 91321768.29 root inner join, inner:TableReader_75, equal:[eq(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey)] - │ │ │ │ ├─TableReader_73 91321768.29 root data:Selection_72 - │ │ │ │ │ └─Selection_72 91321768.29 cop ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) +Sort_22 769.96 root tpch.shipping.supp_nation:asc, tpch.shipping.cust_nation:asc, shipping.l_year:asc +└─Projection_24 769.96 root tpch.shipping.supp_nation, tpch.shipping.cust_nation, shipping.l_year, 14_col_0 + └─HashAgg_27 769.96 root group by:shipping.l_year, tpch.shipping.cust_nation, tpch.shipping.supp_nation, funcs:sum(shipping.volume), firstrow(tpch.shipping.supp_nation), firstrow(tpch.shipping.cust_nation), firstrow(shipping.l_year) + └─Projection_28 585255.87 root tpch.n1.n_name, tpch.n2.n_name, extract("YEAR", tpch.lineitem.l_shipdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)) + └─HashLeftJoin_33 585255.87 root inner join, inner:TableReader_85, equal:[eq(tpch.customer.c_nationkey, tpch.n2.n_nationkey)], other cond:or(and(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n2.n_name, "INDIA")), and(eq(tpch.n1.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN"))) + ├─IndexJoin_37 7315698.42 root inner join, inner:TableReader_36, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey + │ ├─IndexJoin_43 7315698.42 root inner join, inner:TableReader_42, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey + │ │ ├─HashLeftJoin_64 7315698.42 root inner join, inner:TableReader_78, equal:[eq(tpch.supplier.s_nationkey, tpch.n1.n_nationkey)] + │ │ │ ├─HashLeftJoin_69 91446230.29 root inner join, inner:TableReader_75, equal:[eq(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey)] + │ │ │ │ ├─TableReader_73 91446230.29 root data:Selection_72 + │ │ │ │ │ └─Selection_72 91446230.29 cop ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) │ │ │ │ │ └─TableScan_71 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false │ │ │ │ └─TableReader_75 500000.00 root data:TableScan_74 │ │ │ │ └─TableScan_74 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false @@ -516,20 +516,20 @@ o_year order by o_year; id count task operator info -Sort_28 718.01 root all_nations.o_year:asc -└─Projection_30 718.01 root all_nations.o_year, div(18_col_0, 18_col_1) - └─HashAgg_33 718.01 root group by:col_3, funcs:sum(col_0), sum(col_1), firstrow(col_2) - └─Projection_105 112469.62 root case(eq(tpch.all_nations.nation, "INDIA"), all_nations.volume, 0), all_nations.volume, all_nations.o_year, all_nations.o_year - └─Projection_34 112469.62 root extract("YEAR", tpch.orders.o_orderdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.n2.n_name - └─HashLeftJoin_39 112469.62 root inner join, inner:TableReader_103, equal:[eq(tpch.n1.n_regionkey, tpch.region.r_regionkey)] - ├─HashLeftJoin_44 562348.12 root inner join, inner:TableReader_100, equal:[eq(tpch.customer.c_nationkey, tpch.n1.n_nationkey)] - │ ├─IndexJoin_48 562348.12 root inner join, inner:TableReader_47, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey - │ │ ├─HashLeftJoin_54 562348.12 root inner join, inner:TableReader_96, equal:[eq(tpch.supplier.s_nationkey, tpch.n2.n_nationkey)] - │ │ │ ├─IndexJoin_58 562348.12 root inner join, inner:TableReader_57, outer key:tpch.lineitem.l_suppkey, inner key:tpch.supplier.s_suppkey - │ │ │ │ ├─HashLeftJoin_65 562348.12 root inner join, inner:TableReader_92, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] - │ │ │ │ │ ├─IndexJoin_71 90661378.61 root inner join, inner:IndexLookUp_70, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey - │ │ │ │ │ │ ├─TableReader_87 22382008.93 root data:Selection_86 - │ │ │ │ │ │ │ └─Selection_86 22382008.93 cop ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), le(tpch.orders.o_orderdate, 1996-12-31 00:00:00.000000) +Sort_28 719.02 root all_nations.o_year:asc +└─Projection_30 719.02 root all_nations.o_year, div(18_col_0, 18_col_1) + └─HashAgg_33 719.02 root group by:col_3, funcs:sum(col_0), sum(col_1), firstrow(col_2) + └─Projection_105 112627.20 root case(eq(tpch.all_nations.nation, "INDIA"), all_nations.volume, 0), all_nations.volume, all_nations.o_year, all_nations.o_year + └─Projection_34 112627.20 root extract("YEAR", tpch.orders.o_orderdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.n2.n_name + └─HashLeftJoin_39 112627.20 root inner join, inner:TableReader_103, equal:[eq(tpch.n1.n_regionkey, tpch.region.r_regionkey)] + ├─HashLeftJoin_44 563136.02 root inner join, inner:TableReader_100, equal:[eq(tpch.customer.c_nationkey, tpch.n1.n_nationkey)] + │ ├─IndexJoin_48 563136.02 root inner join, inner:TableReader_47, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey + │ │ ├─HashLeftJoin_54 563136.02 root inner join, inner:TableReader_96, equal:[eq(tpch.supplier.s_nationkey, tpch.n2.n_nationkey)] + │ │ │ ├─IndexJoin_58 563136.02 root inner join, inner:TableReader_57, outer key:tpch.lineitem.l_suppkey, inner key:tpch.supplier.s_suppkey + │ │ │ │ ├─HashLeftJoin_65 563136.02 root inner join, inner:TableReader_92, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] + │ │ │ │ │ ├─IndexJoin_71 90788402.51 root inner join, inner:IndexLookUp_70, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey + │ │ │ │ │ │ ├─TableReader_87 22413367.93 root data:Selection_86 + │ │ │ │ │ │ │ └─Selection_86 22413367.93 cop ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), le(tpch.orders.o_orderdate, 1996-12-31 00:00:00.000000) │ │ │ │ │ │ │ └─TableScan_85 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false │ │ │ │ │ │ └─IndexLookUp_70 1.00 root │ │ │ │ │ │ ├─IndexScan_68 1.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false diff --git a/cmd/explaintest/t/explain_easy.test b/cmd/explaintest/t/explain_easy.test index 25c2e94b79f81..3e9b7a1ca0aec 100644 --- a/cmd/explaintest/t/explain_easy.test +++ b/cmd/explaintest/t/explain_easy.test @@ -111,3 +111,10 @@ insert into t values (1); explain select * from t left outer join t t1 on t.a = t1.a where t.a not between 1 and 2; rollback; drop table if exists t; + +create table t(a time, b date); +insert into t values (1, "1000-01-01"), (2, "1000-01-02"), (3, "1000-01-03"); +analyze table t; +explain select * from t where a = 1; +explain select * from t where b = "1000-01-01"; +drop table t; diff --git a/statistics/cmsketch.go b/statistics/cmsketch.go index 18915ba5df25b..a5d3188934a94 100644 --- a/statistics/cmsketch.go +++ b/statistics/cmsketch.go @@ -20,8 +20,8 @@ import ( "github.com/cznic/sortutil" "github.com/pingcap/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" + "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" - "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" "github.com/spaolacci/murmur3" ) @@ -67,7 +67,7 @@ func (c *CMSketch) setValue(h1, h2 uint64, count uint32) { } func (c *CMSketch) queryValue(sc *stmtctx.StatementContext, val types.Datum) (uint32, error) { - bytes, err := codec.EncodeValue(sc, nil, val) + bytes, err := tablecodec.EncodeValue(sc, val) if err != nil { return 0, errors.Trace(err) } diff --git a/statistics/update_test.go b/statistics/update_test.go index 7175df1d6733b..0b73641e2ef8a 100644 --- a/statistics/update_test.go +++ b/statistics/update_test.go @@ -1215,7 +1215,7 @@ func (s *testStatsUpdateSuite) TestIndexQueryFeedback(c *C) { sql: "select * from t use index(idx_ag) where a = 1 and g < 21", hist: "column:7 ndv:20 totColSize:98\n" + "num: 13 lower_bound: -838:59:59 upper_bound: 00:00:06 repeats: 0\n" + - "num: 11 lower_bound: 00:00:07 upper_bound: 00:00:13 repeats: 0\n" + + "num: 12 lower_bound: 00:00:07 upper_bound: 00:00:13 repeats: 0\n" + "num: 10 lower_bound: 00:00:14 upper_bound: 00:00:21 repeats: 0", rangeID: tblInfo.Columns[6].ID, idxID: tblInfo.Indices[6].ID, @@ -1226,7 +1226,7 @@ func (s *testStatsUpdateSuite) TestIndexQueryFeedback(c *C) { sql: `select * from t use index(idx_ah) where a = 1 and h < "1000-01-21"`, hist: "column:8 ndv:20 totColSize:180\n" + "num: 13 lower_bound: 1000-01-01 upper_bound: 1000-01-07 repeats: 0\n" + - "num: 11 lower_bound: 1000-01-08 upper_bound: 1000-01-14 repeats: 0\n" + + "num: 12 lower_bound: 1000-01-08 upper_bound: 1000-01-14 repeats: 0\n" + "num: 10 lower_bound: 1000-01-15 upper_bound: 1000-01-21 repeats: 0", rangeID: tblInfo.Columns[7].ID, idxID: tblInfo.Indices[7].ID,