~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/table.cc

  • Committer: Brian Aker
  • Date: 2008-07-08 16:53:50 UTC
  • mfrom: (51.1.8 remove-dbug)
  • Revision ID: brian@tangent.org-20080708165350-y246k7585xv56c0m
Merging in Jay's Tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
Object_creation_ctx *Object_creation_ctx::set_n_backup(THD *thd)
44
44
{
45
45
  Object_creation_ctx *backup_ctx;
46
 
  DBUG_ENTER("Object_creation_ctx::set_n_backup");
47
46
 
48
47
  backup_ctx= create_backup_ctx(thd);
49
48
  change_env(thd);
50
49
 
51
 
  DBUG_RETURN(backup_ctx);
 
50
  return(backup_ctx);
52
51
}
53
52
 
54
53
void Object_creation_ctx::restore_env(THD *thd, Object_creation_ctx *backup_ctx)
133
132
 
134
133
TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name)
135
134
{
136
 
  DBUG_ASSERT(db != NULL);
137
 
  DBUG_ASSERT(name != NULL);
 
135
  assert(db != NULL);
 
136
  assert(name != NULL);
138
137
 
139
138
  if ((db->length == INFORMATION_SCHEMA_NAME.length) &&
140
139
      (my_strcasecmp(system_charset_info,
170
169
  char *key_buff, *path_buff;
171
170
  char path[FN_REFLEN];
172
171
  uint path_length;
173
 
  DBUG_ENTER("alloc_table_share");
174
 
  DBUG_PRINT("enter", ("table: '%s'.'%s'",
175
 
                       table_list->db, table_list->table_name));
176
172
 
177
173
  path_length= build_table_filename(path, sizeof(path) - 1,
178
174
                                    table_list->db,
219
215
    pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST);
220
216
    pthread_cond_init(&share->cond, NULL);
221
217
  }
222
 
  DBUG_RETURN(share);
 
218
  return(share);
223
219
}
224
220
 
225
221
 
250
246
                          uint key_length, const char *table_name,
251
247
                          const char *path)
252
248
{
253
 
  DBUG_ENTER("init_tmp_table_share");
254
 
  DBUG_PRINT("enter", ("table: '%s'.'%s'", key, table_name));
255
249
 
256
250
  bzero((char*) share, sizeof(*share));
257
251
  init_sql_alloc(&share->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
281
275
  */
282
276
  share->table_map_id= (ulong) thd->query_id;
283
277
 
284
 
  DBUG_VOID_RETURN;
 
278
  return;
285
279
}
286
280
 
287
281
 
299
293
void free_table_share(TABLE_SHARE *share)
300
294
{
301
295
  MEM_ROOT mem_root;
302
 
  DBUG_ENTER("free_table_share");
303
 
  DBUG_PRINT("enter", ("table: %s.%s", share->db.str, share->table_name.str));
304
 
  DBUG_ASSERT(share->ref_count == 0);
 
296
  assert(share->ref_count == 0);
305
297
 
306
298
  /*
307
299
    If someone is waiting for this to be deleted, inform it about this.
328
320
  /* We must copy mem_root from share because share is allocated through it */
329
321
  memcpy((char*) &mem_root, (char*) &share->mem_root, sizeof(mem_root));
330
322
  free_root(&mem_root, MYF(0));                 // Free's share
331
 
  DBUG_VOID_RETURN;
 
323
  return;
332
324
}
333
325
 
334
326
/*
364
356
  uchar head[64], *disk_buff;
365
357
  char  path[FN_REFLEN];
366
358
  MEM_ROOT **root_ptr, *old_root;
367
 
  DBUG_ENTER("open_table_def");
368
 
  DBUG_PRINT("enter", ("table: '%s'.'%s'  path: '%s'", share->db.str,
369
 
                       share->table_name.str, share->normalized_path.str));
370
359
 
371
360
  error= 1;
372
361
  error_given= 0;
403
392
      The following is a safety test and should never fail
404
393
      as the old file name should never be longer than the new one.
405
394
    */
406
 
    DBUG_ASSERT(length <= share->normalized_path.length);
 
395
    assert(length <= share->normalized_path.length);
407
396
    /*
408
397
      If the old and the new names have the same length,
409
398
      then table name does not have tricky characters,
473
462
    open_table_error(share, error, (share->open_errno= my_errno), 0);
474
463
  }
475
464
 
476
 
  DBUG_RETURN(error);
 
465
  return(error);
477
466
}
478
467
 
479
468
 
507
496
  my_bitmap_map *bitmaps;
508
497
  uchar *buff= 0;
509
498
  uchar *field_extra_info= 0;
510
 
  DBUG_ENTER("open_binary_frm");
511
499
 
512
500
  new_field_pack_flag= head[27];
513
501
  new_frm_ver= (head[2] - FRM_VER);
532
520
    share->frm_version= FRM_VER_TRUE_VARCHAR;
533
521
 
534
522
  legacy_db_type= DB_TYPE_FIRST_DYNAMIC;
535
 
  DBUG_ASSERT(share->db_plugin == NULL);
 
523
  assert(share->db_plugin == NULL);
536
524
  /*
537
525
    if the storage engine is dynamic, no point in resolving it by its
538
526
    dynamically allocated legacy_db_type. We will resolve it later by name.
662
650
                                         keyinfo->comment.length);
663
651
      strpos+= 2 + keyinfo->comment.length;
664
652
    } 
665
 
    DBUG_ASSERT(test(keyinfo->flags & HA_USES_COMMENT) == 
 
653
    assert(test(keyinfo->flags & HA_USES_COMMENT) == 
666
654
               (keyinfo->comment.length > 0));
667
655
  }
668
656
 
678
666
  {
679
667
    /* Read extra data segment */
680
668
    uchar *next_chunk, *buff_end;
681
 
    DBUG_PRINT("info", ("extra segment size is %u bytes", n_length));
682
669
    if (!(next_chunk= buff= (uchar*) my_malloc(n_length, MYF(MY_WME))))
683
670
      goto err;
684
671
    if (pread(file, buff, n_length, record_offset + share->reclength) == 0)
721
708
        */
722
709
        plugin_unlock(NULL, share->db_plugin);
723
710
        share->db_plugin= my_plugin_lock(NULL, &tmp_plugin);
724
 
        DBUG_PRINT("info", ("setting dbtype to '%.*s' (%d)",
725
 
                            str_db_type_length, next_chunk + 2,
726
 
                            ha_legacy_type(share->db_type())));
727
711
      }
728
712
      else if (!tmp_plugin)
729
713
      {
746
730
      //reading long table comment
747
731
      if (next_chunk + 2 > buff_end)
748
732
      {
749
 
          DBUG_PRINT("error",
750
 
                     ("long table comment is not defined in .frm"));
751
733
          my_free(buff, MYF(0));
752
734
          goto err;
753
735
      }
760
742
      }
761
743
      next_chunk+= 2 + share->comment.length;
762
744
    }
763
 
    DBUG_ASSERT (next_chunk <= buff_end);
 
745
    assert(next_chunk <= buff_end);
764
746
    if (share->mysql_version >= MYSQL_VERSION_TABLESPACE_IN_FRM_CGE)
765
747
    {
766
748
      /*
774
756
      {
775
757
        if (share->mysql_version >= MYSQL_VERSION_TABLESPACE_IN_FRM)
776
758
        {
777
 
          DBUG_PRINT("error", ("Found no field extra info"));
778
759
          goto err;
779
760
        }
780
 
        DBUG_PRINT("info", ("Found no field extra info"));
781
761
      }
782
762
      else
783
763
      {
784
 
        DBUG_PRINT("info", ("Found field extra info"));
785
764
        const uint format_section_header_size= 8;
786
765
        uint format_section_len= uint2korr(next_chunk+0);
787
766
        uint flags=              uint4korr(next_chunk+2);
803
782
        next_chunk+= format_section_len;
804
783
      }
805
784
    }
806
 
    DBUG_ASSERT (next_chunk <= buff_end);
 
785
    assert (next_chunk <= buff_end);
807
786
    if (next_chunk > buff_end)
808
787
    {
809
 
      DBUG_PRINT("error", ("Buffer overflow in field extra info"));
810
788
      goto err;
811
789
    }
812
790
  }
840
818
                                     share->comment.length);
841
819
  }
842
820
 
843
 
  DBUG_PRINT("info",("i_count: %d  i_parts: %d  index: %d  n_length: %d  int_length: %d  com_length: %d", interval_count,interval_parts, share->keys,n_length,int_length, com_length));
844
821
 
845
822
  if (!(field_ptr = (Field **)
846
823
        alloc_root(&share->mem_root,
946
923
      storage_type= (enum ha_storage_media)(tmp & STORAGE_TYPE_MASK);
947
924
      column_format= (enum column_format_type)
948
925
                    ((tmp >> COLUMN_FORMAT_SHIFT) & COLUMN_FORMAT_MASK);
949
 
      DBUG_PRINT("info", ("Field extra: storage %u format %u",
950
 
                          storage_type, column_format));
951
926
    }
952
927
    if (new_frm_ver >= 3)
953
928
    {
1337
1312
#endif
1338
1313
  if (buff)
1339
1314
    my_free(buff, MYF(0));
1340
 
  DBUG_RETURN (0);
 
1315
  return (0);
1341
1316
 
1342
1317
 err:
1343
1318
  if (buff)
1351
1326
  hash_free(&share->name_hash);
1352
1327
 
1353
1328
  open_table_error(share, error, share->open_errno, errarg);
1354
 
  DBUG_RETURN(error);
 
1329
  return(error);
1355
1330
} /* open_binary_frm */
1356
1331
 
1357
1332
 
1392
1367
  bool error_reported= FALSE;
1393
1368
  uchar *record, *bitmaps;
1394
1369
  Field **field_ptr;
1395
 
  DBUG_ENTER("open_table_from_share");
1396
 
  DBUG_PRINT("enter",("name: '%s.%s'  form: 0x%lx, open mode:%s",
1397
 
                      share->db.str,
1398
 
                      share->table_name.str,
1399
 
                      (long) outparam,
1400
 
                      (open_mode == OTM_OPEN)?"open":
1401
 
                      ((open_mode == OTM_CREATE)?"create":"alter")));
1402
1370
 
1403
1371
  /* Parsing of partitioning information from .frm needs thd->lex set up. */
1404
 
  DBUG_ASSERT(thd->lex->is_lex_started);
 
1372
  assert(thd->lex->is_lex_started);
1405
1373
 
1406
1374
  error= 1;
1407
1375
  bzero((char*) outparam, sizeof(*outparam));
1428
1396
  }
