Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#54769 closed enhancement (fixed)

INNER JOIN missing "AS" in /wp-includes/link-template.php

Reported by: domainsupport Owned by: SergeyBiryukov
Priority: normal Milestone: 6.0
Component: Database Version:
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

Line 1833 of /wp-includes/link-template.php reads ...

<?php
                                $join  .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";

... but I believe it should read ...

<?php
                                $join  .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";

It appears to be missing an "AS" after the second INNER JOIN.

Oliver

Attachments (1)

54769.diff (2.0 KB ) - added by costdev 5 years ago.
Add missing AS keywords to src/wp-includes/link-template.php and src/wp-includes/taxonomy.php.

Download all attachments as: .zip

Change History (5)

#1 @costdev
5 years ago

  • Milestone Awaiting Review6.0
  • Type defect (bug)enhancement

@domainsupport thanks for opening this ticket.

While AS is an optional keyword in SQL, meaning that this isn't a defect (bug), it is commonly considered best practice to include the AS keyword for better readability and compatibility.

To my knowledge, this doesn't fall under any of the official coding standards in WordPress, but this query and almost every other INNER JOIN that uses aliases in Core includes the AS keyword - the one other exception I could find was in src/wp-includes/taxonomy.php:2536.

For the reason(s) above as well as consistency in Core, I think we should add the AS keyword in both of these files.

Milestoning this for 6.0 and marking as an enhancement.

Last edited 5 years ago by costdev (previous) (diff)

@costdev
5 years ago

Add missing AS keywords to src/wp-includes/link-template.php and src/wp-includes/taxonomy.php.

#2 @costdev
5 years ago

  • Keywords has-patch added

#3 @johnbillion
5 years ago

  • Version trunk

#4 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolutionfixed
  • Status newclosed

In 52553:

Database: Add missing AS after INNER JOIN in some queries.

While AS is an optional keyword in SQL, it is commonly considered best practice to include it for better readability and compatibility. This also makes the queries more consistent with other queries using aliases in core.

Follow-up to [6359], [30238].

Props costdev, domainsupport.
Fixes #54769.

Note: See TracTickets for help on using tickets.