@@ -341,6 +341,68 @@ func (s *testIntegrationSerialSuite) TestSelPushDownTiFlash(c *C) {
341
341
}
342
342
}
343
343
344
+ func (s * testIntegrationSerialSuite ) TestBroadcastJoin (c * C ) {
345
+ tk := testkit .NewTestKit (c , s .store )
346
+ tk .MustExec ("use test" )
347
+ tk .MustExec ("drop table if exists d1_t" )
348
+ tk .MustExec ("create table d1_t(d1_k int, value int)" )
349
+ tk .MustExec ("insert into d1_t values(1,2),(2,3)" )
350
+ tk .MustExec ("analyze table d1_t" )
351
+ tk .MustExec ("drop table if exists d2_t" )
352
+ tk .MustExec ("create table d2_t(d2_k decimal(10,2), value int)" )
353
+ tk .MustExec ("insert into d2_t values(10.11,2),(10.12,3)" )
354
+ tk .MustExec ("analyze table d2_t" )
355
+ tk .MustExec ("drop table if exists d3_t" )
356
+ tk .MustExec ("create table d3_t(d3_k date, value int)" )
357
+ tk .MustExec ("insert into d3_t values(date'2010-01-01',2),(date'2010-01-02',3)" )
358
+ tk .MustExec ("analyze table d3_t" )
359
+ tk .MustExec ("drop table if exists fact_t" )
360
+ tk .MustExec ("create table fact_t(d1_k int, d2_k decimal(10,2), d3_k date, col1 int, col2 int, col3 int)" )
361
+ tk .MustExec ("insert into fact_t values(1,10.11,date'2010-01-01',1,2,3),(1,10.11,date'2010-01-02',1,2,3),(1,10.12,date'2010-01-01',1,2,3),(1,10.12,date'2010-01-02',1,2,3)" )
362
+ tk .MustExec ("insert into fact_t values(2,10.11,date'2010-01-01',1,2,3),(2,10.11,date'2010-01-02',1,2,3),(2,10.12,date'2010-01-01',1,2,3),(2,10.12,date'2010-01-02',1,2,3)" )
363
+ tk .MustExec ("analyze table fact_t" )
364
+
365
+ // Create virtual tiflash replica info.
366
+ dom := domain .GetDomain (tk .Se )
367
+ is := dom .InfoSchema ()
368
+ db , exists := is .SchemaByName (model .NewCIStr ("test" ))
369
+ c .Assert (exists , IsTrue )
370
+ for _ , tblInfo := range db .Tables {
371
+ if tblInfo .Name .L == "fact_t" || tblInfo .Name .L == "d1_t" || tblInfo .Name .L == "d2_t" || tblInfo .Name .L == "d3_t" {
372
+ tblInfo .TiFlashReplica = & model.TiFlashReplicaInfo {
373
+ Count : 1 ,
374
+ Available : true ,
375
+ }
376
+ }
377
+ }
378
+
379
+ tk .MustExec ("set @@session.tidb_isolation_read_engines = 'tiflash'" )
380
+ tk .MustExec ("set @@session.tidb_opt_broadcast_join = 1" )
381
+ var input []string
382
+ var output []struct {
383
+ SQL string
384
+ Plan []string
385
+ }
386
+ s .testData .GetTestCases (c , & input , & output )
387
+ for i , tt := range input {
388
+ s .testData .OnRecord (func () {
389
+ output [i ].SQL = tt
390
+ output [i ].Plan = s .testData .ConvertRowsToStrings (tk .MustQuery (tt ).Rows ())
391
+ })
392
+ res := tk .MustQuery (tt )
393
+ res .Check (testkit .Rows (output [i ].Plan ... ))
394
+ }
395
+
396
+ // out join not supported
397
+ _ , err := tk .Exec ("explain select /*+ tidb_bcj(fact_t, d1_t) */ count(*) from fact_t left join d1_t on fact_t.d1_k = d1_t.d1_k" )
398
+ c .Assert (err , NotNil )
399
+ c .Assert (err .Error (), Equals , "[planner:1815]Internal : Can't find a proper physical plan for this query" )
400
+ // join with non-equal condition not supported
401
+ _ , err = tk .Exec ("explain select /*+ tidb_bcj(fact_t, d1_t) */ count(*) from fact_t join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col1 > d1_t.value" )
402
+ c .Assert (err , NotNil )
403
+ c .Assert (err .Error (), Equals , "[planner:1815]Internal : Can't find a proper physical plan for this query" )
404
+ }
405
+
344
406
func (s * testIntegrationSerialSuite ) TestIssue15110 (c * C ) {
345
407
tk := testkit .NewTestKit (c , s .store )
346
408
tk .MustExec ("use test" )
0 commit comments