~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/myisam/mi_delete_all.c

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (c) 2000, 2011, Oracle and/or its affiliates
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; version 2 of the License.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
16
 
 
17
/* Remove all rows from a MyISAM table */
 
18
/* This clears the status information and truncates files */
 
19
 
 
20
#include "myisamdef.h"
 
21
 
 
22
int mi_delete_all_rows(MI_INFO *info)
 
23
{
 
24
  uint i;
 
25
  MYISAM_SHARE *share=info->s;
 
26
  MI_STATE_INFO *state=&share->state;
 
27
  DBUG_ENTER("mi_delete_all_rows");
 
28
 
 
29
  if (share->options & HA_OPTION_READ_ONLY_DATA)
 
30
  {
 
31
    DBUG_RETURN(my_errno=EACCES);
 
32
  }
 
33
  if (_mi_readinfo(info,F_WRLCK,1))
 
34
    DBUG_RETURN(my_errno);
 
35
  if (_mi_mark_file_changed(info))
 
36
    goto err;
 
37
 
 
38
  info->state->records=info->state->del=state->split=0;
 
39
  state->dellink = HA_OFFSET_ERROR;
 
40
  state->sortkey=  (ushort) ~0;
 
41
  info->state->key_file_length=share->base.keystart;
 
42
  info->state->data_file_length=0;
 
43
  info->state->empty=info->state->key_empty=0;
 
44
  info->state->checksum=0;
 
45
 
 
46
  for (i=share->base.max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH ; i-- ; )
 
47
    state->key_del[i]= HA_OFFSET_ERROR;
 
48
  for (i=0 ; i < share->base.keys ; i++)
 
49
    state->key_root[i]= HA_OFFSET_ERROR;
 
50
 
 
51
  myisam_log_command(MI_LOG_DELETE_ALL,info,(uchar*) 0,0,0);
 
52
  /*
 
53
    If we are using delayed keys or if the user has done changes to the tables
 
54
    since it was locked then there may be key blocks in the key cache
 
55
  */
 
56
  flush_key_blocks(share->key_cache, share->kfile, &share->dirty_part_map,
 
57
                   FLUSH_IGNORE_CHANGED);
 
58
#ifdef HAVE_MMAP
 
59
  if (share->file_map)
 
60
    mi_munmap_file(info);
 
61
#endif
 
62
  if (mysql_file_chsize(info->dfile, 0, 0, MYF(MY_WME)) ||
 
63
      mysql_file_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)))
 
64
    goto err;
 
65
  (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
66
  DBUG_RETURN(0);
 
67
 
 
68
err:
 
69
  {
 
70
    int save_errno=my_errno;
 
71
    (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
 
72
    info->update|=HA_STATE_WRITTEN;     /* Buffer changed */
 
73
    DBUG_RETURN(my_errno=save_errno);
 
74
  }
 
75
} /* mi_delete */