简体   繁体   中英

Efficient way to find which values in CSV are NOT in DB?

A vendor is feeding us a CSV file of their products. A particular column on the file (eg column 3) is the style number. This file has thousands on entries.

We have a data-base table of products with a column called manufacturer_num which is the vendors style number.

I need to find which of the vendor's products we do not currently have.

I know I can loop throw each line in the CSV file and extract the style_number and check to see if it is in our data-base. But then I am making a call to the data-base for each line. This would be thousands of calls to the data-base. I think this is inefficient.

I could also build a list of the style numbers (either as a string or array) to make one DB call. Something like: WHERE manufactuer_num IN(...) But won't PHP run out of memory if the list is too big? And actually this would give me the ones we do have, not the ones we don't have.

Whats an efficient way to do this?

将CSV批量加载到临时表中,执行LEFT JOIN ,然后获取LEFT JOIN的RHS为NULL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM