[Enhance] add a rewrite rule of compoundPredicate 'OR' 'AND'
See original GitHub issueHere is a simplified SQL in the meituan,data is over than 600w rows:
select
shop_id,sum(view_shop_pv) as view_shop_pv
from rpt_ad_shop_view_overall_rank
where partition_date between '2020-08-12' and '2021-08-12'
and (-2 = 2 or city_id = 2)
and (-2 = 14 or district_id = 14)
and (-2 = 23006 or region_id = 23006)
and (-2 = 35 or cat0_id = 35)
and (-2 = 50025 or cat1_id = 50025)
and (-2 = 3 or star_range = 3)
group by shop_id
order by view_shop_pv desc
limit 100
This SQL will exceed limit time(over 20s),we find ‘-2=14’ is obvious false,But if you rewrite the SQL as:
select
shop_id,sum(view_shop_pv) as view_shop_pv
from rpt_ad_shop_view_overall_rank
where partition_date between '2020-08-12' and '2021-08-12'
and (city_id = 2)
and (district_id = 14)
and (region_id = 23006)
and (cat0_id = 35)
and (cat1_id = 50025)
and (star_range = 3)
group by shop_id
order by view_shop_pv desc
limit 100
it only costs 2s.
we explain a test SQL and find:
explain select * from table1 where (2=-2) OR (citycode=0 AND 1=1);
#PREDICATES: (FALSE OR (`citycode` = 0 AND TRUE))
compoundPredicate ‘OR’ will cause the invalidation of the prefix index,which will lead to the exceed time of SQL.
so i am trying to rewrite the compoundpredicate rule, after optimized rewrite rule,prefix index will work again.
explain select * from table1 where (2=-2) OR (citycode=0 AND 1=1);
#PREDICATES: `citycode` = 0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Creating Outbound Rules for URL Rewrite Module
Adding an Inbound Rewrite Rule. The next step is to add a rule that rewrites URLs that have the following format: Console Copy....
Read more >mod_rewrite - Apache HTTP Server Version 2.4
The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly.
Read more >How to Rewrite URLs with mod_rewrite for Apache on Ubuntu ...
Apache's mod_rewrite module lets you rewrite URLs more cleanly, translating human-readable paths into code-friendly query strings.
Read more >Dynamic URL Rewriting at the edge with Cloudflare
This move allows us to add new rule categories such as Transform Rules. All API endpoints remain unchanged. Try it now. URL Rewriting...
Read more >How to Create NGINX Rewrite Rules
If your original question is about where in the NGINX configuration to put the rewrite directive, the documentation says it can go in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Related PR: #5623
OK. It is meaningful to compute any two predicates with ‘AND’ / ‘OR’ operation.