MCPcopy Create free account
hub / github.com/MariaDB/server / remove_duplicates

Method remove_duplicates

sql/sql_select.cc:28362–28462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28360*/
28361
28362bool
28363JOIN_TAB::remove_duplicates()
28364
28365{
28366 bool error;
28367 ulong keylength= 0, sort_field_keylength= 0;
28368 uint field_count, item_count;
28369 List<Item> *fields= (this-1)->fields;
28370 Item *item;
28371 THD *thd= join->thd;
28372 SORT_FIELD *sortorder, *sorder;
28373 DBUG_ENTER("remove_duplicates");
28374
28375 DBUG_ASSERT(join->aggr_tables > 0 && table->s->tmp_table != NO_TMP_TABLE);
28376 THD_STAGE_INFO(join->thd, stage_removing_duplicates);
28377
28378 if (!(sortorder= (SORT_FIELD*) my_malloc(PSI_INSTRUMENT_ME,
28379 (fields->elements+1) *
28380 sizeof(SORT_FIELD),
28381 MYF(MY_WME | MY_ZEROFILL))))
28382 DBUG_RETURN(TRUE);
28383
28384 /* Calculate how many saved fields there is in list */
28385 field_count= item_count= 0;
28386
28387 List_iterator<Item> it(*fields);
28388 for (sorder= sortorder ; (item=it++) ;)
28389 {
28390 if (!item->const_item())
28391 {
28392 if (item->get_tmp_table_field())
28393 {
28394 /* Field is stored in temporary table, skip */
28395 field_count++;
28396 }
28397 else
28398 {
28399 /* Item is not stored in temporary table, remember it */
28400 sorder->item= item;
28401 sorder->type= sorder->item->type_handler()->is_packable() ?
28402 SORT_FIELD_ATTR::VARIABLE_SIZE :
28403 SORT_FIELD_ATTR::FIXED_SIZE;
28404 /* Calculate sorder->length */
28405 item->type_handler()->sort_length(thd, item, sorder);
28406 sorder++;
28407 item_count++;
28408 }
28409 }
28410 }
28411 sorder->item= 0; // End marker
28412
28413 if ((field_count + item_count == 0) && ! having &&
28414 !(join->select_options & OPTION_FOUND_ROWS))
28415 {
28416 // only const items with no OPTION_FOUND_ROWS
28417 join->unit->lim.send_first_row(); // Only send first row
28418 my_free(sortorder);
28419 DBUG_RETURN(false);

Callers 1

join_init_read_recordFunction · 0.45

Calls 15

my_mallocFunction · 0.85
my_freeFunction · 0.85
remove_dup_with_compareFunction · 0.85
send_first_rowMethod · 0.80
reset_killedMethod · 0.80
db_typeMethod · 0.80
master_unitMethod · 0.80
free_blobsFunction · 0.70
const_itemMethod · 0.45

Tested by

no test coverage detected