We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Result of query with same column names with return different column names
Issue exists for any 'internal' tables. If query multiple columns with same name:
```
select 1 as "a", 1 as "a" from information_schema.tables limit 1;
```
then result will be:
```
+------+------+
| a    | a_2  |
+------+------+
| 1    | 1    |
+------+------+
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mindsdb/api/mysql/mysql_proxy/utilities/sql.py`
Content:
```
1 import duckdb
2 import numpy as np
3 from mindsdb_sql import parse_sql
4 from mindsdb_sql.parser.ast import Select, Identifier, BinaryOperation, OrderBy
5 from mindsdb_sql.render.sqlalchemy_render import SqlalchemyRender
6 
7 from mindsdb.utilities.log import log
8 
9 
10 def _remove_table_name(root):
11     if isinstance(root, BinaryOperation):
12         _remove_table_name(root.args[0])
13         _remove_table_name(root.args[1])
14     elif isinstance(root, Identifier):
15         root.parts = [root.parts[-1]]
16 
17 
18 def query_df(df, query):
19     """ Perform simple query ('select' from one table, without subqueries and joins) on DataFrame.
20 
21         Args:
22             df (pandas.DataFrame): data
23             query (mindsdb_sql.parser.ast.Select | str): select query
24 
25         Returns:
26             pandas.DataFrame
27     """
28 
29     if isinstance(query, str):
30         query_ast = parse_sql(query, dialect='mysql')
31     else:
32         query_ast = query
33 
34     if isinstance(query_ast, Select) is False or isinstance(query_ast.from_table, Identifier) is False:
35         raise Exception("Only 'SELECT from TABLE' statements supported for internal query")
36 
37     query_ast.from_table.parts = ['df_table']
38     for identifier in query_ast.targets:
39         if isinstance(identifier, Identifier):
40             identifier.parts = [identifier.parts[-1]]
41     if isinstance(query_ast.order_by, list):
42         for orderby in query_ast.order_by:
43             if isinstance(orderby, OrderBy) and isinstance(orderby.field, Identifier):
44                 orderby.field.parts = [orderby.field.parts[-1]]
45     _remove_table_name(query_ast.where)
46 
47     render = SqlalchemyRender('postgres')
48     try:
49         query_str = render.get_string(query_ast, with_failback=False)
50     except Exception as e:
51         log.error(f"Exception during query casting to 'postgres' dialect. Query: {str(query)}. Error: {e}")
52         query_str = render.get_string(query_ast, with_failback=True)
53 
54     res = duckdb.query_df(df, 'df_table', query_str)
55     result_df = res.df()
56     result_df = result_df.replace({np.nan: None})
57     return result_df
58
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mindsdb/api/mysql/mysql_proxy/utilities/sql.py b/mindsdb/api/mysql/mysql_proxy/utilities/sql.py
--- a/mindsdb/api/mysql/mysql_proxy/utilities/sql.py
+++ b/mindsdb/api/mysql/mysql_proxy/utilities/sql.py
@@ -54,4 +54,13 @@
     res = duckdb.query_df(df, 'df_table', query_str)
     result_df = res.df()
     result_df = result_df.replace({np.nan: None})
+
+    new_column_names = {}
+    real_column_names = [x[0] for x in res.description()]
+    for i, duck_column_name in enumerate(result_df.columns):
+        new_column_names[duck_column_name] = real_column_names[i]
+    result_df = result_df.rename(
+        new_column_names,
+        axis='columns'
+    )
     return result_df

{"golden_diff": "diff --git a/mindsdb/api/mysql/mysql_proxy/utilities/sql.py b/mindsdb/api/mysql/mysql_proxy/utilities/sql.py\n--- a/mindsdb/api/mysql/mysql_proxy/utilities/sql.py\n+++ b/mindsdb/api/mysql/mysql_proxy/utilities/sql.py\n@@ -54,4 +54,13 @@\n     res = duckdb.query_df(df, 'df_table', query_str)\n     result_df = res.df()\n     result_df = result_df.replace({np.nan: None})\n+\n+    new_column_names = {}\n+    real_column_names = [x[0] for x in res.description()]\n+    for i, duck_column_name in enumerate(result_df.columns):\n+        new_column_names[duck_column_name] = real_column_names[i]\n+    result_df = result_df.rename(\n+        new_column_names,\n+        axis='columns'\n+    )\n     return result_df\n", "issue": "Result of query with same column names with return different column names\nIssue exists for any 'internal' tables. If query multiple columns with same name:\r\n```\r\nselect 1 as \"a\", 1 as \"a\" from information_schema.tables limit 1;\r\n```\r\nthen result will be:\r\n```\r\n+------+------+\r\n| a    | a_2  |\r\n+------+------+\r\n| 1    | 1    |\r\n+------+------+\r\n```\n", "before_files": [{"content": "import duckdb\nimport numpy as np\nfrom mindsdb_sql import parse_sql\nfrom mindsdb_sql.parser.ast import Select, Identifier, BinaryOperation, OrderBy\nfrom mindsdb_sql.render.sqlalchemy_render import SqlalchemyRender\n\nfrom mindsdb.utilities.log import log\n\n\ndef _remove_table_name(root):\n    if isinstance(root, BinaryOperation):\n        _remove_table_name(root.args[0])\n        _remove_table_name(root.args[1])\n    elif isinstance(root, Identifier):\n        root.parts = [root.parts[-1]]\n\n\ndef query_df(df, query):\n    \"\"\" Perform simple query ('select' from one table, without subqueries and joins) on DataFrame.\n\n        Args:\n            df (pandas.DataFrame): data\n            query (mindsdb_sql.parser.ast.Select | str): select query\n\n        Returns:\n            pandas.DataFrame\n    \"\"\"\n\n    if isinstance(query, str):\n        query_ast = parse_sql(query, dialect='mysql')\n    else:\n        query_ast = query\n\n    if isinstance(query_ast, Select) is False or isinstance(query_ast.from_table, Identifier) is False:\n        raise Exception(\"Only 'SELECT from TABLE' statements supported for internal query\")\n\n    query_ast.from_table.parts = ['df_table']\n    for identifier in query_ast.targets:\n        if isinstance(identifier, Identifier):\n            identifier.parts = [identifier.parts[-1]]\n    if isinstance(query_ast.order_by, list):\n        for orderby in query_ast.order_by:\n            if isinstance(orderby, OrderBy) and isinstance(orderby.field, Identifier):\n                orderby.field.parts = [orderby.field.parts[-1]]\n    _remove_table_name(query_ast.where)\n\n    render = SqlalchemyRender('postgres')\n    try:\n        query_str = render.get_string(query_ast, with_failback=False)\n    except Exception as e:\n        log.error(f\"Exception during query casting to 'postgres' dialect. Query: {str(query)}. Error: {e}\")\n        query_str = render.get_string(query_ast, with_failback=True)\n\n    res = duckdb.query_df(df, 'df_table', query_str)\n    result_df = res.df()\n    result_df = result_df.replace({np.nan: None})\n    return result_df\n", "path": "mindsdb/api/mysql/mysql_proxy/utilities/sql.py"}], "after_files": [{"content": "import duckdb\nimport numpy as np\nfrom mindsdb_sql import parse_sql\nfrom mindsdb_sql.parser.ast import Select, Identifier, BinaryOperation, OrderBy\nfrom mindsdb_sql.render.sqlalchemy_render import SqlalchemyRender\n\nfrom mindsdb.utilities.log import log\n\n\ndef _remove_table_name(root):\n    if isinstance(root, BinaryOperation):\n        _remove_table_name(root.args[0])\n        _remove_table_name(root.args[1])\n    elif isinstance(root, Identifier):\n        root.parts = [root.parts[-1]]\n\n\ndef query_df(df, query):\n    \"\"\" Perform simple query ('select' from one table, without subqueries and joins) on DataFrame.\n\n        Args:\n            df (pandas.DataFrame): data\n            query (mindsdb_sql.parser.ast.Select | str): select query\n\n        Returns:\n            pandas.DataFrame\n    \"\"\"\n\n    if isinstance(query, str):\n        query_ast = parse_sql(query, dialect='mysql')\n    else:\n        query_ast = query\n\n    if isinstance(query_ast, Select) is False or isinstance(query_ast.from_table, Identifier) is False:\n        raise Exception(\"Only 'SELECT from TABLE' statements supported for internal query\")\n\n    query_ast.from_table.parts = ['df_table']\n    for identifier in query_ast.targets:\n        if isinstance(identifier, Identifier):\n            identifier.parts = [identifier.parts[-1]]\n    if isinstance(query_ast.order_by, list):\n        for orderby in query_ast.order_by:\n            if isinstance(orderby, OrderBy) and isinstance(orderby.field, Identifier):\n                orderby.field.parts = [orderby.field.parts[-1]]\n    _remove_table_name(query_ast.where)\n\n    render = SqlalchemyRender('postgres')\n    try:\n        query_str = render.get_string(query_ast, with_failback=False)\n    except Exception as e:\n        log.error(f\"Exception during query casting to 'postgres' dialect. Query: {str(query)}. Error: {e}\")\n        query_str = render.get_string(query_ast, with_failback=True)\n\n    res = duckdb.query_df(df, 'df_table', query_str)\n    result_df = res.df()\n    result_df = result_df.replace({np.nan: None})\n\n    new_column_names = {}\n    real_column_names = [x[0] for x in res.description()]\n    for i, duck_column_name in enumerate(result_df.columns):\n        new_column_names[duck_column_name] = real_column_names[i]\n    result_df = result_df.rename(\n        new_column_names,\n        axis='columns'\n    )\n    return result_df\n", "path": "mindsdb/api/mysql/mysql_proxy/utilities/sql.py"}]}