~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_open.cc

  • Committer: Patrick Crews
  • Date: 2010-08-09 16:31:29 UTC
  • mto: (1711.1.21 build)
  • mto: This revision was merged to the branch mainline in revision 1714.
  • Revision ID: gleebix@gmail.com-20100809163129-jh0jlwejpuefjrok
Updated test results with changes due to optimizer bug fix.  EXPLAIN output now includes 'Using where' for several queries that didn't previously have this output

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* open a isam-database */
17
17
 
19
19
 
20
20
#include <string.h>
21
21
#include <algorithm>
22
 
#include <memory>
23
 
#include <boost/scoped_ptr.hpp>
24
 
#include <boost/scoped_array.hpp>
25
22
 
26
23
#include "drizzled/charset_info.h"
27
24
#include "drizzled/internal/m_string.h"
79
76
  have an open count of 0.
80
77
******************************************************************************/
81
78
 
82
 
MI_INFO *mi_open(const drizzled::TableIdentifier &identifier, int mode, uint32_t open_flags)
 
79
MI_INFO *mi_open(const char *name, int mode, uint32_t open_flags)
83
80
{
84
81
  int lock_error,kfile,open_mode,save_errno,have_rtree=0;
85
82
  uint32_t i,j,len,errpos,head_length,base_pos,offset,info_length,keys,
89
86
  unsigned char *disk_cache= NULL;
90
87
  unsigned char *disk_pos, *end_pos;
91
88
  MI_INFO info,*m_info,*old_info;
92
 
  boost::scoped_ptr<MYISAM_SHARE> share_buff_ap(new MYISAM_SHARE);
93
 
  MYISAM_SHARE &share_buff= *share_buff_ap.get();
94
 
  MYISAM_SHARE *share;
95
 
  boost::scoped_array<ulong> rec_per_key_part_ap(new ulong[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG]);
96
 
  ulong *rec_per_key_part= rec_per_key_part_ap.get();
 
89
  MYISAM_SHARE share_buff,*share;
 
90
  ulong rec_per_key_part[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG];
97
91
  internal::my_off_t key_root[HA_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE];
98
92
  uint64_t max_key_file_length, max_data_file_length;
99
93
 
103
97
  head_length=sizeof(share_buff.state.header);
104
98
  memset(&info, 0, sizeof(info));
105
99
 
106
 
  (void)internal::fn_format(org_name,
107
 
                            identifier.getPath().c_str(), 
108
 
                            "",
109
 
                            MI_NAME_IEXT,
110
 
                            MY_UNPACK_FILENAME);
 
100
  (void)internal::fn_format(org_name,name,"",MI_NAME_IEXT, MY_UNPACK_FILENAME);
111
101
  if (!realpath(org_name,rp_buff))
112
102
    internal::my_load_path(rp_buff,org_name, NULL);
113
103
  rp_buff[FN_REFLEN-1]= '\0';
114
104
  strcpy(name_buff,rp_buff);
115
 
  THR_LOCK_myisam.lock();
 
105
  pthread_mutex_lock(&THR_LOCK_myisam);
116
106
  if (!(old_info=test_if_reopen(name_buff)))
117
107
  {
118
108
    share= &share_buff;
120
110
    share_buff.state.rec_per_key_part=rec_per_key_part;
121
111
    share_buff.state.key_root=key_root;
122
112
    share_buff.state.key_del=key_del;
123
 
    share_buff.setKeyCache();
 
113
    share_buff.key_cache= dflt_key_cache;
124
114
 
125
115
    if ((kfile=internal::my_open(name_buff,(open_mode=O_RDWR),MYF(0))) < 0)
126
116
    {
143
133
      goto err;
144
134
    }
145
135
    share->options= mi_uint2korr(share->state.header.options);
146
 
    static const uint64_t OLD_FILE_OPTIONS= HA_OPTION_PACK_RECORD |
147
 
            HA_OPTION_PACK_KEYS |
148
 
            HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA |
149
 
            HA_OPTION_TEMP_COMPRESS_RECORD |
150
 
            HA_OPTION_TMP_TABLE;
151
 
    if (share->options & ~OLD_FILE_OPTIONS)
 
136
    if (share->options &
 
137
        ~(HA_OPTION_PACK_RECORD | HA_OPTION_PACK_KEYS |
 
138
          HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA |
 
139
          HA_OPTION_TEMP_COMPRESS_RECORD |
 
140
          HA_OPTION_TMP_TABLE
 
141
          ))
152
142
    {
153
143
      errno=HA_ERR_OLD_FILE;
154
144
      goto err;
257
247
           &share->state.key_root,keys*sizeof(uint64_t),
258
248
           &share->state.key_del,
259
249
           (share->state.header.max_block_size_index*sizeof(uint64_t)),
 
250
           &share->key_root_lock,sizeof(pthread_rwlock_t)*keys,
 
251
           &share->mmap_lock,sizeof(pthread_rwlock_t),
260
252
           NULL))
261
253
      goto err;
262
254
    errpos=4;
397
389
    disk_cache= NULL;
398
390
    mi_setup_functions(share);
399
391
    share->is_log_table= false;
 
392
    thr_lock_init(&share->lock);
 
393
    pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST);
 
394
    for (i=0; i<keys; i++)
 
395
      pthread_rwlock_init(&share->key_root_lock[i], NULL);
 
396
    pthread_rwlock_init(&share->mmap_lock, NULL);
400
397
    if (myisam_concurrent_insert)
401
398
    {
402
399
      share->concurrent_insert=
432
429
                     share->base.max_key_length),
433
430
         &info.lastkey,share->base.max_key_length*3+1,
434
431
         &info.first_mbr_key, share->base.max_key_length,
435
 
         &info.filename, identifier.getPath().length()+1,
 
432
         &info.filename,strlen(name)+1,
436
433
         &info.rtree_recursion_state,have_rtree ? 1024 : 0,
437
434
         NULL))
438
435
    goto err;
441
438
  if (!have_rtree)
442
439
    info.rtree_recursion_state= NULL;
443
440
 
444
 
  strcpy(info.filename, identifier.getPath().c_str());
 
441
  strcpy(info.filename,name);
445
442
  memcpy(info.blobs,share->blobs,sizeof(MI_BLOB)*share->base.blobs);
446
443
  info.lastkey2=info.lastkey+share->base.max_key_length;
447
444
 
462
459
  info.bulk_insert=0;
463
460
  info.errkey= -1;
464
461
  info.page_changed=1;
 
462
  pthread_mutex_lock(&share->intern_lock);
465
463
  info.read_record=share->read_record;
466
464
  share->reopen++;
467
465
  share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL);
491
489
 
492
490
  share->delay_key_write= 1;
493
491
  info.state= &share->state.state;      /* Change global values by default */
 
492
  pthread_mutex_unlock(&share->intern_lock);
494
493
 
495
494
  /* Allocate buffer for one record */
496
495
 
497
496
  /* prerequisites: memset(info, 0) && info->s=share; are met. */
498
 
  if (!mi_alloc_rec_buff(&info, SIZE_MAX, &info.rec_buff))
 
497
  if (!mi_alloc_rec_buff(&info, -1, &info.rec_buff))
499
498
    goto err;
500
499
  memset(info.rec_buff, 0, mi_get_rec_buff_len(&info, info.rec_buff));
501
500
 
502
501
  *m_info=info;
 
502
  thr_lock_data_init(&share->lock,&m_info->lock,(void*) m_info);
503
503
  myisam_open_list.push_front(m_info);
504
504
 
505
 
  THR_LOCK_myisam.unlock();
 
505
  pthread_mutex_unlock(&THR_LOCK_myisam);
506
506
  return(m_info);
507
507
 
508
508
err:
512
512
  if ((save_errno == HA_ERR_CRASHED) ||
513
513
      (save_errno == HA_ERR_CRASHED_ON_USAGE) ||
514
514
      (save_errno == HA_ERR_CRASHED_ON_REPAIR))
515
 
    mi_report_error(save_errno, identifier.getPath().c_str());
 
515
    mi_report_error(save_errno, name);
516
516
  switch (errpos) {
517
517
  case 6:
518
518
    free((unsigned char*) m_info);
534
534
  default:
535
535
    break;
536
536
  }
537
 
  THR_LOCK_myisam.unlock();
 
537
  pthread_mutex_unlock(&THR_LOCK_myisam);
538
538
  errno=save_errno;
539
539
  return (NULL);
540
540
} /* mi_open */
550
550
    unsigned char *newptr = *buf;
551
551
 
552
552
    /* to simplify initial init of info->rec_buf in mi_open and mi_extra */
553
 
    if (length == SIZE_MAX)
 
553
    if (length == (ulong) -1)
554
554
    {
555
555
      if (info->s->options & HA_OPTION_COMPRESS_RECORD)
556
556
        length= max(info->s->base.pack_reclength, info->s->max_pack_length);