1429
1397
  else
1430
1398
  {
1431
 
    DBUG_ASSERT(!db_stat);
 
1399
    assert(!db_stat);
1432
1400
  }
1433
1401
 
1434
1402
  error= 4;
1597
1565
            Too many files opened, use same error message as if the .frm
1598
1566
            file can't open
1599
1567
           */
1600
 
          DBUG_PRINT("error", ("open file: %s failed, too many files opened (errno: %d)", 
1601
 
                  share->normalized_path.str, ha_err));
1602
1568
          error= 1;
1603
1569
          my_errno= EMFILE;
1604
1570
          break;
1622
1588
                               HA_HAS_OWN_BINLOGGING);
1623
1589
  thd->status_var.opened_tables++;
1624
1590
 
1625
 
  DBUG_RETURN (0);
 
1591
  return (0);
1626
1592
 
1627
1593
 err:
1628
1594
  if (!error_reported && !(prgflag & DONT_GIVE_ERROR))
1632
1598
  outparam->db_stat=0;
1633
1599
  free_root(&outparam->mem_root, MYF(0));       // Safe to call on bzero'd root
1634
1600
  my_free((char*) outparam->alias, MYF(MY_ALLOW_ZERO_PTR));
1635
 
  DBUG_RETURN (error);
 
1601
  return (error);
1636
1602
}
1637
1603
 
1638
1604
 
1648
1614
int closefrm(register TABLE *table, bool free_share)
1649
1615
{
1650
1616
  int error=0;
1651
 
  DBUG_ENTER("closefrm");
1652
 
  DBUG_PRINT("enter", ("table: 0x%lx", (long) table));
1653
1617
 
1654
1618
  if (table->db_stat)
1655
1619
    error=table->file->close();
1671
1635
      free_table_share(table->s);
1672
1636
  }
1673
1637
  free_root(&table->mem_root, MYF(0));
1674
 
  DBUG_RETURN(error);
 
1638
  return(error);
1675
1639
}
1676
1640
 
1677
1641
 
1695
1659
  uint a_length,names,length;
1696
1660
  uchar *pos,*buf;
1697
1661
  ulong ret_value=0;
1698
 
  DBUG_ENTER("get_form_pos");
1699
1662
 
1700
1663
  names=uint2korr(head+8);
1701
1664
  a_length=(names+2)*sizeof(char *);            /* Room for two extra */
1715
1678
                MYF(MY_NABP)))
1716
1679
    {                                           /* purecov: inspected */
1717
1680
      x_free((uchar*) buf);                     /* purecov: inspected */
1718
 
      DBUG_RETURN(0L);                          /* purecov: inspected */
 
1681
      return(0L);                               /* purecov: inspected */
1719
1682
    }
1720
1683
    pos= buf+a_length+length;
1721
1684
    ret_value=uint4korr(pos);
1733
1696
    str=(char *) (buf+a_length);
1734
1697
    fix_type_pointers((const char ***) &buf,save_names,1,&str);
1735
1698
  }
1736
 
  DBUG_RETURN(ret_value);
 
1699
  return(ret_value);
1737
1700
}
1738
1701
 
1739
1702
 
1746
1709
 
1747
1710
int read_string(File file, uchar**to, size_t length)
1748
1711
{
1749
 
  DBUG_ENTER("read_string");
1750
1712
 
1751
1713
  x_free(*to);
1752
1714
  if (!(*to= (uchar*) my_malloc(length+1,MYF(MY_WME))) ||
1754
1716
  {
1755
1717
    x_free(*to);                              /* purecov: inspected */
1756
1718
    *to= 0;                                   /* purecov: inspected */
1757
 
    DBUG_RETURN(1);                           /* purecov: inspected */
 
1719
    return(1);                           /* purecov: inspected */
1758
1720
  }
1759
1721
  *((char*) *to+length)= '\0';
1760
 
  DBUG_RETURN (0);
 
1722
  return (0);
1761
1723
} /* read_string */
1762
1724
 
1763
1725
 
1770
1732
  ulong endpos,newpos;
1771
1733
  uchar buff[IO_SIZE];
1772
1734
  uchar *pos;
1773
 
  DBUG_ENTER("make_new_entry");
1774
1735
 
1775
1736
  length=(uint) strlen(newname)+1;
1776
1737
  n_length=uint2korr(fileinfo+4);
1789
1750
    {
1790
1751
      VOID(my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0)));
1791
1752
      if (my_read(file, buff, bufflength, MYF(MY_NABP+MY_WME)))
1792
 
        DBUG_RETURN(0L);
 
1753
        return(0L);
1793
1754
      VOID(my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET,
1794
1755
                   MYF(0)));
1795
1756
      if ((my_write(file, buff,bufflength,MYF(MY_NABP+MY_WME))))
1796
 
        DBUG_RETURN(0);
 
1757
        return(0);
1797
1758
      endpos-=bufflength; bufflength=IO_SIZE;
1798
1759
    }
1799
1760
    bzero(buff,IO_SIZE);                        /* Null new block */
1800
1761
    VOID(my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0)));
1801
1762
    if (my_write(file,buff,bufflength,MYF(MY_NABP+MY_WME)))
1802
 
        DBUG_RETURN(0L);
 
1763
        return(0L);
1803
1764
    maxlength+=IO_SIZE;                         /* Fix old ref */
1804
1765
    int2store(fileinfo+6,maxlength);
1805
1766
    for (i=names, pos= (uchar*) *formnames->type_names+n_length-1; i-- ;
1822
1783
      (names && my_write(file,(uchar*) (*formnames->type_names+n_length-1),
1823
1784
                         names*4, MYF(MY_NABP+MY_WME))) ||
1824
1785
      my_write(file, fileinfo+10, 4,MYF(MY_NABP+MY_WME)))
1825
 
    DBUG_RETURN(0L); /* purecov: inspected */
 
1786
    return(0L); /* purecov: inspected */
1826
1787
 
1827
1788
  int2store(fileinfo+8,names+1);
1828
1789
  int2store(fileinfo+4,n_length+length);
1829
1790
  (void)ftruncate(file, newpos);/* Append file with '\0' */
1830
 
  DBUG_RETURN(newpos);
 
1791
  return(newpos);
1831
1792
} /* make_new_entry */
1832
1793
 
1833
1794
 
1838
1799
  int err_no;
1839
1800
  char buff[FN_REFLEN];
1840
1801
  myf errortype= ME_ERROR+ME_WAITTANG;
1841
 
  DBUG_ENTER("open_table_error");
1842
1802
 
1843
1803
  switch (error) {
1844
1804
  case 7:
1902
1862
    my_error(ER_NOT_FORM_FILE, errortype, buff, 0);
1903
1863
    break;
1904
1864
  }
1905
 
  DBUG_VOID_RETURN;
 
1865
  return;
1906
1866
} /* open_table_error */
1907
1867
 
1908
1868
 
2126
2086
    int2store(fileinfo+6,IO_SIZE);              /* Next block starts here */
2127
2087
    for (i= 0; i < keys; i++)
2128
2088
    {
2129
 
      DBUG_ASSERT(test(key_info[i].flags & HA_USES_COMMENT) == 
 
2089
      assert(test(key_info[i].flags & HA_USES_COMMENT) == 
2130
2090
                 (key_info[i].comment.length > 0));
2131
2091
      if (key_info[i].flags & HA_USES_COMMENT)
2132
2092
        key_comment_total_bytes += 2 + key_info[i].comment.length;
2208
2168
void update_create_info_from_table(HA_CREATE_INFO *create_info, TABLE *table)
2209
2169
{
2210
2170
  TABLE_SHARE *share= table->s;
2211
 
  DBUG_ENTER("update_create_info_from_table");
2212
2171
 
2213
2172
  create_info->max_rows= share->max_rows;
2214
2173
  create_info->min_rows= share->min_rows;
2221
2180
  create_info->table_charset= 0;
2222
2181
  create_info->comment= share->comment;
2223
2182
 
2224
 
  DBUG_VOID_RETURN;
 
2183
  return;
2225
2184
}
2226
2185
 
2227
2186
int
2304
2263
                       key_part_map keypart_map)
2305
2264
{
2306
2265
  /* works only with key prefixes */
2307
 
  DBUG_ASSERT(((keypart_map + 1) & keypart_map) == 0);
 
2266
  assert(((keypart_map + 1) & keypart_map) == 0);
2308
2267
 
2309
2268
  KEY *key_info= table->s->key_info+key;
2310
2269
  KEY_PART_INFO *key_part= key_info->key_part;
2404
2363
      This assert is to catch use of this byte if we decide to
2405
2364
      use non-utf8 as system_character_set.
2406
2365
    */
2407
 
    DBUG_ASSERT(*name != NAMES_SEP_CHAR);
 
2366
    assert(*name != NAMES_SEP_CHAR);
2408
2367
    name++;
2409
2368
    name_length++;
2410
2369
  }
2437
2396
  uint i;
2438
2397
  my_bool error= FALSE;
2439
2398
  my_bool fields_diff_count;
2440
 
  DBUG_ENTER("table_check_intact");
2441
 
  DBUG_PRINT("info",("table: %s  expected_count: %d",
2442
 
                     table->alias, table_f_count));
2443
2399
 
2444
2400
  fields_diff_count= (table->s->fields != table_f_count);
2445
2401
  if (fields_diff_count)
2446
2402
  {
2447
 
    DBUG_PRINT("info", ("Column count has changed, checking the definition"));
2448
2403
 
2449
2404
    /* previous MySQL version */
2450
2405
    if (MYSQL_VERSION_ID > table->s->mysql_version)
2452
2407
      sql_print_error(ER(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE),
2453
2408
                      table->alias, table_f_count, table->s->fields,
2454
2409
                      table->s->mysql_version, MYSQL_VERSION_ID);
2455
 
      DBUG_RETURN(TRUE);
 
2410
      return(TRUE);
2456
2411
    }
2457
2412
    else if (MYSQL_VERSION_ID == table->s->mysql_version)
2458
2413
    {
2459
2414
      sql_print_error(ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED), table->alias,
2460
2415
                      table_f_count, table->s->fields);
2461
 
      DBUG_RETURN(TRUE);
 
2416
      return(TRUE);
2462
2417
    }
2463
2418
    /*
2464
2419
      Something has definitely changed, but we're running an older
2549
2504
      error= TRUE;
2550
2505
    }
2551
2506
  }
2552
 
  DBUG_RETURN(error);
 
2507
  return(error);
2553
2508
}
2554
2509
 
2555
2510
 
2606
2561
  for (Field **ptr= field; *ptr; ptr++)
2607
2562
  {
2608
2563
    Item_field *item_field= (Item_field*) it++;
2609
 
    DBUG_ASSERT(item_field != 0);
 
2564
    assert(item_field != 0);
2610
2565
    item_field->reset_field(*ptr);
2611
2566
  }
2612
2567
}
2634
2589
static Item *
2635
2590
merge_on_conds(THD *thd, TABLE_LIST *table, bool is_cascaded)
2636
2591
{
2637
 
  DBUG_ENTER("merge_on_conds");
2638
2592
 
2639
2593
  Item *cond= NULL;
2640
 
  DBUG_PRINT("info", ("alias: %s", table->alias));
2641
2594
  if (table->on_expr)
2642
2595
    cond= table->on_expr->copy_andor_structure(thd);
2643
2596
  if (!table->nested_join)
2644
 
    DBUG_RETURN(cond);
 
2597
    return(cond);
2645
2598
  List_iterator<TABLE_LIST> li(table->nested_join->join_list);
2646
2599
  while (TABLE_LIST *tbl= li++)
2647
2600
  {
2648
2601
    cond= and_conds(cond, merge_on_conds(thd, tbl, is_cascaded));
2649
2602
  }
2650
 
  DBUG_RETURN(cond);
 
2603
  return(cond);
2651
2604
}
2652
2605
 
2653
2606
 
2776
2729
 
2777
2730
  if (is_leaf_for_name_resolution())
2778
2731
    return this;
2779
 
  DBUG_ASSERT(nested_join);
 
2732
  assert(nested_join);
2780
2733
 
2781
2734
  for (cur_nested_join= nested_join;
2782
2735
       cur_nested_join;
2833
2786
 
2834
2787
  if (is_leaf_for_name_resolution())
2835
2788
    return this;
2836
 
  DBUG_ASSERT(nested_join);
 
2789
  assert(nested_join);
2837
2790
 
2838
2791
  for (cur_nested_join= nested_join;
2839
2792
       cur_nested_join;
2863
2816
Natural_join_column::Natural_join_column(Field_translator *field_param,
2864
2817
                                         TABLE_LIST *tab)
2865
2818
{
2866
 
  DBUG_ASSERT(tab->field_translation);
 
2819
  assert(tab->field_translation);
2867
2820
  view_field= field_param;
2868
2821
  table_field= NULL;
2869
2822
  table_ref= tab;
2874
2827
Natural_join_column::Natural_join_column(Field *field_param,
2875
2828
                                         TABLE_LIST *tab)
2876
2829
{
2877
 
  DBUG_ASSERT(tab->table == field_param->table);
 
2830
  assert(tab->table == field_param->table);
2878
2831
  table_field= field_param;
2879
2832
  view_field= NULL;
2880
2833
  table_ref= tab;
2886
2839
{
2887
2840
  if (view_field)
2888
2841
  {
2889
 
    DBUG_ASSERT(table_field == NULL);
 
2842
    assert(table_field == NULL);
2890
2843
    return view_field->name;
2891
2844
  }
2892
2845
 
2898
2851
{
2899
2852
  if (view_field)
2900
2853
  {
2901
 
    DBUG_ASSERT(table_field == NULL);
 
2854
    assert(table_field == NULL);
2902
2855
    return create_view_field(thd, table_ref, &view_field->item,
2903
2856
                             view_field->name);
2904
2857
  }
2910
2863
{
2911
2864
  if (view_field)
2912
2865
  {
2913
 
    DBUG_ASSERT(table_field == NULL);
 
2866
    assert(table_field == NULL);
2914
2867
    return NULL;
2915
2868
  }
2916
2869
  return table_field;
2919
2872
 
2920
2873
const char *Natural_join_column::table_name()
2921
2874
{
2922
 
  DBUG_ASSERT(table_ref);
 
2875
  assert(table_ref);
2923
2876
  return table_ref->alias;
2924
2877
}
2925
2878
 
2931
2884
    ensure consistency. An exception are I_S schema tables, which
2932
2885
    are inconsistent in this respect.
2933
2886
  */
2934
 
  DBUG_ASSERT(!strcmp(table_ref->db,
 
2887
  assert(!strcmp(table_ref->db,
2935
2888
                      table_ref->table->s->db.str) ||
2936
2889
              (table_ref->schema_table &&
2937
2890
               table_ref->table->s->db.str[0] == 0));
2941
2894
 
2942
2895
void Field_iterator_view::set(TABLE_LIST *table)
2943
2896
{
2944
 
  DBUG_ASSERT(table->field_translation);
 
2897
  assert(table->field_translation);
2945
2898
  view= table;
2946
2899
  ptr= table->field_translation;
2947
2900
  array_end= table->field_translation_end;
2983
2936
Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
2984
2937
                        const char *name)
2985
2938
{
2986
 
  DBUG_ENTER("create_view_field");
2987
2939
  if (view->schema_table_reformed)
2988
2940
  {
2989
2941
    Item *field= *field_ref;
2993
2945
      ('mysql_schema_table' function). So we can return directly the
2994
2946
      field. This case happens only for 'show & where' commands.
2995
2947
    */
2996
 
    DBUG_ASSERT(field && field->fixed);
2997
 
    DBUG_RETURN(field);
 
2948
    assert(field && field->fixed);
 
2949
    return(field);
2998
2950
  }
2999
2951
 
3000
 
  DBUG_RETURN(NULL);
 
2952
  return(NULL);
3001
2953
}
3002
2954
 
3003
2955
 
3004
2956
void Field_iterator_natural_join::set(TABLE_LIST *table_ref)
3005
2957
{
3006
 
  DBUG_ASSERT(table_ref->join_columns);
 
2958
  assert(table_ref->join_columns);
3007
2959
  column_ref_it.init(*(table_ref->join_columns));
3008
2960
  cur_column_ref= column_ref_it++;
3009
2961
}
3012
2964
void Field_iterator_natural_join::next()
3013
2965
{
3014
2966
  cur_column_ref= column_ref_it++;
3015
 
  DBUG_ASSERT(!cur_column_ref || ! cur_column_ref->table_field ||
 
2967
  assert(!cur_column_ref || ! cur_column_ref->table_field ||
3016
2968
              cur_column_ref->table_ref->table ==
3017
2969
              cur_column_ref->table_field->table);
3018
2970
}
3020
2972
 
3021
2973
void Field_iterator_table_ref::set_field_iterator()
3022
2974
{
3023
 
  DBUG_ENTER("Field_iterator_table_ref::set_field_iterator");
3024
2975
  /*
3025
2976
    If the table reference we are iterating over is a natural join, or it is
3026
2977
    an operand of a natural join, and TABLE_LIST::join_columns contains all
3031
2982
  if (table_ref->is_join_columns_complete)
3032
2983
  {
3033
2984
    /* Necesary, but insufficient conditions. */
3034
 
    DBUG_ASSERT(table_ref->is_natural_join ||
 
2985
    assert(table_ref->is_natural_join ||
3035
2986
                table_ref->nested_join ||
3036
2987
                table_ref->join_columns &&
3037
2988
                /* This is a merge view. */
3044
2995
                  table_ref->join_columns->elements ==
3045
2996
                  table_ref->table->s->fields)));
3046
2997
    field_it= &natural_join_it;
3047
 
    DBUG_PRINT("info",("field_it for '%s' is Field_iterator_natural_join",
3048
 
                       table_ref->alias));
3049
2998
  }
3050
2999
  /* This is a base table or stored view. */
3051
3000
  else
3052
3001
  {
3053
 
    DBUG_ASSERT(table_ref->table);
 
3002
    assert(table_ref->table);
3054
3003
    field_it= &table_field_it;
3055
 
    DBUG_PRINT("info", ("field_it for '%s' is Field_iterator_table",
3056
 
                        table_ref->alias));
3057
3004
  }
3058
3005
  field_it->set(table_ref);
3059
 
  DBUG_VOID_RETURN;
 
3006
  return;
3060
3007
}
3061
3008
 
3062
3009
 
3063
3010
void Field_iterator_table_ref::set(TABLE_LIST *table)
3064
3011
{
3065
 
  DBUG_ASSERT(table);
 
3012
  assert(table);
3066
3013
  first_leaf= table->first_leaf_for_name_resolution();
3067
3014
  last_leaf=  table->last_leaf_for_name_resolution();
3068
 
  DBUG_ASSERT(first_leaf && last_leaf);
 
3015
  assert(first_leaf && last_leaf);
3069
3016
  table_ref= first_leaf;
3070
3017
  set_field_iterator();
3071
3018
}
3082
3029
  if (field_it->end_of_fields() && table_ref != last_leaf)
3083
3030
  {
3084
3031
    table_ref= table_ref->next_name_resolution_table;
3085
 
    DBUG_ASSERT(table_ref);
 
3032
    assert(table_ref);
3086
3033
    set_field_iterator();
3087
3034
  }
3088
3035
}
3093
3040
  if (table_ref->is_natural_join)
