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> <dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())"
SET @current_reference = NULL; <dtml-var sql_delimiter> 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 SELECT path, uid
FROM FROM
( (
...@@ -14,7 +21,7 @@ FROM ...@@ -14,7 +21,7 @@ FROM
@current_path:=IF(@current_reference = reference, @current_path, path) AS path, @current_path:=IF(@current_reference = reference, @current_path, path) AS path,
@current_reference:=reference AS reference @current_reference:=reference AS reference
FROM ( FROM (
SELECT DISTINCT SELECT
reference, reference,
path, path,
catalog.uid, catalog.uid,
...@@ -42,6 +49,8 @@ WHERE ...@@ -42,6 +49,8 @@ WHERE
<dtml-sqltest "getUid()" column=uid op=ne type=int> <dtml-sqltest "getUid()" column=uid op=ne type=int>
LIMIT 1000 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>
</dtml-let>
SET @current_path = NULL; <dtml-var sql_delimiter> <dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())"
SET @current_reference = NULL; <dtml-var sql_delimiter> user_language="Localizer.get_selected_language()"
optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()">
<dtml-let query="portal_catalog.buildSQLQuery(query=portal_catalog.getSecurityQuery(), portal_type=getPortalDocumentTypeList())"> <dtml-if "'derived_merge' in optimizer_switch_key_list">
<dtml-let user_language="Localizer.get_selected_language()"> 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 SELECT path, uid
FROM FROM
( (
...@@ -14,7 +20,7 @@ FROM ...@@ -14,7 +20,7 @@ FROM
@current_path:=IF(@current_reference = reference, @current_path, path) AS path, @current_path:=IF(@current_reference = reference, @current_path, path) AS path,
@current_reference:=reference AS reference @current_reference:=reference AS reference
FROM ( FROM (
SELECT DISTINCT SELECT
reference, reference,
path, path,
catalog.uid, catalog.uid,
...@@ -43,5 +49,8 @@ WHERE ...@@ -43,5 +49,8 @@ WHERE
<dtml-sqltest "getUid()" column=uid op=ne type=int> <dtml-sqltest "getUid()" column=uid op=ne type=int>
LIMIT 1000 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>
<dtml-let query="buildSQLQuery(query=portal_catalog.getSecurityQuery(**kw), **kw)" <dtml-let query="buildSQLQuery(query=portal_catalog.getSecurityQuery(**kw), **kw)"
selection_domain="kw.get('selection_domain', None)" 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> <dtml-comment>
Currently, there is no other choice to implement this method as an SQL catalog until SQLCatalog Currently, there is no other choice to implement this method as an SQL catalog until SQLCatalog
...@@ -10,11 +11,16 @@ ...@@ -10,11 +11,16 @@
The subquery is named catalog to prevent use another LEFT JOIN. The subquery is named catalog to prevent use another LEFT JOIN.
</dtml-comment> </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 SELECT
catalog.* catalog.*
FROM FROM
( (
SELECT DISTINCT SELECT
catalog.uid, catalog.uid,
catalog.path, catalog.path,
catalog.int_index, catalog.int_index,
...@@ -73,4 +79,8 @@ ...@@ -73,4 +79,8 @@
LIMIT 1000 LIMIT 1000
</dtml-if> </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>
<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>, SET @running_total_quantity := <dtml-var initial_running_total_quantity>,
@running_total_price := <dtml-var initial_running_total_price>; @running_total_price := <dtml-var initial_running_total_price>;
<dtml-var sql_delimiter> <dtml-var sql_delimiter>
...@@ -9,7 +15,7 @@ SELECT ...@@ -9,7 +15,7 @@ SELECT
@running_total_price := IFNULL(q1.total_price, 0) + @running_total_price := IFNULL(q1.total_price, 0) +
@running_total_price AS running_total_price @running_total_price AS running_total_price
FROM ( FROM (
SELECT DISTINCT SELECT
catalog.path as path, catalog.path as path,
catalog.uid as uid, catalog.uid as uid,
catalog.relative_url as relative_url, catalog.relative_url as relative_url,
...@@ -153,3 +159,8 @@ LIMIT ...@@ -153,3 +159,8 @@ LIMIT
ORDER BY ORDER BY
<dtml-var order_by_expression> <dtml-var order_by_expression>
</dtml-if> </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