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

Error when importing exported view with USE INDEX hint #18566

Closed
M393 opened this issue Jul 24, 2023 · 4 comments
Closed

Error when importing exported view with USE INDEX hint #18566

M393 opened this issue Jul 24, 2023 · 4 comments
Assignees
Labels
Bug A problem or regression with an existing feature has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete
Milestone

Comments

@M393
Copy link
Contributor

M393 commented Jul 24, 2023

Describe the bug

CREATE VIEW statements are written to the exported sql before indexes, when the view uses USE INDEX (...) import fails.

To Reproduce

CREATE SCHEMA s;
USE `s`;

CREATE TABLE `t` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `t_name` (`name`)
);
CREATE VIEW `v`  AS SELECT `t`.`id` AS `id`, `t`.`name` AS `name` FROM `t` USE INDEX (`t_name`) ;

Steps to reproduce the behavior:

  1. Execute the sql above
  2. Select the schema
  3. Click on Export tab
  4. Click on Export button
  5. Re-create schema: DROP SCHEMA s; CREATE SCHEMA s; USE s;
  6. Execute the exported script

Expected behavior

Should be able to execute exported sql without error.

Server configuration

  • Database version: MySQL 5.7.38
  • phpMyAdmin version: 5.2.1
@williamdes
Copy link
Member

williamdes commented Jul 24, 2023

Hi @M393
Thanks for reporting this parser bug!
/cc @Tithugues if you want to have a look, else no worries

@williamdes williamdes added Bug A problem or regression with an existing feature parser affects/5.2 This issue or pull-request affects 5.2.x releases (and maybe further versions) affects/6.0 This issue or pull-request affects 6.0.x releases (and maybe further versions) confirmed/5.2 This issue is confirmed to be reproduced on 5.2 at the time this label was set confirmed/6.0 This issue is confirmed to be reproduced on 6.0 at the time this label was set labels Jul 24, 2023
@williamdes
Copy link
Member

Can you provide a screenshot for this @M393?

@M393
Copy link
Contributor Author

M393 commented Jul 24, 2023

I don't think it is a parser bug.

This can be resolved by exporting indexes before views.

See the exported file:

-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Jul 24, 2023 at 05:21 PM
-- Server version: 5.7.38-log
-- PHP Version: 8.1.13

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `s`
--

-- --------------------------------------------------------

--
-- Table structure for table `t`
--

CREATE TABLE `t` (
  `id` int(11) NOT NULL,
  `name` varchar(45) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Stand-in structure for view `v`
-- (See below for the actual view)
--
CREATE TABLE `v` (
`id` int(11)
,`name` varchar(45)
);

-- --------------------------------------------------------

--
-- Structure for view `v`
--
DROP TABLE IF EXISTS `v`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v`  AS SELECT `t`.`id` AS `id`, `t`.`name` AS `name` FROM `t` USE INDEX (`t_name`) ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `t`
--
ALTER TABLE `t`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `t_name` (`name`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `t`
--
ALTER TABLE `t`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

image

@williamdes williamdes removed the parser label Jul 25, 2023
@williamdes
Copy link
Member

williamdes commented Jul 25, 2023

Thanks, I better understand the error now with your screenshot

@williamdes williamdes added has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete and removed affects/5.2 This issue or pull-request affects 5.2.x releases (and maybe further versions) affects/6.0 This issue or pull-request affects 6.0.x releases (and maybe further versions) confirmed/5.2 This issue is confirmed to be reproduced on 5.2 at the time this label was set confirmed/6.0 This issue is confirmed to be reproduced on 6.0 at the time this label was set labels Apr 28, 2024
@williamdes williamdes added this to the 5.2.2 milestone Apr 28, 2024
@williamdes williamdes self-assigned this Apr 28, 2024
williamdes added a commit that referenced this issue Apr 28, 2024
Signed-off-by: William Desportes <williamdes@wdes.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A problem or regression with an existing feature has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete
Projects
None yet
Development

No branches or pull requests

2 participants