Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 48462)
+++ wp-includes/link-template.php	(working copy)
@@ -1854,7 +1854,21 @@
 	 */
 	$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );
 
-	$query     = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
+	$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
+
+	/**
+	 * Filters the final SQL for an adjacent post query.
+	 *
+	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
+	 * of adjacency, 'next' or 'previous'.
+	 *
+	 * @since 5.6.0
+	 *
+	 * @param string  $query The final SQL.
+	 * @param WP_Post $post  WP_Post object.
+	 */
+	$query = apply_filters( "get_{$adjacent}_post_query", $query, $post );
+
 	$query_key = 'adjacent_post_' . md5( $query );
 	$result    = wp_cache_get( $query_key, 'counts' );
 	if ( false !== $result ) {
