Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 20426)
+++ wp-includes/post.php	(working copy)
@@ -2034,20 +2034,12 @@
 	$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
 
 	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
-	if ( ! empty($comment_ids) ) {
-		do_action( 'delete_comment', $comment_ids );
-		foreach ( $comment_ids as $comment_id )
-			wp_delete_comment( $comment_id, true );
-		do_action( 'deleted_comment', $comment_ids );
-	}
+	foreach ( $comment_ids as $comment_id )
+		wp_delete_comment( $comment_id, true );
 
 	$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
-	if ( !empty($post_meta_ids) ) {
-		do_action( 'delete_postmeta', $post_meta_ids );
-		$in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
-		$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
-		do_action( 'deleted_postmeta', $post_meta_ids );
-	}
+	foreach ( $post_meta_ids as $mid )
+		delete_metadata_by_id( 'post', $mid );
 
 	do_action( 'delete_post', $postid );
 	$wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
@@ -3800,23 +3792,15 @@
 	wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
 	wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
 
-	$wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_thumbnail_id' , 'meta_value' => $post_id ) );
+	delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); // delete all for any posts.
 
 	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
-	if ( ! empty( $comment_ids ) ) {
-		do_action( 'delete_comment', $comment_ids );
-		foreach ( $comment_ids as $comment_id )
-			wp_delete_comment( $comment_id, true );
-		do_action( 'deleted_comment', $comment_ids );
-	}
+	foreach ( $comment_ids as $comment_id )
+		wp_delete_comment( $comment_id, true );
 
 	$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
-	if ( !empty($post_meta_ids) ) {
-		do_action( 'delete_postmeta', $post_meta_ids );
-		$in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
-		$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
-		do_action( 'deleted_postmeta', $post_meta_ids );
-	}
+	foreach ( $post_meta_ids as $mid )
+		delete_metadata_by_id( 'post', $mid );
 
 	do_action( 'delete_post', $post_id );
 	$wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
@@ -4564,12 +4548,9 @@
 		return;
 
 	$data = array( 'post_id' => $post_id, 'meta_value' => '1' );
-	if ( get_option('default_pingback_flag') ) {
-		$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
-		do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 );
-	}
-	$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );
-	do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 );
+	if ( get_option('default_pingback_flag') )
+		add_post_meta( $post_id, '_pingme', '1' );
+	add_post_meta( $post_id, '_encloseme', '1' );
 
 	wp_schedule_single_event(time(), 'do_pings');
 }
Index: wp-includes/comment.php
===================================================================
--- wp-includes/comment.php	(revision 20426)
+++ wp-includes/comment.php	(working copy)
@@ -980,13 +980,9 @@
 	}
 
 	// Delete metadata
-	$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) );
-	if ( !empty($meta_ids) ) {
-		do_action( 'delete_commentmeta', $meta_ids );
-		$in_meta_ids = "'" . implode("', '", $meta_ids) . "'";
-		$wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" );
-		do_action( 'deleted_commentmeta', $meta_ids );
-	}
+	$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
+	foreach ( $meta_ids as $mid )
+		delete_metadata_by_id( 'comment', $mid );
 
 	if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
 		return false;
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 20426)
+++ wp-includes/functions.php	(working copy)
@@ -426,10 +426,9 @@
 
 	foreach ( $pung as $link_test ) {
 		if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
-			$mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
-			do_action( 'delete_postmeta', $mid );
-			$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
-			do_action( 'deleted_postmeta', $mid );
+			$mids = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
+			foreach ( $mids as $mid )
+				delete_metadata_by_mid( 'post', $mid );
 		}
 	}
 
@@ -469,9 +468,7 @@
 				}
 
 				if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
-					$meta_value = "$url\n$len\n$type\n";
-					$wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
-					do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
+					add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
 				}
 			}
 		}
Index: wp-includes/meta.php
===================================================================
--- wp-includes/meta.php	(revision 20426)
+++ wp-includes/meta.php	(working copy)
@@ -223,6 +223,7 @@
 
 	do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
 
+	// Old-style action.
 	if ( 'post' == $meta_type )
 		do_action( 'delete_postmeta', $meta_ids );
 
@@ -243,6 +244,7 @@
 
 	do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
 
+	// Old-style action.
 	if ( 'post' == $meta_type )
 		do_action( 'deleted_postmeta', $meta_ids );
 
@@ -485,8 +487,9 @@
 
 		do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
 
-		if ( 'post' == $meta_type )
-			do_action( 'delete_postmeta', $meta_id );
+		// Old-style action.
+		if ( 'post' == $meta_type || 'comment' == $meta_type )
+			do_action( "delete_{$meta_type}meta", $meta_id );
 
 		// Run the query, will return true if deleted, false otherwise
 		$result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) );
@@ -496,8 +499,9 @@
 
 		do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
 
-		if ( 'post' == $meta_type )
-			do_action( 'deleted_postmeta', $meta_id );
+		// Old-style action.
+		if ( 'post' == $meta_type || 'comment' == $meta_type )
+			do_action( "deleted_{$meta_type}meta", $meta_id );
 
 		return $result;
 
