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

Indexes are not created on Structure tab after update to 4.7.9 #14059

Closed
yura3d opened this issue Mar 6, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@yura3d
Copy link

commented Mar 6, 2018

Steps to reproduce

  1. Open a Structure tab.
  2. Click an Primary/Unique/Index link at Action column on any field row.

Expected behaviour

An index should be created.

Actual behaviour

An index is not created on 4.7.9. On 4.7.8 and below everything was fine.

Server configuration

Operating system: Debian 9.3 (4.9.0-6-amd64)

Web server: nginx/1.12.2

Database: 5.7.21-20 - Percona Server (GPL), Release '20', Revision 'ed217b06ca3'

PHP version: 7.2.3

phpMyAdmin version: 4.7.9

Client configuration

Browser: Google Chrome 64.0.3282.186 x64, Mozilla Firefox 58.0.2 x64

Operating system: Windows 10 Pro x64 (1709, build 16299.248)

@yura3d

This comment has been minimized.

Copy link
Author

commented Mar 7, 2018

Also, I see the same behaviour on the demo server (https://demo.phpmyadmin.net/master-config/), which has 4.8.0-dev installed version.

@kampalex

This comment has been minimized.

Copy link
Contributor

commented Mar 9, 2018

I also ran in this bug - trying to resolve using differences between 4.7.8 and 4.7.9.

The way requests are fired to tbl_structure.php is different. In 4.7.9, all GET values are merged into a POST request. Method getJSConfirmCommonParam (/js/functions.js) collects the arguments.

=============== 4.7.8 ==================
GET
db: (database)
table: (table)
token: (token)
goto: tbl_structure.php
back: tbl_structure.php
add_key: 1
sql_query: ALTER TABLE (table) ADD INDEX((field));
message_to_show: (Message on success)
POST
ajax_request: true
ajax_page_request: true
token: (token)
_nocache: (timestamp)

=============== 4.7.9 ==================
POST
db: (database)
table: (table)
token: (token)
goto: tbl_structure.php
back: tbl_structure.php
add_key: 1
sql_query: ALTER TABLE (table) ADD INDEX((field));
message_to_show: (Message on success)
is_js_confirmed: 1
ajax_request: true
fk_checks0:
ajax_page_request: 1
_nocache: (timestamp)

I've spotted a migration bug here:
/js/functions.js - r1856
params += 'is_js_confirmed=1&ajax_request=true&fk_checks' + ($elem.find('#fk_checks').is(':checked') ? 1 : 0);
The '=' is missing after 'fk_checks', causing 'fk_checks0' as POST name + empty value.
params += 'is_js_confirmed=1&ajax_request=true&fk_checks=' + ($elem.find('#fk_checks').is(':checked') ? 1 : 0);

Not tested yet:

  • Checks which are expecting GET (but now supplied via POST)
  • Differences of inconsistent usage of '1' / 'true'

(Added few minutes later:)
If you change destination of 'index_add' link to 'sql.php' (instead of tbl_structure.php), the index is added. I suspect an incomplete release of functionality. (Will wait for further responses.)

@kampalex

This comment has been minimized.

Copy link
Contributor

commented Mar 10, 2018

Found the issue why query wasn't executed.
POST tbl_structure.php

  • delegate to TableStructureController [r47+48]
    -> /libraries/controllers/table/TableStructureController.php
  • delegate to /sql.php [r303]
    -> /sql.php
  • code block [r71-76]: else-part should set $sql_query if $_GET['sql_query'] is set. Because it's POSTed now, variable is not set. (This part is also failing due to GET->POST switch, but I don't know which parts of PMA do supply sql_query via GET.)
  • code block [r123-133] checks for existing $sql_query. Because it's empty ('not set' evaluated to true), a simple 'SELECT * FROM (table)' query will be defined instead. This query is executed actually.

Why it did work requesting the sql.php?
I think it's about the function context. $sql_query variable was set onto $GLOBALS in r394 of common.inc.php. This variable is available in global scope.
When calling the tbl_structure.php, sql.php was included via TableStructureController::indexAction() method, in method scope. So $sql_query wasn't defined.

Fix?
Set variable $sql_query in TableStructureController.php before include 'sql.php';.
$sql_query = $GLOBALS['sql_query'];
Or replace $_GET['sql_query'] to POST of REQUEST variant in sql.php - but this situation must be tested for regressions and can break other parts of PMA. So I prefer first fix.

@yura3d

This comment has been minimized.

Copy link
Author

commented Mar 10, 2018

@kampalex, thank you! Your "first fix" resolves the problem for me.

@kampalex

This comment has been minimized.

Copy link
Contributor

commented Mar 11, 2018

According source of Github repository, this issue also exists in (tagged) RELEASE_4_8_0ALPHA1 (so yura3d is right about the demo site).
So I suggest the "first fix" on 4.7 and 4.8 branches. Also the fix for 'fk_checks' is included.

(Due to lack of experience I've made a quick diff/patch file for now. Sorry for this.)

patch-qa47-issue-14059.diff.txt

@mauriciofauth mauriciofauth self-assigned this Mar 12, 2018

@mauriciofauth mauriciofauth added this to the 4.7.10 milestone Mar 12, 2018

@ibennetch ibennetch modified the milestones: 4.7.10, 4.8.0 May 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.