Commit 44e25a1c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

disable derived_merge in a query where it may cause the wrong result, instead...

disable derived_merge in a query where it may cause the wrong result, instead of using DISTINCT trick.
parent 646ef35a
SET @current_path = NULL; <dtml-var sql_delimiter>
SET @current_reference = NULL; <dtml-var sql_delimiter>
<dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())"
user_language="Localizer.get_selected_language()"
optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()">
<dtml-if "'derived_merge' in optimizer_switch_key_list">
SET @current_optimizer_switch = @@optimizer_switch,
@@optimizer_switch = 'derived_merge=off'
<dtml-var sql_delimiter>
</dtml-if>
SET @current_path = NULL,
@current_reference = NULL
<dtml-var sql_delimiter>
<dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())">
<dtml-let user_language="Localizer.get_selected_language()">
SELECT path, uid
FROM
(
......@@ -14,7 +21,7 @@ FROM
@current_path:=IF(@current_reference = reference, @current_path, path) AS path,
@current_reference:=reference AS reference
FROM (
SELECT DISTINCT
SELECT
reference,
path,
catalog.uid,
......@@ -42,6 +49,8 @@ WHERE
<dtml-sqltest "getUid()" column=uid op=ne type=int>
LIMIT 1000
<dtml-if "'derived_merge' in optimizer_switch_key_list">
<dtml-var sql_delimiter>
SET @@optimizer_switch = @current_optimizer_switch
</dtml-if>
</dtml-let>
</dtml-let>
SET @current_path = NULL; <dtml-var sql_delimiter>
SET @current_reference = NULL; <dtml-var sql_delimiter>
<dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())">
<dtml-let user_language="Localizer.get_selected_language()">
<dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())"
user_language="Localizer.get_selected_language()"
optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()">
<dtml-if "'derived_merge' in optimizer_switch_key_list">
SET @current_optimizer_switch = @@optimizer_switch,
@@optimizer_switch = 'derived_merge=off'
<dtml-var sql_delimiter>
</dtml-if>
SET @current_path = NULL,
@current_reference = NULL
<dtml-var sql_delimiter>
SELECT path, uid
FROM
(
......@@ -14,7 +20,7 @@ FROM
@current_path:=IF(@current_reference = reference, @current_path, path) AS path,
@current_reference:=reference AS reference
FROM (
SELECT DISTINCT
SELECT
reference,
path,
catalog.uid,
......@@ -43,5 +49,8 @@ WHERE
<dtml-sqltest "getUid()" column=uid op=ne type=int>
LIMIT 1000
</dtml-let>
<dtml-if "'derived_merge' in optimizer_switch_key_list">
<dtml-var sql_delimiter>
SET @@optimizer_switch = @current_optimizer_switch
</dtml-if>
</dtml-let>
<dtml-let query="buildSQLQuery(query=portal_catalog.getSecurityQuery(**kw), **kw)"
selection_domain="kw.get('selection_domain', None)"
selection_report="kw.get('selection_report', None)">
selection_report="kw.get('selection_report', None)"
optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()">
<dtml-comment>
Currently, there is no other choice to implement this method as an SQL catalog until SQLCatalog
......@@ -10,11 +11,16 @@
The subquery is named catalog to prevent use another LEFT JOIN.
</dtml-comment>
<dtml-if "'derived_merge' in optimizer_switch_key_list">
SET @current_optimizer_switch = @@optimizer_switch,
@@optimizer_switch = 'derived_merge=off'
<dtml-var sql_delimiter>
</dtml-if>
SELECT
catalog.*
FROM
(
SELECT DISTINCT
SELECT
catalog.uid,
catalog.path,
catalog.int_index,
......@@ -73,4 +79,8 @@
LIMIT 1000
</dtml-if>
<dtml-if "'derived_merge' in optimizer_switch_key_list">
<dtml-var sql_delimiter>
SET @@optimizer_switch = @current_optimizer_switch
</dtml-if>
</dtml-let>
<dtml-let optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()">
<dtml-if "'derived_merge' in optimizer_switch_key_list">
SET @current_optimizer_switch = @@optimizer_switch,
@@optimizer_switch = 'derived_merge=off'
<dtml-var sql_delimiter>
</dtml-if>
SET @running_total_quantity := <dtml-var initial_running_total_quantity>,
@running_total_price := <dtml-var initial_running_total_price>;
<dtml-var sql_delimiter>
......@@ -9,7 +15,7 @@ SELECT
@running_total_price := IFNULL(q1.total_price, 0) +
@running_total_price AS running_total_price
FROM (
SELECT DISTINCT
SELECT
catalog.path as path,
catalog.uid as uid,
catalog.relative_url as relative_url,
......@@ -153,3 +159,8 @@ LIMIT
ORDER BY
<dtml-var order_by_expression>
</dtml-if>
<dtml-if "'derived_merge' in optimizer_switch_key_list">
<dtml-var sql_delimiter>
SET @@optimizer_switch = @current_optimizer_switch
</dtml-if>
</dtml-let>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment