SQL query takes the infinity time: function get_custom_field_names()

Hey there,

I’m working on supporting one big project and faced with the issue of calling this function get_custom_field_names(). It gathers all custom fields from the database by running this query:

$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";
	$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%' ) );

Since in the wp_postmeta table we have more than 30 millions of records the mysql server cannot complete this query. We also increased the resources, but it didn’t help us.

The first question I have, why the gravityforms plugin does not have separate database table for storing fields keys?
And the second question, is there any way to fix this issue?

Thank you in advance for your help.

Hi Viktor. We have a filter you can use to disable that query; it sounds like this may be useful in your environment:

Please let us know how it goes.

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.