MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / mysql_sql_parse_group

Function mysql_sql_parse_group

sqladvisor/main.cc:775–809  ·  view source on GitHub ↗

如果SQL中有group by, 判断group by 的条件是哪一张表的。当group by 来自于多张表,则不做处理。只有当group by 的条件都来自于同一张表,或者这张表是驱动表则将返回这张表,否则返回NULL

Source from the content-addressed store, hash-verified

773
774//如果SQL中有group by, 判断group by 的条件是哪一张表的。当group by 来自于多张表,则不做处理。只有当group by 的条件都来自于同一张表,或者这张表是驱动表则将返回这张表,否则返回NULL
775TABLE_LIST* mysql_sql_parse_group() {
776 TABLE_LIST * table = NULL;
777 bool is_only_one_table = true;
778 SQL_I_List<ORDER> group_list = current_lex->group_list;
779 if (group_list.elements > 0) {
780 if (options.verbose)
781 sql_print_information("第%d步:开始解析group by 条件 \n", STEP_CNT++);
782 ORDER *order_field = group_list.first;
783 while (order_field != NULL) {
784 if (order_field->item_ptr->type() == Item::FIELD_ITEM) {
785 TABLE_LIST * tbname2 = find_table(
786 (Item_field *) (order_field->item_ptr));
787 if (tbname2 == NULL) {
788 is_only_one_table = false;
789 break;
790 } else {
791 if (table == NULL) {
792 table = tbname2;
793 } else if (table->table_name != tbname2->table_name) {
794 is_only_one_table = false;
795 break;
796 }
797 }
798 }
799 order_field = order_field->next;
800 }
801
802 if (is_only_one_table) {
803 if (TABLE_ELEMENT == 1 || table->is_table_driverd) {
804 return table;
805 }
806 }
807 }
808 return NULL;
809}
810
811//同理,同时判断order by 表是否相同,还要判断升降序是否一致
812TABLE_LIST* mysql_sql_parse_order() {

Callers 1

mysql_sql_parse_adminFunction · 0.85

Calls 3

sql_print_informationFunction · 0.85
find_tableFunction · 0.85
typeMethod · 0.45

Tested by

no test coverage detected