Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SQL_CALC_FOUND_ROWS #1200

Closed
nprasath002 opened this issue Nov 23, 2020 · 0 comments · Fixed by #1203
Closed

Remove SQL_CALC_FOUND_ROWS #1200

nprasath002 opened this issue Nov 23, 2020 · 0 comments · Fixed by #1203

Comments

@nprasath002
Copy link

nprasath002 commented Nov 23, 2020

SQL_CALC_FOUND_ROWS is depcreated from MySQL

The SQL_CALC_FOUND_ROWS query modifier and accompanying FOUND_ROWS() function are deprecated as of MySQL 8.0.17 and will be removed in a future MySQL version

See https://dev.mysql.com/worklog/task/?id=12615

We need to modify Query::query() function to remove SQL_CALC_FOUND_ROWS and use COUNT (*) to get the total number of rows

		/**
		 * BUILD THE FINAL QUERY
		 */
		$query = "SELECT SQL_CALC_FOUND_ROWS {$select}
		FROM $wpdb->stream
		{$join}
		WHERE 1=1 {$where}
		{$orderby}
		{$limits}";

		/**
		 * Filter allows the final query to be modified before execution
		 *
		 * @param string $query
		 * @param array  $args
		 *
		 * @return string
		 */
		$query = apply_filters( 'wp_stream_db_query', $query, $args );

		$result = array();
		/**
		 * QUERY THE DATABASE FOR RESULTS
		 */
		$result['items'] = $wpdb->get_results( $query ); // @codingStandardsIgnoreLine $query already prepared
		$result['count'] = $result['items'] ? absint( $wpdb->get_var( 'SELECT FOUND_ROWS()' ) ) : 0;

		return $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant