0

I am using WordPress with MySQL and the query takes too long to respond.

https://i.ibb.co/Pzwv1Hk/image.png

I am trying to add indexes using this query

ALTER TABLE lfab_posts ADD INDEX latest_post_date ('post_status', 'post_date' DESC)

what is wrong in the syntax? This lfab_posts table already has indexes as shown in the attached picture.

https://i.stack.imgur.com/frNse.png

WeDevelop
  • 79
  • 2
  • 13
  • What happens when you try to add the index? – aynber Jul 21 '20 at 15:52
  • https://ibb.co/wyddD1B – WeDevelop Jul 21 '20 at 15:57
  • Don't quote your column names. That passes the values as strings instead of identifiers. If you need to use some sort of quote, it should be ticks, not single quotes – aynber Jul 21 '20 at 16:06
  • why u closed the question? It is not the answer to my question – WeDevelop Jul 21 '20 at 17:09
  • Did you try removing the quotes? Both a validation error checker and the error message itself say that the error starts at `'post_status'`, because the columns should not be surrounded by single quotes. They are column names, not values, so should be surrounded by ticks or not at all. – aynber Jul 21 '20 at 17:50
  • https://ibb.co/VTZdzhz it is the same. there is a syntax error in it. That's what I am asking – WeDevelop Jul 21 '20 at 18:06
  • I have visited this link but unable to figure out the mistake. How to sort it by DESC order? https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html Mysql version https://ibb.co/FspWvHM – WeDevelop Jul 21 '20 at 18:08
  • Okay, there's actually two different issues at play here, with the quotations fixed. The first is the PhpMyAdmin validator, which doesn't like the syntax but it seems to go ahead and submit the query. The second is the error that MySQL is throwing, which is that it doesn't like the default value for `post_date`. So it's no longer a syntax error, but a data error. – aynber Jul 21 '20 at 18:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218304/discussion-between-wedevelop-and-aynber). – WeDevelop Jul 21 '20 at 18:27

0 Answers0