Sql12
Version 2 (Jaime Phillips, 01/03/2012 06:00 pm)
| 1 | 1 | Jaime Phillips | h1. Bucket Selects |
|---|---|---|---|
| 2 | 2 | Jaime Phillips | |
| 3 | 1 | Jaime Phillips | Bucket results are stored in two tables, bucket_file and bucket_container. |
| 4 | 1 | Jaime Phillips | Table bucket_file is used to relate pfile_pk's to a bucket. |
| 5 | 1 | Jaime Phillips | Table bucket_container is used to relate uploadtree_pk's to a bucket. This table |
| 6 | 1 | Jaime Phillips | is used when the uploadtree_pk has no pfile. For example, directories. |
| 7 | 1 | Jaime Phillips | |
| 8 | 1 | Jaime Phillips | h2. Selecting bucket_file records |
| 9 | 2 | Jaime Phillips | |
| 10 | 1 | Jaime Phillips | select distinct bucket_file.pfile_fk, ufile_name, bucket_fk |
| 11 | 1 | Jaime Phillips | from bucket_file, |
| 12 | 1 | Jaime Phillips | (select pfile_fk as PF, ufile_name from uploadtree where upload_fk=444) as SS |
| 13 | 1 | Jaime Phillips | where PF=bucket_file.pfile_fk; |
| 14 | 1 | Jaime Phillips | |
| 15 | 1 | Jaime Phillips | The above will return the bucket_file recs for upload_pk=444 regardless of the file |
| 16 | 1 | Jaime Phillips | being an artifact or which version of the nomos and bucket agents were used to do the scan. |
| 17 | 1 | Jaime Phillips | The condition to remove artifacts looks like |
| 18 | 1 | Jaime Phillips | |
| 19 | 1 | Jaime Phillips | ((ufile_mode & (1<<28))=0) |
| 20 | 1 | Jaime Phillips | |
| 21 | 1 | Jaime Phillips | So here is the new query to select the non-artifact pfile buckets for a specific scan of an upload, that is, for specific nomos and bucket agent pk's (nomos agent_pk 134 and the bucket agent_pk 151 are used in this example): |
| 22 | 1 | Jaime Phillips | |
| 23 | 1 | Jaime Phillips | select distinct bucket_file.pfile_fk, ufile_name, bucket_fk, |
| 24 | 1 | Jaime Phillips | nomosagent_fk, agent_fk |
| 25 | 1 | Jaime Phillips | from bucket_file, |
| 26 | 1 | Jaime Phillips | (select pfile_fk as PF, ufile_name, ufile_mode from uploadtree |
| 27 | 1 | Jaime Phillips | where upload_fk=444) as SS |
| 28 | 1 | Jaime Phillips | where PF=bucket_file.pfile_fk |
| 29 | 1 | Jaime Phillips | and ((ufile_mode & (1<<28))=0) |
| 30 | 1 | Jaime Phillips | and nomosagent_fk=134 |
| 31 | 1 | Jaime Phillips | and agent_fk=151; |
| 32 | 1 | Jaime Phillips | |
| 33 | 1 | Jaime Phillips | Or if you want the bucket name resolved, add another join: |
| 34 | 1 | Jaime Phillips | |
| 35 | 1 | Jaime Phillips | select distinct bucket_file.pfile_fk, ufile_name, bucket_fk, bucket_name, |
| 36 | 1 | Jaime Phillips | nomosagent_fk, agent_fk |
| 37 | 1 | Jaime Phillips | from bucket_def, |
| 38 | 1 | Jaime Phillips | bucket_file, |
| 39 | 1 | Jaime Phillips | (select pfile_fk as PF, ufile_name, ufile_mode from uploadtree |
| 40 | 1 | Jaime Phillips | where upload_fk=444) as SS |
| 41 | 1 | Jaime Phillips | where PF=bucket_file.pfile_fk |
| 42 | 1 | Jaime Phillips | and ((ufile_mode & (1<<28))=0) |
| 43 | 1 | Jaime Phillips | and nomosagent_fk=134 |
| 44 | 1 | Jaime Phillips | and agent_fk=151 |
| 45 | 1 | Jaime Phillips | and bucket_fk=bucket_pk; |
| 46 | 1 | Jaime Phillips | |
| 47 | 1 | Jaime Phillips | h2. Selecting bucket_container records |
| 48 | 2 | Jaime Phillips | |
| 49 | 1 | Jaime Phillips | The same query for bucket_container is: |
| 50 | 1 | Jaime Phillips | select distinct UPK, ufile_name, bucket_fk, bucket_name, |
| 51 | 1 | Jaime Phillips | nomosagent_fk, agent_fk |
| 52 | 1 | Jaime Phillips | from bucket_def, bucket_container, |
| 53 | 1 | Jaime Phillips | (select uploadtree_pk as UPK, ufile_name, ufile_mode from uploadtree |
| 54 | 1 | Jaime Phillips | where upload_fk=444) as SS |
| 55 | 1 | Jaime Phillips | where UPK=uploadtree_fk |
| 56 | 1 | Jaime Phillips | and ((ufile_mode & (1<<28))=0) |
| 57 | 1 | Jaime Phillips | and nomosagent_fk=134 |
| 58 | 1 | Jaime Phillips | and agent_fk=151 |
| 59 | 1 | Jaime Phillips | and bucket_fk=bucket_pk; |