{"id":4185,"date":"2023-11-06T21:35:09","date_gmt":"2023-11-06T13:35:09","guid":{"rendered":"https:\/\/white-night.club\/?p=4185"},"modified":"2024-08-24T11:18:41","modified_gmt":"2024-08-24T03:18:41","slug":"pg25","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/06\/pg25\/","title":{"rendered":"MIT6.5830 Lab 2: GoDB Operators\u5b9e\u9a8c\u8bb0\u5f55\uff08\u4e8c\uff09"},"content":{"rendered":"\n<p>Filter\uff08\u5176\u5b9e\u5c31\u662fwhere\uff09\u5b8c\u6210\u540e\uff0c\u63a5\u4e0b\u6765\u63a5\u7740\u5b8c\u6210Join\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite><em>\u5b8c\u6210join<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5728Mysql\u4e2d\uff0c\u5982\u679c\u6211\u4eec\u53ea\u4f7f\u7528join\u800c\u4e0d\u7528on\uff0c\u90a3\u4e48\u4f1a\u51fa\u73b0\u7b1b\u5361\u513f\u79ef\u3002\u4f46\u8fd9\u91cc\u6ca1\u63d0\u5230\u8fd9\u70b9\uff0c\u6240\u4ee5\u6211\u4eec\u6682\u65f6\u4e0d\u7ba1\u3002<\/p>\n\n\n\n<p>\u8001\u6837\u5b50\uff0c\u5148\u8865\u5168desc\u3002EqualityJoin\u91cc\u9762\u80fd\u62ff\u5230desc\u7684\u5c31\u4e24\u4e2a*Operator\u3002\u90a3\u76f4\u63a5\u5199\u4e0a\u5373\u53ef\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (hj *EqualityJoin[T]) Descriptor() *TupleDesc {\n\t\/\/ TODO: some code goes here\n\tdesc := ((*hj.left).Descriptor()).merge((*hj.right).Descriptor())\n\treturn desc\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (hj *EqualityJoin[T]) <\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">() *TupleDesc {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">desc<\/span><span style=\"color: #D4D4D4\"> := ((*hj.left).<\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">()).<\/span><span style=\"color: #DCDCAA\">merge<\/span><span style=\"color: #D4D4D4\">((*hj.right).<\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> desc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u8865\u5168\u8fed\u4ee3\u5668\u3002\u6709\u4e00\u8bf4\u4e00\uff0c\u5f88\u96be\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u601d\u8def<\/p>\n<cite><em>\u4ec0\u4e48\u662fJoin<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5728\u6b64\u8865\u5168Iterator\u4e4b\u524d\uff0c\u6211\u4eec\u5f97\u5148\u60f3\u60f3\u4ec0\u4e48\u662fJoin\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>2023\/11\/8\uff1a\u505c\u66f4\u4e00\u4e24\u5468\uff0c\u5148\u628a\u671f\u4e2d\u8003\u8bd5\u548c\u4e0b\u5b66\u671f\u7684\u5b9e\u4e60\u641e\u5b9a\u4e86\u5148\u3002<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>\u6253\u7b97\u627e\u4e2a\u65f6\u95f4\u5148\u5de9\u56fa\u4e00\u4e0b\u524d\u9762\u5199\u7684\u5185\u5bb9\uff0c\u518d\u6076\u8865\u4e00\u4e0b\u6570\u636e\u5e93\u5e95\u5c42\u539f\u7406\u518d\u56de\u6765\u5199\u3002\u4e0d\u7136\u9762\u8bd5\u95ee\u5230\u7ec6\u8282\u8001\u662f\u5fd8\u3002<\/cite><\/blockquote>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color has-link-color wp-elements-e0ccac45b73211023381243d7d95192e\">\n<p>\u6211\u56de\u6765\u4e86\uff082024\/8\/23\uff09<\/p>\n<cite><em>\u6709\u59cb\u6709\u7ec8<\/em><\/cite><\/blockquote>\n\n\n\n<p>Man, what can I say?<\/p>\n\n\n\n<p>\u6bd5\u7adf\u5f88\u4e45\u6ca1\u5199\uff0c\u6709\u4e9b\u6982\u5ff5\u90fd\u548c\u53d8\u91cf\u90fd\u5fd8\u4e86\u3002\u5199\u7684\u65f6\u5019\u987a\u5e26\u590d\u4e60\u4e0b\u4e4b\u524d\u7684\u77e5\u8bc6\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color has-link-color wp-elements-29ee558ff6d5ace145aa02933701ab82\">\n<p>Join<\/p>\n<cite><em>\u5b8c\u6210Exercise 1<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u76f8\u4fe1\u5199\u8fc7\u591a\u8868\u8fde\u7ed3SQL\u9898\u7684\u90fd\u6bd4\u8f83\u719f\u6089Join\u7684\u7528\u6cd5\u3002\u6bd4\u5982A JOIN B\uff0c\u6bcf\u4eceA\u53d6\u51fa\u4e00\u884c\u6570\u636e\uff0c\u90fd\u9700\u8981\u904d\u5386\u4e00\u6b21B\u4e2d\u6240\u6709\u5143\u7ec4\u5e76\u8fdb\u884c\u62fc\u63a5\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4e5f\u662f\u4e00\u6837\uff0c\u6bd4\u5982\u6211\u4eec\u53ef\u4ee5\u5148\u4ece\u6d4b\u8bd5\u6837\u4f8b\u5165\u624b\uff0c\u770b\u770b\u8f93\u5165\u8f93\u51fa\u662f\u4ec0\u4e48\u3002\u7531\u4e8e\u6392\u7248\u95ee\u9898\uff0c\u8fd9\u91cc\u80af\u5b9a\u5c55\u793a\u4e0d\u4e86\u6240\u6709\u7684\u53d8\u91cf\uff0c\u53ef\u4ee5\u81ea\u5df1\u6253\u4e2a\u65ad\u70b9\u770b\u770b\u3002<\/p>\n\n\n\n<figure data-wp-context=\"{ &quot;core&quot;:\n\t\t\t\t{ &quot;image&quot;:\n\t\t\t\t\t{   &quot;imageLoaded&quot;: false,\n\t\t\t\t\t\t&quot;initialized&quot;: false,\n\t\t\t\t\t\t&quot;lightboxEnabled&quot;: false,\n\t\t\t\t\t\t&quot;hideAnimationEnabled&quot;: false,\n\t\t\t\t\t\t&quot;preloadInitialized&quot;: false,\n\t\t\t\t\t\t&quot;lightboxAnimation&quot;: &quot;zoom&quot;,\n\t\t\t\t\t\t&quot;imageUploadedSrc&quot;: &quot;https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55.png&quot;,\n\t\t\t\t\t\t&quot;imageCurrentSrc&quot;: &quot;&quot;,\n\t\t\t\t\t\t&quot;targetWidth&quot;: &quot;1920&quot;,\n\t\t\t\t\t\t&quot;targetHeight&quot;: &quot;1040&quot;,\n\t\t\t\t\t\t&quot;scaleAttr&quot;: &quot;&quot;,\n\t\t\t\t\t\t&quot;dialogLabel&quot;: &quot;Enlarged image&quot;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\" data-wp-interactive class=\"wp-block-image size-large has-custom-border wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"555\" data-wp-effect--setStylesOnResize=\"effects.core.image.setStylesOnResize\" data-wp-effect=\"effects.core.image.setButtonStyles\" data-wp-init=\"effects.core.image.initOriginImage\" data-wp-on--click=\"actions.core.image.showLightbox\" data-wp-on--load=\"actions.core.image.handleLoad\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55-1024x555.png\" alt=\"\" class=\"wp-image-9418\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55-1024x555.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55-300x163.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55-768x416.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55-1536x832.png 1536w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-55.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge image\"\n\t\t\tdata-wp-on--click=\"actions.core.image.showLightbox\"\n\t\t\tdata-wp-style--right=\"context.core.image.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"context.core.image.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button>        <div data-wp-body=\"\" class=\"wp-lightbox-overlay zoom\"\n            data-wp-bind--role=\"selectors.core.image.roleAttribute\"\n            data-wp-bind--aria-label=\"selectors.core.image.dialogLabel\"\n            data-wp-class--initialized=\"context.core.image.initialized\"\n            data-wp-class--active=\"context.core.image.lightboxEnabled\"\n            data-wp-class--hideAnimationEnabled=\"context.core.image.hideAnimationEnabled\"\n            data-wp-bind--aria-modal=\"selectors.core.image.ariaModal\"\n            data-wp-effect=\"effects.core.image.initLightbox\"\n            data-wp-on--keydown=\"actions.core.image.handleKeydown\"\n            data-wp-on--touchstart=\"actions.core.image.handleTouchStart\"\n            data-wp-on--touchmove=\"actions.core.image.handleTouchMove\"\n            data-wp-on--touchend=\"actions.core.image.handleTouchEnd\"\n            data-wp-on--click=\"actions.core.image.hideLightbox\"\n            tabindex=\"-1\"\n            >\n                <button type=\"button\" aria-label=\"\u5173\u95ed\" style=\"fill: var(--wp--preset--color--foreground)\" class=\"close-button\" data-wp-on--click=\"actions.core.image.hideLightbox\">\n                    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\" width=\"20\" height=\"20\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z\"><\/path><\/svg>\n                <\/button>\n                <div class=\"lightbox-image-container\">\n<figure class=\"wp-block-image size-large has-custom-border responsive-image\"><img decoding=\"async\" data-wp-bind--src=\"context.core.image.imageCurrentSrc\" data-wp-style--object-fit=\"selectors.core.image.lightboxObjectFit\" src=\"\" alt=\"\" class=\"wp-image-9418\" style=\"border-style:none;border-width:0px;border-radius:0px\"\/><\/figure>\n<\/div>\n                <div class=\"lightbox-image-container\">\n<figure class=\"wp-block-image size-large has-custom-border enlarged-image\"><img decoding=\"async\" data-wp-bind--src=\"selectors.core.image.enlargedImgSrc\" data-wp-style--object-fit=\"selectors.core.image.lightboxObjectFit\" src=\"\" alt=\"\" class=\"wp-image-9418\" style=\"border-style:none;border-width:0px;border-radius:0px\"\/><\/figure>\n<\/div>\n                <div class=\"scrim\" style=\"background-color: var(--wp--preset--color--background)\" aria-hidden=\"true\"><\/div>\n        <\/div><\/figure>\n\n\n\n<p>\u7b80\u5355\u6765\u8bf4\uff0c\u7ed9\u4e86\u4e24\u4e2a\u6570\u636e\u76f8\u540c\u7684\u8868hf\u548chf2\u3002\u8fd8\u7ed9\u4e86\u4e24\u4e2a\u5143\u7ec4outT1\uff0coutT2\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">name<\/td><td class=\"has-text-align-center\" data-align=\"center\">age<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">sam<\/td><td class=\"has-text-align-center\" data-align=\"center\">25<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">george jones<\/td><td class=\"has-text-align-center\" data-align=\"center\">999<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">george jones<\/td><td class=\"has-text-align-center\" data-align=\"center\">999<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6211\u5728\u5199join\u7684\u65f6\u5019\uff0c\u4e00\u76f4\u60f3\u7740on\u662f\u4e0d\u662f\u8981\u5206\u5f00\u5b9e\u73b0\uff0c\u4f46\u53d1\u73b0\u4e0d\u7528\u3002\u6bd4\u5982outT1\u8c03\u7528\u7684joinTuples\u662f\u6211\u4eec\u5728lab1\u4e2d\u8865\u5168\u7684\u4ee3\u7801\uff08\u5982\u4e0b\uff09\uff0c\u4f5c\u7528\u662f\u5408\u5e76\u4e24\u4e2a\u5143\u7ec4\u3002\u5f53\u65f6\u6211\u8fd8\u6ca1\u53d1\u73b0\u4ec0\u4e48\uff0c\u73b0\u5728\u624d\u53d1\u73b0\u8fd9\u4e00\u6b65\u5df2\u7ecf\u81ea\u5e26\u4e86ON\u7684\u64cd\u4f5c\uff0c\u56e0\u4e3a\u53ef\u4ee5\u770b\u5230\u5408\u5e76\u4e4b\u540e\u63cf\u8ff0\u7b26\u5b57\u6bb5\u662f\u4e0d\u53d8\u7684\u3002\u76f8\u5f53\u4e8eJOIN\u4e4b\u540e\u5e76\u4e0d\u4f1a\u591a\u51e0\u5217\u51fa\u6765\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Merge two tuples together, producing a new tuple with the fields of t2 appended to t1.\nfunc joinTuples(t1 *Tuple, t2 *Tuple) *Tuple {\n\t\/\/ TODO: some code goes here\n\tif t1 == nil &amp;&amp; t2 == nil {\n\t\treturn nil\n\t} else if t1 == nil {\n\t\treturn t2\n\t} else if t2 == nil {\n\t\treturn t1\n\t}\n\tnewfield := append(t1.Fields, t2.Fields...)\n\treturn &amp;Tuple{Desc: t1.Desc, Fields: newfield}\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ Merge two tuples together, producing a new tuple with the fields of t2 appended to t1.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">joinTuples<\/span><span style=\"color: #D4D4D4\">(t1 *Tuple, t2 *Tuple) *Tuple {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t1 == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> &amp;&amp; t2 == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t1 == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> t2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t2 == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> t1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">newfield<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">append<\/span><span style=\"color: #D4D4D4\">(t1.Fields, t2.Fields...)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> &amp;Tuple{Desc: t1.Desc, Fields: newfield}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4ed4\u7ec6\u89c2\u5bdf\u6d4b\u8bd5\u6837\u4f8b\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u5224\u65ad\u51fa\u6267\u884c\u7684\u64cd\u4f5c\u5e94\u8be5\u662f <strong>hf JOIN hf2<\/strong>\u3002\u5176\u4e2d\u8fd8\u7528\u5230\u4e86int\u7c7b\u578b\u7684\u5b57\u6bb5<strong>age<\/strong>\u3002\u8f6c\u6362\u6210SQL\u8bed\u53e5\u90a3\u5c31\u662f<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>hf JOIN hf2 ON hf.age = hf2.age<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-left\">\u6700\u540e\u7684\u68c0\u9a8c\u53ef\u4ee5\u770b\u5230\uff0cjoin\u4e4b\u540e\u7684\u8868\u6709\u4e94\u7ec4\u6570\u636e\uff0c\u5176\u4e2dsam\u51fa\u73b0\u4e00\u6b21\uff0cgeorge\u51fa\u73b0\u56db\u6b21\uff0c\u4e5f\u7b26\u5408\u4e0a\u9762SQL\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"  leftField := FieldExpr{td.Fields[1]}\n\tjoin, err := NewIntJoin(hf, &amp;leftField, hf2, &amp;leftField, 100)\n\tif err != nil {\n\t\tt.Errorf(&quot;unexpected error initializing join&quot;)\n\t\treturn\n\t}\n\titer, err := join.Iterator(tid)\n\tif err != nil {\n\t\tt.Fatalf(err.Error())\n\t}\n\tif iter == nil {\n\t\tt.Fatalf(&quot;iter was nil&quot;)\n\t}\n\tcnt := 0\n\tcntOut1 := 0\n\tcntOut2 := 0\n\tfor {\n\t\tt, _ := iter()\n\t\tif t == nil {\n\t\t\tbreak\n\t\t}\n\t\tif t.equals(outT1) {\n\t\t\tcntOut1++\n\t\t} else if t.equals(outT2) {\n\t\t\tcntOut2++\n\t\t}\n\t\t\/\/fmt.Printf(&quot;got tuple %v: %v\\n&quot;, cnt, t)\n\t\tcnt++\n\t}\n\tif cnt != 5 {\n\t\tt.Errorf(&quot;unexpected number of join results (%d, expected 5)&quot;, cnt)\n\t}\n\tif cntOut1 != 1 {\n\t\tt.Errorf(&quot;unexpected number of t1 results (%d, expected 1)&quot;, cntOut1)\n\t}\n\tif cntOut2 != 4 {\n\t\tt.Errorf(&quot;unexpected number of t2 results (%d, expected 4)&quot;, cntOut2)\n\t}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">leftField<\/span><span style=\"color: #D4D4D4\"> := FieldExpr{td.Fields[<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">]}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">join<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">NewIntJoin<\/span><span style=\"color: #D4D4D4\">(hf, &amp;leftField, hf2, &amp;leftField, <\/span><span style=\"color: #B5CEA8\">100<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Errorf<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;unexpected error initializing join&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">iter<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := join.<\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Fatalf<\/span><span style=\"color: #D4D4D4\">(err.<\/span><span style=\"color: #DCDCAA\">Error<\/span><span style=\"color: #D4D4D4\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> iter == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Fatalf<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;iter was nil&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">cnt<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">cntOut1<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">cntOut2<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">t<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">iter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">break<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t.<\/span><span style=\"color: #DCDCAA\">equals<\/span><span style=\"color: #D4D4D4\">(outT1) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\tcntOut1++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t.<\/span><span style=\"color: #DCDCAA\">equals<\/span><span style=\"color: #D4D4D4\">(outT2) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\tcntOut2++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #6A9955\">\/\/fmt.Printf(&quot;got tuple %v: %v\\n&quot;, cnt, t)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tcnt++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> cnt != <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Errorf<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;unexpected number of join results (<\/span><span style=\"color: #9CDCFE\">%d<\/span><span style=\"color: #CE9178\">, expected 5)&quot;<\/span><span style=\"color: #D4D4D4\">, cnt)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> cntOut1 != <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Errorf<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;unexpected number of t1 results (<\/span><span style=\"color: #9CDCFE\">%d<\/span><span style=\"color: #CE9178\">, expected 1)&quot;<\/span><span style=\"color: #D4D4D4\">, cntOut1)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> cntOut2 != <\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Errorf<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;unexpected number of t2 results (<\/span><span style=\"color: #9CDCFE\">%d<\/span><span style=\"color: #CE9178\">, expected 4)&quot;<\/span><span style=\"color: #D4D4D4\">, cntOut2)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u77e5\u9053\u4e0d\u7528\u5b9e\u73b0ON\uff0c\u90a3\u63a5\u4e0b\u6765\u5c31\u662f\u8865\u5168\u8fed\u4ee3\u5668\u4e86\u3002\u9700\u8981\u6ce8\u610f\u7684\u662fON\u5de6\u53f3\u4e24\u8fb9\u53ef\u80fd\u4e3a\u8868\u8fbe\u5f0f\uff0c\u4e0d\u80fd\u76f4\u63a5\u6839\u636e\u5de6\u53f3\u5b57\u6bb5\u7684Fields.EvalExpr\u53bb\u8fdb\u884c\u6bd4\u8f83\u3002\u8fd9\u70b9\u5728markdown\u91cc\u9762\u5df2\u6709\u6ce8\u660e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"513\" height=\"455\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-56.png\" alt=\"\" class=\"wp-image-9437\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-56.png 513w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-56-300x266.png 300w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/figure>\n\n\n\n<p>\u6709\u4e86\u601d\u8def\uff0c\u5199\u5c31\u5b8c\u4e8b\u4e86\u3002\u6bcf\u4ece\u5de6\u8fed\u4ee3\u5668\u53d6\u51fa\u4e00\u4e2a\u5143\u7ec4\uff0c\u5c31\u91cd\u65b0\u521d\u59cb\u5316\u53f3\u8fed\u4ee3\u5668\u518d\u5faa\u73af\u53d6\u51fa\u5143\u7ec4\uff0c\u5e76\u6bd4\u8f83\u5de6\u53f3\u5143\u7ec4\u7684\u5b57\u6bb5\u662f\u5426\u76f8\u7b49\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (joinOp *EqualityJoin[T]) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\n\t\/\/ TODO: some code goes here\n\tleftIter, err := (*joinOp.left).Iterator(tid)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trightIter, err := (*joinOp.right).Iterator(tid)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar leftTuple, rightTuple *Tuple\n\treturn func() (*Tuple, error) {\n\t\tfor {\n\t\t\tif leftTuple == nil {\n\t\t\t\tleftTuple, err = leftIter()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif leftTuple == nil {\n\t\t\t\t\treturn nil, nil\n\t\t\t\t}\n\t\t\t\trightIter, err = (*joinOp.right).Iterator(tid)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor {\n\t\t\t\trightTuple, err = rightIter()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif rightTuple == nil {\n\t\t\t\t\tleftTuple = nil\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tv, _ := joinOp.leftField.EvalExpr(leftTuple)\n\t\t\t\tleftDesc := joinOp.getter(v)\n\t\t\t\tv, _ = joinOp.rightField.EvalExpr(rightTuple)\n\t\t\t\trightDesc := joinOp.getter(v)\n\t\t\t\tif leftDesc == rightDesc {\n\t\t\t\t\treturn joinTuples(leftTuple, rightTuple), nil\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, nil\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (joinOp *EqualityJoin[T]) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">leftIter<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := (*joinOp.left).<\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">rightIter<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := (*joinOp.right).<\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">leftTuple<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">rightTuple<\/span><span style=\"color: #D4D4D4\"> *Tuple<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> leftTuple == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">leftTuple<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">leftIter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> leftTuple == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">rightIter<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> = (*joinOp.right).<\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">rightTuple<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">rightIter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> rightTuple == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #9CDCFE\">leftTuple<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">break<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">v<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := joinOp.leftField.<\/span><span style=\"color: #DCDCAA\">EvalExpr<\/span><span style=\"color: #D4D4D4\">(leftTuple)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">leftDesc<\/span><span style=\"color: #D4D4D4\"> := joinOp.<\/span><span style=\"color: #DCDCAA\">getter<\/span><span style=\"color: #D4D4D4\">(v)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">v<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> = joinOp.rightField.<\/span><span style=\"color: #DCDCAA\">EvalExpr<\/span><span style=\"color: #D4D4D4\">(rightTuple)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">rightDesc<\/span><span style=\"color: #D4D4D4\"> := joinOp.<\/span><span style=\"color: #DCDCAA\">getter<\/span><span style=\"color: #D4D4D4\">(v)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> leftDesc == rightDesc {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">joinTuples<\/span><span style=\"color: #D4D4D4\">(leftTuple, rightTuple), <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u8dd1\u4e00\u4e0b\uff0c\u8fc7\u3002\u4e0d\u8fc7\u6211\u6ca1\u505aoptional exercise\u3002\u6211\u76f4\u63a5\u8dd1\u4e86\u4e0b\u53d1\u73b0\u4f1a\u8d85\u65f610s+\u3002\u63d0\u793a\u8bf4\u4e0d\u7528\u5d4c\u5957\u5faa\u73af\u624d\u80fd\u8fc7TestBigJoinOptional\u3002\u6211\u8bb0\u5f97join\u8fd8\u6709\u5206\u4e3ahash join\u548cmerge join\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u81ea\u884c\u4e86\u89e3\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"559\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-57.png\" alt=\"\" class=\"wp-image-9440\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-57.png 889w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-57-300x189.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/08\/image-57-768x483.png 768w\" sizes=\"(max-width: 889px) 100vw, 889px\" \/><\/figure>\n\n\n\n<p>Lab2\u770b\u4e86\u4e0b\uff0c\u4e00\u5171\u67097\u4e2aexercise\u3002\u987f\u65f6\u611f\u89c9\u524d\u8def\u8270\u8f9b\u554a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lab2\u5b9e\u9a8c\u8bb0\u5f55\uff1aJoin<\/p>\n","protected":false},"author":1,"featured_media":3838,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[44,33],"tags":[34],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4185"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=4185"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4185\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3838"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=4185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}