在论坛中出现的各种疑难问题:模糊匹配问题
关于2个表模糊搜索匹配的问题,现已找到较快的解决方法,速度提升到每秒5条记录左右,而且不占CPU,不占内存,方法如下: ------------------------------------------------------------------------- 环境: 有2个表, 表1:MainTable (现有记录数在10万条
关于2个表模糊搜索匹配的问题,现已找到较快的解决方法,速度提升到每秒5条记录左右,而且不占CPU,不占内存,方法如下:
-------------------------------------------------------------------------
环境:
有2个表,
表1:MainTable (现有记录数在10万条左右)
字段:
id bigint自动编号
Title nvarchar(30)
SubId nvarchar(max)
表MainTable:
Id Title SubId
1 A 0
2 B 0
3 C 0
4 D 0
5 E 0
6 F 0
表2:SubTable (现有记录数在300万条左右)
字段:
id bigint自动编号
Description nvarchar(100)
Fl int '默认值为0,当进行模糊匹配后,值改为1
表SubTable:
Id Description Fl
1 ABC 0
2 AB 0
3 CD 0
4 EA 0
二、需要实现的结果为:
表MainTable:
Id Title SubId
1 A 0,1,2,4
2 B 0,1,2
3 C 0,1,3
4 D 0,3
5 E 0,4
6 F Null
第6条记录由于没有匹配的值,所以改为Null
-------------------------------------------------------------------------
1、由于记录数太多,通过内部存储搜索速度太慢,中途不能暂停,平均每分钟才能处理5条记录左右;
2、原先通过外部循环的方法处理,速度1秒1条左右,会比方法1速度快,但非常占CPU;
现在的办法:
用VBS编写,定义2个数组,IDArray()和DescriptionArray()分别用于存储在SubTable表检索到的ID集和Description集
1、MainTable用循环的方式,按字段Title升序的方式得取Title字段的值,
先取得第一条记录的Title字段的第一个字符,根据这个字符模糊匹配SubTable的Description字段,并将检索到的结果存放在数组IDArray和DescriptionArray()中。
2、通过循环方式,将MainTable表的当前记录的Title字段的完整值与DescriptionArray()的值进行匹配处理,并update。
3、获取MainTable的下一条记录,判断该条记录Title字段的第一个字符是否与上一条记录的Title的第一个字符相同,如果相同,则从第2步开始处理;如果不同,则从第1步开始处理。
------------------------------------------------------------------------------
这种方法减少了每次去SubTable模糊搜索的次数,如果Title字段的第一个字符相同的记录非常多的情况下,速度还可能会提高很多。
总结一下,这个问题的解决不是通过sql server,而是在vbs,通过运用数据本身的特性,也就是:Title字段的第一个字符相同的记录非常多,减少了重复的劳动,少做了很多的无用功,最后,大幅提升性能。
真的是好办法,其实,从这个例子中可以看出,优化,更重要的是强调思维,而不简单的是某个技术,注重细节,仔细分析,楼主就解决了这个优化问题。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











You can blur the photos in Yitian Camera, so how to blur the photos? Users can click Edit to select a photo, then click Effects and select Blur to blur the photo. This introduction to how to blur photos can tell you the specific content. The following is a detailed introduction, come and take a look! Yitian Camera usage tutorial. How to blur photos with Yitian Camera. Answer: Go to Edit-Special Effects-Blur. The specific process: 1. First open the app and click Edit on the lower left. 2. Then click on a picture and click the edit button. 3. Then click the special effects button below. 4. You can find the blur function below. 5. Then select the magnification of the blur.

The clustering effect evaluation problem in the clustering algorithm requires specific code examples. Clustering is an unsupervised learning method that groups similar samples into one category by clustering data. In clustering algorithms, how to evaluate the effect of clustering is an important issue. This article will introduce several commonly used clustering effect evaluation indicators and give corresponding code examples. 1. Clustering effect evaluation index Silhouette Coefficient Silhouette coefficient evaluates the clustering effect by calculating the closeness of the sample and the degree of separation from other clusters.

Discuz forum permission management: Read the permission setting guide In Discuz forum management, permission setting is a crucial part. Among them, the setting of reading permissions is particularly important, as it determines the scope of content that different users can see in the forum. This article will introduce in detail the reading permission settings of the Discuz forum and how to flexibly configure it for different needs. 1. Basic concepts of reading permissions In the Discuz forum, reading permissions mainly include the following concepts that need to be understood: Default reading permissions: Default after new user registration

Sometimes the wallpaper is blurred when using Win11. I don’t know what’s going on. In fact, we can solve it by modifying the registry or application compatibility. Win11 wallpaper blur solution: 1. Desktop blur 1. If the desktop is blurred, you can right-click the bottom start menu and open "Run" 2. Then enter "regedit" and press Enter to open the registry. 3. After opening, go to the "Computer\HKEY_CURRENT_USER\ControlPanel\Desktop" location. 4. After entering, right-click on the blank space and select Create a new "DWORD Value" 5. Rename it to "JPEGImportQuality" and double-click to open the data.

Known for its powerful performance and versatile features, the iPhone is not immune to the occasional hiccup or technical difficulty, a common trait among complex electronic devices. Experiencing iPhone problems can be frustrating, but usually no alarm is needed. In this comprehensive guide, we aim to demystify some of the most commonly encountered challenges associated with iPhone usage. Our step-by-step approach is designed to help you resolve these common issues, providing practical solutions and troubleshooting tips to get your equipment back in peak working order. Whether you're facing a glitch or a more complex problem, this article can help you resolve them effectively. General Troubleshooting Tips Before delving into specific troubleshooting steps, here are some helpful

To solve the problem that jQuery.val() cannot be used, specific code examples are required. For front-end developers, using jQuery is one of the common operations. Among them, using the .val() method to get or set the value of a form element is a very common operation. However, in some specific cases, the problem of not being able to use the .val() method may arise. This article will introduce some common situations and solutions, and provide specific code examples. Problem Description When using jQuery to develop front-end pages, sometimes you will encounter

PHP String Matching Tips: Avoid Ambiguous Included Expressions In PHP development, string matching is a common task, usually used to find specific text content or to verify the format of input. However, sometimes we need to avoid using ambiguous inclusion expressions to ensure match accuracy. This article will introduce some techniques to avoid ambiguous inclusion expressions when doing string matching in PHP, and provide specific code examples. Use preg_match() function for exact matching In PHP, you can use preg_mat

PHP Regular Expressions: Exact Matching and Exclusion Fuzzy inclusion regular expressions are a powerful text matching tool that can help programmers perform efficient search, replacement and filtering when processing text. In PHP, regular expressions are also widely used in string processing and data matching. This article will focus on how to perform exact matching and exclude fuzzy inclusion operations in PHP, and will illustrate it with specific code examples. Exact match Exact match means matching only strings that meet the exact condition, not any variations or extra words.
