Index: src/wp-admin/includes/template.php
===================================================================
--- src/wp-admin/includes/template.php	(revision 33453)
+++ src/wp-admin/includes/template.php	(working copy)
@@ -666,8 +666,7 @@
  */
 function meta_form( $post = null ) {
 	global $wpdb;
-	$post = get_post( $post );
-
+	$post = get_post( $post );	
 	/**
 	 * Filter the number of custom fields to retrieve for the drop-down
 	 * in the Custom Fields meta box.
@@ -677,13 +676,26 @@
 	 * @param int $limit Number of custom fields to retrieve. Default 30.
 	 */
 	$limit = apply_filters( 'postmeta_form_limit', 30 );
-	$sql = "SELECT DISTINCT meta_key
-		FROM $wpdb->postmeta
-		WHERE meta_key NOT BETWEEN '_' AND '_z'
-		HAVING meta_key NOT LIKE %s
-		ORDER BY meta_key
-		LIMIT %d";
-	$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
+
+	if ( $post instanceof WP_Post && isset( $post->ID ) && is_int( $post->ID ) && $post->ID > 0 ){
+		$post_id = (int) $post->ID;
+		$sql = "SELECT DISTINCT meta_key
+			FROM $wpdb->postmeta
+			WHERE post_id = %d AND meta_key NOT BETWEEN '_' AND '_z'
+			HAVING meta_key NOT LIKE %s
+			LIMIT %d";
+		
+		$keys = $wpdb->get_col( $wpdb->prepare( $sql, $post_id, $wpdb->esc_like( '_' ) . '%', $limit ) );
+	} else {
+		$sql = "SELECT DISTINCT meta_key
+			FROM $wpdb->postmeta
+			WHERE meta_key NOT BETWEEN '_' AND '_z'
+			HAVING meta_key NOT LIKE %s
+			LIMIT %d";
+
+		$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
+	}
+
 	if ( $keys ) {
 		natcasesort( $keys );
 		$meta_key_input_id = 'metakeyselect';