3094
3041
    return natural_join_it.column_ref()->table_name();
3095
3042
 
3096
 
  DBUG_ASSERT(!strcmp(table_ref->table_name,
 
3043
  assert(!strcmp(table_ref->table_name,
3097
3044
                      table_ref->table->s->table_name.str));
3098
3045
  return table_ref->table_name;
3099
3046
}
3109
3056
    ensure consistency. An exception are I_S schema tables, which
3110
3057
    are inconsistent in this respect.
3111
3058
  */
3112
 
  DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) ||
 
3059
  assert(!strcmp(table_ref->db, table_ref->table->s->db.str) ||
3113
3060
              (table_ref->schema_table &&
3114
3061
               table_ref->table->s->db.str[0] == 0));
3115
3062
 
3185
3132
      already created via one of the two constructor calls above. In this case
3186
3133
      we just return the already created column reference.
3187
3134
    */
3188
 
    DBUG_ASSERT(table_ref->is_join_columns_complete);
 
3135
    assert(table_ref->is_join_columns_complete);
3189
3136
    is_created= FALSE;
3190
3137
    nj_col= natural_join_it.column_ref();
3191
 
    DBUG_ASSERT(nj_col);
 
3138
    assert(nj_col);
3192
3139
  }
3193
 
  DBUG_ASSERT(!nj_col->table_field ||
 
3140
  assert(!nj_col->table_field ||
3194
3141
              nj_col->table_ref->table == nj_col->table_field->table);
3195
3142
 
3196
3143
  /*
3201
3148
  if (is_created)
3202
3149
  {
3203
3150
    /* Make sure not all columns were materialized. */
3204
 
    DBUG_ASSERT(!add_table_ref->is_join_columns_complete);
 
3151
    assert(!add_table_ref->is_join_columns_complete);
3205
3152
    if (!add_table_ref->join_columns)
3206
3153
    {
3207
3154
      /* Create a list of natural join columns on demand. */
3247
3194
{
3248
3195
  Natural_join_column *nj_col;
3249
3196
 
3250
 
  DBUG_ASSERT(field_it == &natural_join_it);
 
3197
  assert(field_it == &natural_join_it);
3251
3198
  /*
3252
3199
    The field belongs to a NATURAL join, therefore the column reference was
3253
3200
    already created via one of the two constructor calls above. In this case
3254
3201
    we just return the already created column reference.
3255
3202
  */
3256
3203
  nj_col= natural_join_it.column_ref();
3257
 
  DBUG_ASSERT(nj_col &&
 
3204
  assert(nj_col &&
3258
3205
              (!nj_col->table_field ||
3259
3206
               nj_col->table_ref->table == nj_col->table_field->table));
3260
3207
  return nj_col;
3289
3236
 
3290
3237
void st_table::prepare_for_position()
3291
3238
{
3292
 
  DBUG_ENTER("st_table::prepare_for_position");
3293
3239
 
3294
3240
  if ((file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
3295
3241
      s->primary_key < MAX_KEY)
3298
3244
    /* signal change */
3299
3245
    file->column_bitmaps_signal();
3300
3246
  }
3301
 
  DBUG_VOID_RETURN;
 
3247
  return;
3302
3248
}
3303
3249
 
3304
3250
 
3315
3261
void st_table::mark_columns_used_by_index(uint index)
3316
3262
{
3317
3263
  MY_BITMAP *bitmap= &tmp_set;
3318
 
  DBUG_ENTER("st_table::mark_columns_used_by_index");
3319
3264
 
3320
3265
  (void) file->extra(HA_EXTRA_KEYREAD);
3321
3266
  bitmap_clear_all(bitmap);
3322
3267
  mark_columns_used_by_index_no_reset(index, bitmap);
3323
3268
  column_bitmaps_set(bitmap, bitmap);
3324
 
  DBUG_VOID_RETURN;
 
3269
  return;
3325
3270
}
3326
3271
 
3327
3272
 
3338
3283
 
3339
3284
void st_table::restore_column_maps_after_mark_index()
3340
3285
{
3341
 
  DBUG_ENTER("st_table::restore_column_maps_after_mark_index");
3342
3286
 
3343
3287
  key_read= 0;
3344
3288
  (void) file->extra(HA_EXTRA_NO_KEYREAD);
3345
3289
  default_column_bitmaps();
3346
3290
  file->column_bitmaps_signal();
3347
 
  DBUG_VOID_RETURN;
 
3291
  return;
3348
3292
}
3349
3293
 
3350
3294
 
3373
3317
 
3374
3318
void st_table::mark_auto_increment_column()
3375
3319
{
3376
 
  DBUG_ASSERT(found_next_number_field);
 
3320
  assert(found_next_number_field);
3377
3321
  /*
3378
3322
    We must set bit in read set as update_auto_increment() is using the
3379
3323
    store() to check overflow of auto_increment values
3456
3400
 
3457
3401
void st_table::mark_columns_needed_for_update()
3458
3402
{
3459
 
  DBUG_ENTER("mark_columns_needed_for_update");
3460
3403
  if (file->ha_table_flags() & HA_REQUIRES_KEY_COLUMNS_FOR_DELETE)
3461
3404
  {
3462
3405
    /* Mark all used key columns for read */
3486
3429
      file->column_bitmaps_signal();
3487
3430
    }
3488
3431
  }
3489
 
  DBUG_VOID_RETURN;
 
3432
  return;
3490
3433
}
3491
3434
 
3492
3435
 
3755
3698
  File file;
3756
3699
  uchar header[10];     /* This should be optimized */
3757
3700
  int error;
3758
 
  DBUG_ENTER("mysql_frm_type");
3759
3701
 
3760
3702
  *dbt= DB_TYPE_UNKNOWN;
3761
3703
 
3762
3704
  if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
3763
 
    DBUG_RETURN(FRMTYPE_ERROR);
 
3705
    return(FRMTYPE_ERROR);
3764
3706
  error= my_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP));
3765
3707
  my_close(file, MYF(MY_WME));
3766
3708
 
3767
3709
  if (error)
3768
 
    DBUG_RETURN(FRMTYPE_ERROR);
 
3710
    return(FRMTYPE_ERROR);
3769
3711
 
3770
3712
  /*  
3771
3713
    This is just a check for DB_TYPE. We'll return default unknown type
3775
3717
  if (header[0] != (uchar) 254 || header[1] != 1 ||
3776
3718
      (header[2] != FRM_VER && header[2] != FRM_VER+1 &&
3777
3719
       (header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
3778
 
    DBUG_RETURN(FRMTYPE_TABLE);
 
3720
    return(FRMTYPE_TABLE);
3779
3721
 
3780
3722
  *dbt= (enum legacy_db_type) (uint) *(header + 3);
3781
 
  DBUG_RETURN(FRMTYPE_TABLE);                   // Is probably a .frm table
 
3723
  return(FRMTYPE_TABLE);                   // Is probably a .frm table
3782
3724
}
3783
3725
 
3784
3726