55
66#include < util/string/printf.h>
77
8+ #include < algorithm>
89#include < fstream>
910#include < regex>
1011
@@ -93,8 +94,17 @@ static TKikimrRunner GetKikimrWithJoinSettings(bool useStreamLookupJoin = false,
9394
9495void PrintPlan (const TString& plan) {
9596 Cout << plan << Endl;
96- NYdb::NConsoleClient::TQueryPlanPrinter queryPlanPrinter (NYdb::NConsoleClient::EDataFormat::PrettyTable, true , Cout, 150 );
97+ NYdb::NConsoleClient::TQueryPlanPrinter queryPlanPrinter (NYdb::NConsoleClient::EDataFormat::PrettyTable, true , Cout, 0 );
9798 queryPlanPrinter.Print (plan);
99+
100+ std::string joinOrder = GetJoinOrder (plan).GetStringRobust ();
101+
102+ Cout << " JoinOrder: " << joinOrder << Endl;
103+ std::replace (joinOrder.begin (), joinOrder.end (), ' [' , ' (' );
104+ std::replace (joinOrder.begin (), joinOrder.end (), ' ]' , ' )' );
105+ std::replace (joinOrder.begin (), joinOrder.end (), ' ,' , ' ' );
106+ joinOrder.erase (std::remove (joinOrder.begin (), joinOrder.end (), ' \" ' ), joinOrder.end ());
107+ Cout << " JoinOrder" << joinOrder << Endl;
98108}
99109
100110class TChainTester {
@@ -355,13 +365,6 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
355365 }
356366 }
357367
358- /* tpcds23 has > 1 result sets */
359- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TPCDS23, StreamLookupJoin, ColumnStore) {
360- ExplainJoinOrderTestDataQueryWithStats (
361- " queries/tpcds23.sql" , " stats/tpcds1000s.json" , StreamLookupJoin, ColumnStore
362- );
363- }
364-
365368 Y_UNIT_TEST_XOR_OR_BOTH_FALSE (FiveWayJoin, StreamLookupJoin, ColumnStore) {
366369 ExecuteJoinOrderTestDataQueryWithStats (
367370 " queries/five_way_join.sql" , " stats/basic.json" , StreamLookupJoin, ColumnStore
@@ -410,14 +413,6 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
410413 );
411414 }
412415
413- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TestJoinHint, StreamLookupJoin, ColumnStore) {
414- CheckJoinCardinality (" queries/test_join_hint.sql" , " stats/basic.json" , " InnerJoin (Grace)" , 10e6 , StreamLookupJoin, ColumnStore);
415- }
416-
417- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TestJoinHint2, StreamLookupJoin, ColumnStore) {
418- CheckJoinCardinality (" queries/test_join_hint2.sql" , " stats/basic.json" , " InnerJoin (MapJoin)" , 1 , StreamLookupJoin, ColumnStore);
419- }
420-
421416 Y_UNIT_TEST_XOR_OR_BOTH_FALSE (FiveWayJoinWithConstantFold, StreamLookupJoin, ColumnStore) {
422417 ExecuteJoinOrderTestDataQueryWithStats (" queries/five_way_join_with_constant_fold.sql" , " stats/basic.json" , StreamLookupJoin, ColumnStore);
423418 }
@@ -458,6 +453,13 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
458453 ExecuteJoinOrderTestDataQueryWithStats (" queries/tpcds16.sql" , " stats/tpcds1000s.json" , StreamLookupJoin, ColumnStore);
459454 }
460455
456+ /* tpcds23 has > 1 result sets */
457+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TPCDS23, StreamLookupJoin, ColumnStore) {
458+ ExplainJoinOrderTestDataQueryWithStats (
459+ " queries/tpcds23.sql" , " stats/tpcds1000s.json" , StreamLookupJoin, ColumnStore
460+ );
461+ }
462+
461463 Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TPCDS34, StreamLookupJoin, ColumnStore) {
462464 ExecuteJoinOrderTestDataQueryWithStats (" queries/tpcds34.sql" , " stats/tpcds1000s.json" , StreamLookupJoin, ColumnStore);
463465 }
@@ -494,6 +496,14 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
494496 ExecuteJoinOrderTestDataQueryWithStats (" queries/tpcds96.sql" , " stats/tpcds1000s.json" , StreamLookupJoin, ColumnStore);
495497 }
496498
499+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TestJoinHint1, StreamLookupJoin, ColumnStore) {
500+ CheckJoinCardinality (" queries/test_join_hint1.sql" , " stats/basic.json" , " InnerJoin (Grace)" , 10e6 , StreamLookupJoin, ColumnStore);
501+ }
502+
503+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TestJoinHint2, StreamLookupJoin, ColumnStore) {
504+ CheckJoinCardinality (" queries/test_join_hint2.sql" , " stats/basic.json" , " InnerJoin (MapJoin)" , 1 , StreamLookupJoin, ColumnStore);
505+ }
506+
497507 Y_UNIT_TEST_XOR_OR_BOTH_FALSE (TestJoinOrderHintsSimple, StreamLookupJoin, ColumnStore) {
498508 auto plan = ExecuteJoinOrderTestDataQueryWithStats (" queries/join_order_hints_simple.sql" , " stats/basic.json" , StreamLookupJoin, ColumnStore);
499509 UNIT_ASSERT_VALUES_EQUAL (GetJoinOrder (plan).GetStringRobust (), R"( ["T",["R","S"]])" ) ;
@@ -512,7 +522,7 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
512522 UNIT_ASSERT_C (joinOrder.find (R"( ["T","U"])" ) != TString::npos, joinOrder);
513523 }
514524
515- void JoinOrderTestWithOverridenStats (const TString& queryPath, const TString& statsPath, TString correctJoinOrderPath, bool useStreamLookupJoin, bool useColumnStore
525+ void CanonizedJoinOrderTest (const TString& queryPath, const TString& statsPath, TString correctJoinOrderPath, bool useStreamLookupJoin, bool useColumnStore
516526 ) {
517527 auto kikimr = GetKikimrWithJoinSettings (useStreamLookupJoin, GetStatic (statsPath));
518528 auto db = kikimr.GetTableClient ();
@@ -557,44 +567,44 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
557567 }
558568 }
559569
560- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (OverrideStatsTPCH2 , StreamLookupJoin, ColumnStore) {
561- JoinOrderTestWithOverridenStats (
570+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (CanonizedJoinOrderTPCH2 , StreamLookupJoin, ColumnStore) {
571+ CanonizedJoinOrderTest (
562572 " queries/tpch2.sql" , " stats/tpch1000s.json" , " join_order/tpch2_1000s.json" , StreamLookupJoin, ColumnStore
563573 );
564574 }
565575
566- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (OverrideStatsTPCH9 , StreamLookupJoin, ColumnStore) {
567- JoinOrderTestWithOverridenStats (
576+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (CanonizedJoinOrderTPCH9 , StreamLookupJoin, ColumnStore) {
577+ CanonizedJoinOrderTest (
568578 " queries/tpch9.sql" , " stats/tpch1000s.json" , " join_order/tpch9_1000s.json" , StreamLookupJoin, ColumnStore
569579 );
570580 }
571581
572- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (OverrideStatsTPCDS64 , StreamLookupJoin, ColumnStore) {
573- JoinOrderTestWithOverridenStats (
582+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (CanonizedJoinOrderTPCDS64 , StreamLookupJoin, ColumnStore) {
583+ CanonizedJoinOrderTest (
574584 " queries/tpcds64.sql" , " stats/tpcds1000s.json" , " join_order/tpcds64_1000s.json" , StreamLookupJoin, ColumnStore
575585 );
576586 }
577587
578- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (OverrideStatsTPCDS64_small , StreamLookupJoin, ColumnStore) {
579- JoinOrderTestWithOverridenStats (
588+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (CanonizedJoinOrderTPCDS64_small , StreamLookupJoin, ColumnStore) {
589+ CanonizedJoinOrderTest (
580590 " queries/tpcds64_small.sql" , " stats/tpcds1000s.json" , " join_order/tpcds64_small_1000s.json" , StreamLookupJoin, ColumnStore
581591 );
582592 }
583593
584- Y_UNIT_TEST_XOR_OR_BOTH_FALSE (OverrideStatsTPCDS78 , StreamLookupJoin, ColumnStore) {
585- JoinOrderTestWithOverridenStats (
594+ Y_UNIT_TEST_XOR_OR_BOTH_FALSE (CanonizedJoinOrderTPCDS78 , StreamLookupJoin, ColumnStore) {
595+ CanonizedJoinOrderTest (
586596 " queries/tpcds78.sql" , " stats/tpcds1000s.json" , " join_order/tpcds78_1000s.json" , StreamLookupJoin, ColumnStore
587597 );
588598 }
589599
590- Y_UNIT_TEST (TPCC ) {
591- JoinOrderTestWithOverridenStats (
600+ Y_UNIT_TEST (CanonizedJoinOrderTPCC ) {
601+ CanonizedJoinOrderTest (
592602 " queries/tpcc.sql" , " stats/tpcc.json" , " join_order/tpcc.json" , false , false
593603 );
594604 }
595605
596- Y_UNIT_TEST (LookupBug ) {
597- JoinOrderTestWithOverridenStats (
606+ Y_UNIT_TEST (CanonizedJoinOrderLookupBug ) {
607+ CanonizedJoinOrderTest (
598608 " queries/lookupbug.sql" , " stats/lookupbug.json" , " join_order/lookupbug.json" , false , false
599609 );
600610 }
0 commit comments