Index: wp-includes/taxonomy-functions.php
===================================================================
--- wp-includes/taxonomy-functions.php	(revision 34843)
+++ wp-includes/taxonomy-functions.php	(working copy)
@@ -1411,13 +1411,13 @@
 	}
 
 	$terms = $wpdb->get_results($query);
-	if ( 'all' == $_fields ) {
+	$term_ids = wp_list_pluck( $terms, 'term_id' );
+	if ( 'all' == $_fields && !empty( $has_term_ids ) ) {
 		update_term_cache( $terms );
 	}
 
 	// Prime termmeta cache.
-	if ( $args['update_term_meta_cache'] ) {
-		$term_ids = wp_list_pluck( $terms, 'term_id' );
+	if ( $args['update_term_meta_cache'] && $term_ids ) {
 		update_termmeta_cache( $term_ids );
 	}
 
@@ -1428,7 +1428,7 @@
 		return apply_filters( 'get_terms', array(), $taxonomies, $args );
 	}
 
-	if ( $child_of ) {
+	if ( $child_of && $term_ids ) {
 		foreach ( $taxonomies as $_tax ) {
 			$children = _get_term_hierarchy( $_tax );
 			if ( ! empty( $children ) ) {
@@ -1438,7 +1438,7 @@
 	}
 
 	// Update term counts to include children.
-	if ( $args['pad_counts'] && 'all' == $_fields ) {
+	if ( $args['pad_counts'] && 'all' == $_fields && $term_ids ) {
 		foreach ( $taxonomies as $_tax ) {
 			_pad_term_counts( $terms, $_tax );
 		}
@@ -1445,7 +1445,7 @@
 	}
 
 	// Make sure we show empty categories that have children.
-	if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) {
+	if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) && $term_ids ) {
 		foreach ( $terms as $k => $term ) {
 			if ( ! $term->count ) {
 				$children = get_term_children( $term->term_id, $term->taxonomy );
@@ -1465,23 +1465,23 @@
 	}
 
 	$_terms = array();
-	if ( 'id=>parent' == $_fields ) {
+	if ( 'id=>parent' == $_fields && $term_ids ) {
 		foreach ( $terms as $term ) {
 			$_terms[ $term->term_id ] = $term->parent;
 		}
-	} elseif ( 'ids' == $_fields ) {
+	} elseif ( 'ids' == $_fields && $term_ids ) {
 		foreach ( $terms as $term ) {
 			$_terms[] = $term->term_id;
 		}
-	} elseif ( 'names' == $_fields ) {
+	} elseif ( 'names' == $_fields && !empty( wp_list_pluck( $terms, 'name' ) ) ) {
 		foreach ( $terms as $term ) {
 			$_terms[] = $term->name;
 		}
-	} elseif ( 'id=>name' == $_fields ) {
+	} elseif ( 'id=>name' == $_fields && $term_ids && !empty( wp_list_pluck( $terms, 'name' ) ) ) {
 		foreach ( $terms as $term ) {
 			$_terms[ $term->term_id ] = $term->name;
 		}
-	} elseif ( 'id=>slug' == $_fields ) {
+	} elseif ( 'id=>slug' == $_fields && $term_ids && !empty( wp_list_pluck( $terms, 'slug' ) ) ) {
 		foreach ( $terms as $term ) {
 			$_terms[ $term->term_id ] = $term->slug;
 		}
