直接LEFT JOIN链和SELECT子查询LEFT JOIN之间的区别(Difference between direct LEFT JOIN chain and SELECT sub-query LEFT JOIN)
我有一个包含4个表的MySQL JOIN:
直接链接
SELECT col1, col2, col3... col12 FROM (((tbl1 LEFT JOIN tbl2...) LEFT JOIN tbl3 ...) LEFT JOIN tbl4);
子选择
(SELECT col10 .. col12 FROM (SELECT col7 .. col9 FROM (SELECT col1, ... col6 FROM tbl1 LEFT JOIN tbl2) AS J1 LEFT JOIN tbl3) AS J2 LEFT JOIN tbl4...)
两种方法之间是否存在效率差异? 我的直觉是,子选择使用SELECT ... WHERE子句丢弃不必要的行和列,使JOIN更快,内存更少。 任何建议? 其他数据库怎么样?
I have a MySQL JOIN consisting 4 tables:
Direct chaining
SELECT col1, col2, col3... col12 FROM (((tbl1 LEFT JOIN tbl2...) LEFT JOIN tbl3 ...) LEFT JOIN tbl4);
Sub-SELECT
(SELECT col10 .. col12 FROM (SELECT col7 .. col9 FROM (SELECT col1, ... col6 FROM tbl1 LEFT JOIN tbl2) AS J1 LEFT JOIN tbl3) AS J2 LEFT JOIN tbl4...)
Is there an efficiency difference between the two methods? My gut feeling is that sub-selects discard unnecessary rows and columns with the SELECT ... WHERE clause and makes JOINs faster and less memory intensive. Any advice? How about other databases?
原文:https://stackoverflow.com/questions/21899104
最满意答案
以下是我如何用递归函数来做到这一点。 不确定这是最佳答案,但它确实有效。
// This is a recursive function stopping when the inner span gets small enough function checkOverflow (container) { const child = container.children[0] if (child.offsetWidth > container.offsetWidth) { // Does only work with px size, for other units, you'll have to modify this child.style.fontSize = parseInt(window.getComputedStyle(child).fontSize) - 1 + 'px' checkOverflow(container) } } const containers = document.querySelectorAll('.div1') containers.forEach(checkOverflow)
div.div1 { height:120px; width:120px; background-color:orange; } span.span1 { font-family: Verdana; font-size: 36px; font-weight: bold; }
<div class="div1"> <span class="span1">1234</span> </div> <br/> <div class="div1"> <span class="span1">12345</span> </div>
Here's how I'd do it with a recursive function. Not sure it's the optimal answer but it does the work.
// This is a recursive function stopping when the inner span gets small enough function checkOverflow (container) { const child = container.children[0] if (child.offsetWidth > container.offsetWidth) { // Does only work with px size, for other units, you'll have to modify this child.style.fontSize = parseInt(window.getComputedStyle(child).fontSize) - 1 + 'px' checkOverflow(container) } } const containers = document.querySelectorAll('.div1') containers.forEach(checkOverflow)
div.div1 { height:120px; width:120px; background-color:orange; } span.span1 { font-family: Verdana; font-size: 36px; font-weight: bold; }
<div class="div1"> <span class="span1">1234</span> </div> <br/> <div class="div1"> <span class="span1">12345</span> </div>
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如何调整并使UILabel的宽度适合文字大小?(How to adjust and make the width of a UILabel to fit the text size?)[2022-12-17]
这假设您已经设置了字体: label.text = @"some text"; [label sizeToFit]; 您还需要定义最大宽度,并告诉程序如果sizeToFit给出的宽度大于该最大值,该怎么做。 This assumes you have already set the font: label.text = @"some text"; [label sizeToFit]; You will also need to define a maximum width, and tell your ... -
自动调整div的大小(Automatically resizing div)[2023-07-20]
我在代码中试过这个,请你尝试一下,看看它是否符合你的需要,下面的代码将使绿色div满足提醒容器的高度,然后在计算文本大小和宽度后缩小以适应新的文字高度 function update() { $('#container').css('height', '200px' /*this would be dynamic based on the container height*/); $('#container .body-text').bigText({ verticalAli ... -
我遇到了同样的问题,这个解决方法对我有用: -(void)webViewDidFinishLoad:(UIWebView *)webView{ [webView scalesPageToFit]; float scale = 130000/webView.scrollView.frame.size.width; NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].st ...
-
跨度和Div行为(Span and Div behaviour)[2022-04-30]
检查一下 http://jsfiddle.net/TY358/1/ 增加了nav类的保证金: margin-top:0px; 并减少顶部填充 Check this http://jsfiddle.net/TY358/1/ Added margin for the nav class: margin-top:0px; and reduced the top padding -
调整div以适合儿童跨度(Sizing div to fit a child span)[2021-11-03]
这个怎么样? ... -
以下是我如何用递归函数来做到这一点。 不确定这是最佳答案,但它确实有效。 // This is a recursive function stopping when the inner span gets small enough function checkOverflow (container) { const child = container.children[0] if (child.offsetWidth > container.offsetWidth) { // D ...
-
根据Vitorino评论 #allcomplex>div { margin-bottom: 10px; display: block; } .complexmem { width: 40vw; height: 10vw; background-color: yellowgreen; display: table-cell; vertical-align: middle; } .complexmem:before { content: ''; height: 100%; ...
-
替换这个: cell.label.adjustsFontSizeToFitWidth 有了这个: cell.label.adjustsFontSizeToFitWidth = true Replace this: cell.label.adjustsFontSizeToFitWidth with this: cell.label.adjustsFontSizeToFitWidth = true