|
Also, synonyms are pretty worthless for avoiding dynamic SQL, as far as I can tell, you can't do SET IDENTITY_INSERT on a synonym, which means using dynamic SQL anyways. code:
I would love to be wrong though.
|
# ? Jun 14, 2008 21:44 |
|
|
# ? May 11, 2024 11:16 |
|
Stephen posted:Is there anything I can do to improve the efficiency of this query? The views table is pushing 5 million records, and the photos table is up to near 200 000 so it's really starting to slow down. I have views.auto_id and views.view_type_id both indexed but it's still taking quite awhile. There aren't any great approaches to solve this problem in a generic way since at the end of the day you still need to aggregate 5 million records, and compute a possibly large outer join. The best thing to do is probably to asynchronously pre-compute part or all of the query and refresh/update on insert or on a timer depending on your needs and your workload. You're probably insert few read many so the additional time added to insert operations is a worthwhile investment. Make sure you look at MySQL concurrency control and make adequate accommodations so that queries don't block while the tables are refreshing.
|
# ? Jun 14, 2008 22:10 |
|
Here's the deal, I have three tables "News", "NewsCategories" and "Category" News has news_Id NewsCategories has news_Id and category_Id Category has category_Id I'm trying to have a recordset where I want news that must have certain categories. I havn't been able to get one working and figured it was pretty basic. Here's the query I have right now (that obviously doesn't work because there's two AND on the same field): code:
|
# ? Jun 17, 2008 21:24 |
|
code:
|
# ? Jun 17, 2008 21:28 |
|
mezz posted:
That works beautifully if it's not strict. But if I want the news to be in category_Id = 81 And category_Id = 2 , what do I do ? :/ Because I don't want news that only match 81 but not 2.
|
# ? Jun 17, 2008 21:37 |
|
code:
|
# ? Jun 17, 2008 21:45 |
|
xenilk posted:That works beautifully if it's not strict. But if I want the news to be in category_Id = 81 And category_Id = 2 , what do I do ? :/ code:
e: well i think both jethro's & mine should work
|
# ? Jun 17, 2008 21:54 |
|
Jethro posted:
I think that's it! Here's what I came up with: code:
xenilk fucked around with this message at 21:57 on Jun 17, 2008 |
# ? Jun 17, 2008 21:55 |
|
Stephen posted:Is there anything I can do to improve the efficiency of this query? The views table is pushing 5 million records, and the photos table is up to near 200 000 so it's really starting to slow down. I have views.auto_id and views.view_type_id both indexed but it's still taking quite awhile. Something like this may help code:
|
# ? Jun 17, 2008 23:04 |
|
How would you go about importing a CSV file into the database with some custom logic and be able to report errors (ideally by sending an e-mail)? We're using SQL Server 2005. Essentially each row in the CSV file should have an ID that matches a record in a database table. If there is a match, then there is an insert done in a separate table using the values from the CSV file. If there is no match, then we may need to report an error with the information from the CSV file. If there are rows in the DB table that are not in the CSV file, then we may need to do an update or report an error depending on the values in the table. My supervisor suggested taking a look into Sql Server Integration Services, which I know absolutely nothing about. Any recommendations for where to learn about SSIS or if it can do what I need it to do? Any suggestions on other tools to look into. This would be running from a windows service that would execute the script once a day automatically.
|
# ? Jun 17, 2008 23:15 |
|
chocojosh posted:How would you go about importing a CSV file into the database with some custom logic and be able to report errors (ideally by sending an e-mail)? We're using SQL Server 2005. Look into BULK INSERT.
|
# ? Jun 18, 2008 00:02 |
|
I've Googled around, but I can't find anything, so I figured I'd ask here. I'm working with HSQLDB right now, and it's got some interesting (read: frustrating) things going on with its quotation requirements. Now, here're the tables that matter for this problem:code:
code:
code:
code:
code:
Fangs404 fucked around with this message at 16:30 on Jun 18, 2008 |
# ? Jun 18, 2008 00:40 |
|
Well you never included the table edges in your FROM statement code:
|
# ? Jun 18, 2008 03:05 |
|
mezz posted:Well you never included the table edges in your FROM statement Holy poo poo.
|
# ? Jun 18, 2008 03:29 |
|
Well, poo poo, I thought that was the problem, but apparently it's not. I got into work today, and it's still giving me the same error. Here's the error now:code:
|
# ? Jun 18, 2008 16:24 |
|
Ardhanari posted:Look into BULK INSERT. Bulk insert doesn't seem to support custom rules. I'm guessing the best thing to do would be to first check the database and ensure that our input is valid. If there are any errors, report them first, and keep the valid data and use bulk insert on the valid data?
|
# ? Jun 18, 2008 16:43 |
|
Fangs404 posted:Well, poo poo, I thought that was the problem, but apparently it's not. I got into work today, and it's still giving me the same error. Here's the error now: quote:Tables and columns which are created with So I think edges."ID" and edges."EDGETYPE" (and probably edges.id and edges.edgetype) might work. I had a bit a similar problem when I started with PostgreSQL actually, there everything gets converted to lowercase.
|
# ? Jun 18, 2008 17:28 |
|
mezz posted:I suspect it will have something to do with this? poo poo, you're right. That worked. I just added quotes around every column name in both the CREATE statements and in the SELECT and INSERT statements. What a pain in the rear end, but at least it works. Thanks!
|
# ? Jun 18, 2008 17:35 |
|
chocojosh posted:Bulk insert doesn't seem to support custom rules. I've never used the FIRE_TRIGGERS part before, but I think you could do it through that -- just set up a trigger on the destination table with whatever custom logic you need (checking that every row in Inserted has a corresponding ID, etc). You should even be able to send emails from the trigger, but make sure you only do it under strictly specified conditions unless you want whoever's running your email server to cut your throat.
|
# ? Jun 18, 2008 21:22 |
|
chocojosh posted:How would you go about importing a CSV file into the database with some custom logic and be able to report errors (ideally by sending an e-mail)? We're using SQL Server 2005.
|
# ? Jun 18, 2008 21:46 |
|
SSIS is painful, please don't use it, you'll only encourage MS to make it 'better'. Also, using triggers to enforce constraints is bad, just don't do it. Your best option is to either use bcp.exe (if you need to trigger the the load externally) or bulk insert (if you want to trigger it from the db) to load the data into a separate table. Then you do something like: code:
|
# ? Jun 19, 2008 00:28 |
|
code:
Any ideas? Acer Pilot fucked around with this message at 06:52 on Jun 19, 2008 |
# ? Jun 19, 2008 06:35 |
|
From a previous code I made a query (that varies alot and as you can see it can create a lot of inner join. GALLERY_ID and CATEGORY_ID are indexed aswell code:
Thanks!
|
# ? Jun 19, 2008 17:26 |
|
xenilk posted:From a previous code I made a query (that varies alot and as you can see it can create a lot of inner join. Why are you joining the same table 6 times? Couldn't this work: code:
|
# ? Jun 19, 2008 20:13 |
|
I think he wants all the galleries who belong to category 82 but not to 38,52,53,74,82,96. So if I got it right, if a gallery has categories '82' and '1' it should fit, if it's in 82,1,38 it should be left out? I think this won't be too far off: code:
it would become code:
|
# ? Jun 19, 2008 20:50 |
|
mezz, you are exactly right! I will try the way you wrote, could you explain to me that specific part code:
I figure the 2 is the number of numbers I have in the first SELECT IN but I'm not sure I get what it means. Thanks!
|
# ? Jun 19, 2008 21:02 |
|
Actually it should just be count(*)=x. I made a quick test, gallery_id=o_id,cat_id=p_id and the table is named 'a' Say you have these elements : code:
Let's take a look at this count thing: code:
code:
This won't work if you have duplicates in the table, the combination o_id & p_id has to be unique.
|
# ? Jun 19, 2008 22:58 |
|
mezz posted:Awesome explanation Thanks for explaining, it completly makes sense now Although, I'm still running into "errors" code:
|
# ? Jun 20, 2008 16:07 |
|
Mezz: Thanks for the clarification, I misread the = for != in the first WHERE statement (and this was a great example why when you ask for help you should also explain *what* you want to do instead of your solution ) Regarding SSIS: my supervisor insists that I use SSIS for this little tool I'm working on. I think they're hinting that I test out a new technology for the company (I've shown interest before in learning new stuff). Any books you'd recommend? I've been given permission from the CTO to go pick up a book and have it expensed by the company. Jethro: Thanks for the BOL page. I'd rather have a real book to start off with (I tend to prefer real books over online books for learning stuff. I prefer using online books/articles when I'm already comfortable with the tool/language and need to do a very specific task).
|
# ? Jun 20, 2008 16:12 |
|
chocojosh posted:Regarding SSIS: my supervisor insists that I use SSIS for this little tool I'm working on. I think they're hinting that I test out a new technology for the company (I've shown interest before in learning new stuff). I've been working with SSIS for about a year now and the two Wrox books I used to get started: Professional SQL Server 2005 Integration Services and the Expert counterpart were both pretty good. Also, reading through Jamie Thomson's blog entries are good too: http://blogs.conchango.com/jamiethomson/
|
# ? Jun 20, 2008 16:16 |
|
edit: ignore me
lhunc fucked around with this message at 17:07 on Jun 20, 2008 |
# ? Jun 20, 2008 16:52 |
|
xenilk posted:Thanks for explaining, it completly makes sense now Use EXCEPT to get rid of that innermost block comparison. code:
|
# ? Jun 20, 2008 17:52 |
|
xenilk posted:
So I'm guessing you're using Mysql on some shared hosting? You get what you pay for
|
# ? Jun 20, 2008 17:58 |
|
mezz posted:I'm afraid it's as good as it gets, I don't see any way to reduce it even more but I could be wrong. In any case it runs in <5 seconds on 300 000 rows with nothing cached and without indexes on my crappy laptop so it's not supposed to be that slow. That is bizarre, I am using a dedicated server at iweb8.com with these specs: Processor #1 Vendor: GenuineIntel Processor #1 Name: Intel(R) Pentium(R) D CPU 2.80GHz Processor #1 speed: 2800.391 MHz Processor #1 cache size: 2048 KB Processor #2 Vendor: GenuineIntel Processor #2 Name: Intel(R) Pentium(R) D CPU 2.80GHz Processor #2 speed: 2800.391 MHz Processor #2 cache size: 2048 KB and 1024meg of ram My gallery table has 44121 rows, gallerycategory has 1174 rows and gallery has 97 rows.
|
# ? Jun 20, 2008 18:36 |
|
No Safe Word posted:
|
# ? Jun 20, 2008 22:47 |
|
I've got some questions for a new hobby project. It's a web bookmark database type thing, and there will be user-added keywords associated with each url. I want to be able to search by keyword, and I want to do this in an intelligent way. I know not to just dump all the keywords into a big Text field, but I don't know the proper way to handle this. Can anyone post some tips or basic-intermediate articles on this type of thing?
|
# ? Jun 21, 2008 23:35 |
|
Factor Mystic posted:I've got some questions for a new hobby project. It's a web bookmark database type thing, and there will be user-added keywords associated with each url. I want to be able to search by keyword, and I want to do this in an intelligent way. I know not to just dump all the keywords into a big Text field, but I don't know the proper way to handle this. Can anyone post some tips or basic-intermediate articles on this type of thing? Each URL can have many keywords, and keywords can have multiple bookmarks 'tagged', right? Set up a Keywords(KeywordID, KeywordData, ...) table and a Bookmark_Keyword (BookmarkID, KeywordID) to create your many-to-many relation. Then you can get the keywords for a URL by querying through the bridge table, or get all bookmarks with a particular tag the same way.
|
# ? Jun 22, 2008 16:58 |
|
Ardhanari posted:Each URL can have many keywords, and keywords can have multiple bookmarks 'tagged', right? Set up a Keywords(KeywordID, KeywordData, ...) table and a Bookmark_Keyword (BookmarkID, KeywordID) to create your many-to-many relation. Then you can get the keywords for a URL by querying through the bridge table, or get all bookmarks with a particular tag the same way. Alright, in that setup I don't understand how a bookmark is related to more than one keyword. If each KeywordID links to only one keyword (KeywordData), how can more than one keyword be saved for a bookmark? I guess I don't understand the proper way to store a variable length list of data.
|
# ? Jun 22, 2008 19:51 |
|
Factor Mystic posted:Alright, in that setup I don't understand how a bookmark is related to more than one keyword. If each KeywordID links to only one keyword (KeywordData), how can more than one keyword be saved for a bookmark? I guess I don't understand the proper way to store a variable length list of data. Keyword.KeywordID links to Bookmark_Keyword.KeywordID. Bookmark_Keyword.BookmarkID then links to Bookmark.BookmarkID. You'll have unique keywords (if you want) but they link to multiple Bookmark_Keyword entries and thus to multiple bookmarks (and vice versa). code:
ninja edit: holy poo poo, I didn't realize I had an encoded message about markup in there. Unintended, but I'm leaving that in!
|
# ? Jun 22, 2008 21:44 |
|
|
# ? May 11, 2024 11:16 |
|
Ardhanari posted:Keyword.KeywordID links to Bookmark_Keyword.KeywordID. Bookmark_Keyword.BookmarkID then links to Bookmark.BookmarkID. You'll have unique keywords (if you want) but they link to multiple Bookmark_Keyword entries and thus to multiple bookmarks (and vice versa). Alright, this is making a lot more sense now with the example tables there. I got that I would need a Keyword and a Bookmark table, but I didn't know how to properly link to the two together. So each row of the Bookmark_Keyword table contains exactly one Keyword <-> Bookmark relation. Now I get it. Thank you
|
# ? Jun 22, 2008 22:46 |